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.
217 lines
7.0 KiB
217 lines
7.0 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class WRJ : MonoBehaviour
|
|
{
|
|
|
|
Transform birthpos;
|
|
Animator animator;
|
|
Queue<IEnumerator> queue = new Queue<IEnumerator>();
|
|
bool curQueueend = true;
|
|
int flag = 0;
|
|
public GameObject Water;
|
|
public GameObject Yan;
|
|
public Transform[] area1;
|
|
public Transform[] area2;
|
|
public Transform[] area3;
|
|
public Transform[] area4;
|
|
|
|
private void Awake()
|
|
{
|
|
animator = GetComponent<Animator>();
|
|
}
|
|
private void Start()
|
|
{
|
|
birthpos = transform;
|
|
}
|
|
|
|
|
|
public void SF(int number)
|
|
{
|
|
if (DataCenter.Instance.isStart) return;
|
|
DataCenter.Instance.isStart = true;
|
|
flag = 1;
|
|
if (number == 0)
|
|
{
|
|
queue.Clear();
|
|
queue.Enqueue(move(area1[0].position, 1));
|
|
queue.Enqueue(move(area1[1].position, 2));
|
|
queue.Enqueue(move(area1[2].position, 3));
|
|
queue.Enqueue(move(area1[3].position, 3,true));
|
|
queue.Enqueue(move(area1[2].position, 3,true));
|
|
queue.Enqueue(move(area1[1].position, 2));
|
|
queue.Enqueue(move(area1[0].position, 2));
|
|
queue.Enqueue(move(birthpos.position, 1));
|
|
StartCoroutine(Begin());
|
|
}
|
|
else if (number == 1)
|
|
{
|
|
queue.Clear();
|
|
queue.Enqueue(move(area2[0].position, 1));
|
|
queue.Enqueue(move(area2[1].position, 2));
|
|
queue.Enqueue(move(area2[2].position, 3,true));
|
|
queue.Enqueue(move(area2[1].position, 2,true));
|
|
queue.Enqueue(move(area2[0].position, 2));
|
|
queue.Enqueue(move(birthpos.position, 1));
|
|
StartCoroutine(Begin());
|
|
}
|
|
else if (number == 2)
|
|
{
|
|
queue.Clear();
|
|
queue.Enqueue(move(area3[0].position, 1));
|
|
queue.Enqueue(move(area3[1].position, 2));
|
|
queue.Enqueue(move(area3[2].position, 3, true));
|
|
queue.Enqueue(move(area3[1].position, 2, true));
|
|
queue.Enqueue(move(area3[0].position, 2));
|
|
queue.Enqueue(move(birthpos.position, 1));
|
|
StartCoroutine(Begin());
|
|
}
|
|
else if (number == 3)
|
|
{
|
|
queue.Clear();
|
|
queue.Enqueue(move(area4[0].position, 1));
|
|
queue.Enqueue(move(area4[1].position, 2));
|
|
queue.Enqueue(move(area4[2].position, 3));
|
|
queue.Enqueue(move(area4[3].position, 3, true));
|
|
queue.Enqueue(move(area4[2].position, 3, true));
|
|
queue.Enqueue(move(area4[1].position, 2));
|
|
queue.Enqueue(move(area4[0].position, 2));
|
|
queue.Enqueue(move(birthpos.position, 1));
|
|
StartCoroutine(Begin());
|
|
}
|
|
}
|
|
|
|
public void CC(int number)
|
|
{
|
|
if (DataCenter.Instance.isStart) return;
|
|
DataCenter.Instance.isStart = true;
|
|
flag = 2;
|
|
if (number == 0)
|
|
{
|
|
queue.Clear();
|
|
queue.Enqueue(moves(area1[0].position, 1));
|
|
queue.Enqueue(moves(area1[1].position, 2));
|
|
queue.Enqueue(moves(area1[2].position, 3));
|
|
queue.Enqueue(moves(area1[3].position, 3, true));
|
|
queue.Enqueue(moves(area1[2].position, 3, true));
|
|
queue.Enqueue(moves(area1[1].position, 2));
|
|
queue.Enqueue(moves(area1[0].position, 2));
|
|
queue.Enqueue(moves(birthpos.position, 1));
|
|
StartCoroutine(Begin());
|
|
}
|
|
else if (number == 1)
|
|
{
|
|
queue.Clear();
|
|
queue.Enqueue(moves(area2[0].position, 1));
|
|
queue.Enqueue(moves(area2[1].position, 2));
|
|
queue.Enqueue(moves(area2[2].position, 3, true));
|
|
queue.Enqueue(moves(area2[1].position, 2, true));
|
|
queue.Enqueue(moves(area2[0].position, 2));
|
|
queue.Enqueue(moves(birthpos.position, 1));
|
|
StartCoroutine(Begin());
|
|
}
|
|
else if (number == 2)
|
|
{
|
|
queue.Clear();
|
|
queue.Enqueue(moves(area3[0].position, 1));
|
|
queue.Enqueue(moves(area3[1].position, 2));
|
|
queue.Enqueue(moves(area3[2].position, 3, true));
|
|
queue.Enqueue(moves(area3[1].position, 2, true));
|
|
queue.Enqueue(moves(area3[0].position, 2));
|
|
queue.Enqueue(moves(birthpos.position, 1));
|
|
StartCoroutine(Begin());
|
|
}
|
|
else if (number == 3)
|
|
{
|
|
queue.Clear();
|
|
queue.Enqueue(moves(area4[0].position, 1));
|
|
queue.Enqueue(moves(area4[1].position, 2));
|
|
queue.Enqueue(moves(area4[2].position, 3));
|
|
queue.Enqueue(moves(area4[3].position, 3, true));
|
|
queue.Enqueue(moves(area4[2].position, 3, true));
|
|
queue.Enqueue(moves(area4[1].position, 2));
|
|
queue.Enqueue(moves(area4[0].position, 2));
|
|
queue.Enqueue(moves(birthpos.position, 1));
|
|
StartCoroutine(Begin());
|
|
}
|
|
}
|
|
|
|
|
|
IEnumerator move(Vector3 targetpos, float speed,bool isWater=false)
|
|
{
|
|
curQueueend = false;
|
|
Vector3 dir = targetpos - transform.position;
|
|
if (isWater) Water.SetActive(true); else Water.SetActive(false);
|
|
while (true)
|
|
{
|
|
yield return new WaitForEndOfFrame();
|
|
transform.position += dir.normalized * speed * Time.deltaTime;
|
|
if (Vector3.Distance(targetpos, transform.position) <= 0.05f)
|
|
{
|
|
transform.position = targetpos;
|
|
queue.Dequeue();
|
|
curQueueend = true;
|
|
yield break;
|
|
}
|
|
}
|
|
}
|
|
|
|
IEnumerator moves(Vector3 targetpos, float speed, bool isWater = false)
|
|
{
|
|
curQueueend = false;
|
|
Vector3 dir = targetpos - transform.position;
|
|
if (isWater) Yan.SetActive(true); else Yan.SetActive(false);
|
|
print(Yan.activeSelf);
|
|
while (true)
|
|
{
|
|
yield return new WaitForEndOfFrame();
|
|
transform.position += dir.normalized * speed * Time.deltaTime;
|
|
if (Vector3.Distance(targetpos, transform.position) <= 0.05f)
|
|
{
|
|
transform.position = targetpos;
|
|
queue.Dequeue();
|
|
curQueueend = true;
|
|
yield break;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
bool check()
|
|
{
|
|
if (curQueueend)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
IEnumerator Begin()
|
|
{
|
|
animator.SetBool("State",true);
|
|
while (queue != null)
|
|
{
|
|
yield return new WaitUntil(check);
|
|
if (queue.Count != 0)
|
|
{
|
|
StartCoroutine(queue.Peek());
|
|
}
|
|
else
|
|
{
|
|
DataCenter.Instance.isStart = false;
|
|
animator.SetBool("State", false);
|
|
if (flag == 1) { TaskManager.Instance.FinishTask(3); }
|
|
if (flag == 2) { TaskManager.Instance.FinishTask(4); }
|
|
flag = 0;
|
|
yield break;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|