123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- using QFramework;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- /// <summary>
- /// ImageTarget 和对应显示物体
- /// </summary>
- ///
- public class VuforialControl : MonoSingleton<VuforialControl>
- {
- public List<VuforialTargetMove> list_Target = new List<VuforialTargetMove>();
- //public Text text1;
- //public Text text2;
- //public Text text3;
- private VuforialTargetMove oldTarget = null;
- private Transform oldTargetobj = null;
- public bool state;
- void Start()
- {
- state = false;
- oldTarget = null;
- // StartCoroutine(LoadARCamera(8));
- // StartCoroutine(ReturnShaPan(17));
- }
- /// <summary>
- /// 识别成功
- /// </summary>
- /// <param name="targetObj"> 识别成功后Target物体 </param>
- /// <param name="num"> 对应的VuforialTargetMove </param>
- /// <param name="pointnum"> VuforialTargetMove 对应的点 </param>
- public void TrackingFound(Transform targetObj, int num , int pointnum)
- {
- try
- {
- state = true;
- if (list_Target.Count < (num + 1) || list_Target.Count < 1)
- return;
- ReplaceSceneSpoit(targetObj, num, pointnum);
- }
- catch (System.Exception)
- {
- ErrorLogPanel.Instance.Show(" 识别模块出现未知错误 ");
-
- }
-
- }
- public void TrackingLost(int num)
- {
- try
- {
- state = false;
- if (list_Target.Count < (num + 1) || list_Target.Count < 1)
- return;
- list_Target[num].Close();
- // oldTargetobj = null;
- }
- catch (System.Exception)
- {
- ErrorLogPanel.Instance.Show(" 识别模块出现未知错误 ");
-
- }
-
- }
- public void ReplaceSceneSpoit(Transform targetObj, int num, int pointnum)
- {
-
- if (oldTarget == null)
- {
- oldTarget = list_Target[num];
- oldTarget.Show(targetObj, pointnum);
- }
- else if (oldTarget == list_Target[num])
- {
- // oldTarget.DirectClose();
- oldTarget.ReplaceShow(targetObj, pointnum);
- }
- else if (oldTarget != list_Target[num])
- {
- oldTarget.DirectClose();
- oldTarget = list_Target[num];
- oldTarget.Show(targetObj, pointnum);
- }
- GameManager.Instance.text2.text = oldTarget.name;
- }
- public void Close()
- {
- oldTarget = null;
- }
- IEnumerator LoadARCamera( float timer)
- {
-
- yield return new WaitForSeconds(timer);
- GameObject.Instantiate(Resources.Load("ARCamera")as GameObject );
- GameManager.Instance.text.text = "ARCamera 加载成功";
- // mrShaPan.transform.GetChild(0).GetComponent<Animator>().Play("ReturnMrRoomFXAnimation");
- // mrShaPan.SetActive(false);
- }
- /// <summary>
- /// 加载ARCamera
- /// </summary>
- public void LoadARCamera()
- {
- GameObject.Instantiate(Resources.Load("ARCamera") as GameObject);
- GameManager.Instance.text.text = "ARCamera 加载成功";
- }
- //IEnumerator ReturnShaPan( float timer)
- //{
- // yield return new WaitForSeconds(timer);
- // mrShaPan.SetActive(false);
- //}
- /// <summary>
- /// 退出显示
- /// </summary>
- public void ExitShow()
- {
- oldTarget = null;
- oldTargetobj = null;
- }
- public void SetEditor(bool state)
- {
- if(state )
- {
- for (int i = 0; i < list_Target.Count; i++)
- {
- list_Target[i].transform.position = Vector3.zero;
- list_Target[i].transform.eulerAngles = Vector3.zero;
- }
- }
- else
- {
- for (int i = 0; i < list_Target.Count; i++)
- {
-
- }
- }
- }
- }
|