using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using DG.Tweening; public class TaskItem : MonoBehaviour { public List shouzhilist; public AudioSource asaudio; public int type = -1; public int nextid = 1; public GameObject t; public GameObject endArea; public GameObject dhs; private void Start() { if (dhs != null) { playjinai(false); } } public void starttask(TaskManager action) { for (int i = 0; i < action.tasklist.Count; i++) { if(action.tasklist[i]!=this) { action.tasklist[i].gameObject.SetActive(false); } } this.gameObject.SetActive(true); StartCoroutine(checkend(action)); if(dhs!=null) { dhs.SetActive(true); } asaudio.Play(); } void playjinai(bool isshang) { return; if(isshang) { dhs.transform.DOLocalMoveY(0.4f, 1f).OnComplete(() => { playjinai(!isshang); }); } else { dhs.transform.DOLocalMoveY(0.5f, 1f).OnComplete(() => { playjinai(!isshang); }); } } private IEnumerator checkend(TaskManager action) { yield return null; switch(type) { case 0: bool isfinish=false; float tmx2 = 0; while (!isfinish) { yield return null; if (action.text.text.Contains("Open")) { yield return new WaitForSeconds(2f); if (action.text.text.Contains("Open")) { isfinish = true; } } tmx2 = Time.deltaTime + tmx2; if (tmx2 > 4) { tmx2 = 0; asaudio.Play(); } } break; case 1: bool isfinish2 = false; float inithandy = 0; float linithandy = 0; float Hinithandy = 0; float tmx = 0; while (!isfinish2) { if(Mathf.Abs(UdpServer.resR)>40) { action.pm.playan("pawL"); isfinish2 = true; } yield return null; if(Vector3.Distance( dhs.transform.position, action.text.transform.position)<=0.2f) { //if ((action.text.text.Contains("Grab") || action.text.text.Contains("Pinch"))) // { if (inithandy == 0) inithandy = action.text.transform.position.y; if (Mathf.Abs(inithandy - action.text.transform.position.y) > 0.1f) { action.pm.playan("pawL"); inithandy = 0; isfinish2 = true; } // } } if (Vector3.Distance(dhs.transform.position, action.ltext.transform.position) <= 0.3f) { // if ((action.ltext.text.Contains("Grab") || action.ltext.text.Contains("Pinch"))) // { if (linithandy == 0) linithandy = action.ltext.transform.position.y; if (Mathf.Abs(linithandy - action.ltext.transform.position.y) > 0.1f) { action.pm.playan("pawL"); linithandy = 0; isfinish2 = true; } // } } if (Vector3.Distance(dhs.transform.position, action.Hand.transform.position) <= 0.3f) { // if ((action.ltext.text.Contains("Grab") || action.ltext.text.Contains("Pinch"))) // { if (action.Hand.transform.localPosition.y >= 0&& Vector3.Distance(dhs.transform.position, action.Hand.transform.position) <= 0.05f) Hinithandy = action.Hand.transform.localPosition.y; if (Hinithandy - action.Hand.transform.localPosition.y > 0.1f&& Hinithandy!=0) { action.pm.playan("pawL"); Hinithandy = 0; isfinish2 = true; } // } } tmx = Time.deltaTime + tmx; if (tmx>3) { tmx = 0; asaudio.Play(); } } action.pm.isplayend = false; break; case 2: yield return new WaitForSeconds(3f); break; default: Vector3 v1p = new Vector3(endArea.transform.position.x, 0, endArea.transform.position.z); Vector3 v2p = new Vector3(OpenXRCamera.Instance.head.position.x, 0, OpenXRCamera.Instance.head.position.z); float tmx3 = 0; while (Vector3.Distance(v1p, v2p) > 0.5f) { v1p = new Vector3(endArea.transform.position.x, 0, endArea.transform.position.z); v2p = new Vector3(OpenXRCamera.Instance.head.position.x, 0, OpenXRCamera.Instance.head.position.z); yield return null; tmx3 = Time.deltaTime + tmx3; if (tmx3 > 4) { tmx3 = 0; asaudio.Play(); } } break; } action.tasklist[nextid].starttask(action); } private void Update() { t.transform.position = OpenXRCamera.Instance.head.position; t.transform.eulerAngles = OpenXRCamera.Instance.head.eulerAngles; for (int i = 0; i < shouzhilist.Count; i++) { shouzhilist[i].transform.localEulerAngles = new Vector3(shouzhilist[i].transform.localEulerAngles.x, shouzhilist[i].transform.localEulerAngles.y, -Mathf.Abs (UdpServer.resR)); } } }