You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
179 lines
5.3 KiB
179 lines
5.3 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using DG.Tweening;
|
|
public enum EnterDoorWay {
|
|
Enter,
|
|
Out
|
|
}
|
|
public class Door : MonoBehaviour
|
|
{
|
|
public GameObject panel;
|
|
Animator animator;
|
|
public EnterDoorWay curOpenWay;
|
|
//地标
|
|
public Transform EnterStartPoint;
|
|
public Transform EnterEndPoint;
|
|
public Transform OutStartPoint;
|
|
public Transform OutEndPoint;
|
|
public GameObject camera;
|
|
public GameObject light1;
|
|
public GameObject light2;
|
|
[Header("非必要")]
|
|
bool isChoose;
|
|
public Button[] buttons;//选择开门方式
|
|
public GameObject shou;
|
|
public GameObject iphone;
|
|
public GameObject player;
|
|
int _curWay;//shouji 1,zhiwen 2,shengyin 3
|
|
AudioSource audiosource;
|
|
|
|
private void Awake()
|
|
{
|
|
animator = GetComponent<Animator>();
|
|
isChoose = false;
|
|
for (int i = 0; i < buttons.Length; i++)
|
|
{
|
|
int number = i;
|
|
buttons[i].onClick.AddListener(delegate () {
|
|
SetOpenWay(number);
|
|
});
|
|
}
|
|
audiosource = GetComponent<AudioSource>();
|
|
}
|
|
private void Start()
|
|
{
|
|
for (int i = 0; i < buttons.Length; i++)
|
|
{
|
|
int number = i;
|
|
buttons[i].onClick.AddListener(delegate () {
|
|
SetOpenWay(number);
|
|
});
|
|
}
|
|
}
|
|
private void Update()
|
|
{
|
|
if (isChoose) return;
|
|
if (Input.GetKeyDown(KeyCode.Z)) {
|
|
SetOpenWay(0);
|
|
} else if (Input.GetKeyDown(KeyCode.X)) {
|
|
SetOpenWay(1);
|
|
} else if (Input.GetKeyDown(KeyCode.C)) {
|
|
SetOpenWay(2);
|
|
}
|
|
}
|
|
|
|
//选择开门方式
|
|
public void SwitchOpenWay() {
|
|
GameManager.GetInstance().IsStartEvent = true;
|
|
GameManager.GetInstance().IsPlayerMove = false;
|
|
GameManager.GetInstance().IsOpenUI = true;
|
|
panel.SetActive(true);
|
|
curOpenWay = EnterDoorWay.Enter;
|
|
DoMoveAction(player.transform,2,EnterStartPoint.position);
|
|
Quaternion qua = Quaternion.Euler(new Vector3(20,88,0));
|
|
camera.transform.rotation=qua;
|
|
player.transform.rotation = qua;
|
|
}
|
|
|
|
public void SetOpenWay(int number)
|
|
{
|
|
_curWay = number;
|
|
isChoose = true;
|
|
panel.SetActive(false);
|
|
OpenDoor();
|
|
}
|
|
void OpenDoor() {
|
|
switch (_curWay) {
|
|
case 0:
|
|
iphone.SetActive(true);
|
|
iphone.GetComponent<Animator>().SetTrigger("iphone");
|
|
break;
|
|
case 1:
|
|
shou.SetActive(true);
|
|
shou.GetComponent<Animator>().SetTrigger("hand");
|
|
break;
|
|
case 2:
|
|
audiosource.Play();
|
|
Invoke("openD",3);
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void MovePlayer()
|
|
{
|
|
if (curOpenWay==EnterDoorWay.Enter) {
|
|
DoMoveAction(player.transform, 3f, EnterEndPoint.position);
|
|
StartCoroutine(IsArrive(player.transform, EnterEndPoint));
|
|
print("玩家进门");
|
|
}
|
|
else {
|
|
DoMoveAction(player.transform, 3, OutEndPoint.position);
|
|
StartCoroutine(IsArrive(player.transform, OutEndPoint));
|
|
}
|
|
|
|
}
|
|
|
|
public void CloseDoor() {
|
|
GameManager.GetInstance().IsStartEvent = true;
|
|
GameManager.GetInstance().IsPlayerMove = false;
|
|
GameManager.GetInstance().IsOpenUI = true;
|
|
light1.SetActive(false);
|
|
light2.SetActive(false);
|
|
curOpenWay = EnterDoorWay.Out;
|
|
player.transform.position = OutStartPoint.position;
|
|
Quaternion qua = Quaternion.Euler(new Vector3(20, 268, 0));
|
|
camera.transform.rotation = qua;
|
|
player.transform.rotation = qua;
|
|
animator.SetTrigger("door");
|
|
}
|
|
|
|
|
|
public void DoMoveAction(Transform trans, float speed, Vector3 targetPoint)
|
|
{
|
|
StartCoroutine(MoveAction(trans, speed, targetPoint));
|
|
}
|
|
|
|
IEnumerator MoveAction(Transform trans, float speed, Vector3 targetPoint)
|
|
{
|
|
Vector3 Dir = (targetPoint - trans.position).normalized;
|
|
while (true)
|
|
{
|
|
print("开始携程");
|
|
//yield return new WaitForFixedUpdate();
|
|
yield return new WaitForEndOfFrame();
|
|
trans.position += Dir * speed * Time.deltaTime;
|
|
if (Vector3.Distance(trans.position, targetPoint) <= 0.25f)
|
|
{
|
|
Debug.Log("Over");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
IEnumerator IsArrive(Transform player,Transform pos) {
|
|
while (true){
|
|
yield return new WaitForEndOfFrame();
|
|
if (Vector3.Distance(player.position, pos.position) <= 0.25f)
|
|
{
|
|
GameManager.GetInstance().IsPlayerMove = true;
|
|
GameManager.GetInstance().IsOpenUI = false;
|
|
GameManager.GetInstance().IsStartEvent = false;
|
|
isChoose = false;
|
|
if (curOpenWay==EnterDoorWay.Enter) {
|
|
light1.SetActive(true);
|
|
light2.SetActive(true);
|
|
TaskCenter.GetInstance().StartTask();
|
|
}
|
|
print("Arrive");
|
|
animator.SetTrigger("closeDoor");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
void openD() {
|
|
GetComponent<Animator>().SetTrigger("door");
|
|
}
|
|
}
|