VuforialControl.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. using QFramework;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. /// <summary>
  7. /// ImageTarget 和对应显示物体
  8. /// </summary>
  9. ///
  10. public class VuforialControl : MonoSingleton<VuforialControl>
  11. {
  12. public List<VuforialTargetMove> list_Target = new List<VuforialTargetMove>();
  13. //public Text text1;
  14. //public Text text2;
  15. //public Text text3;
  16. private VuforialTargetMove oldTarget = null;
  17. private Transform oldTargetobj = null;
  18. public bool state;
  19. void Start()
  20. {
  21. state = false;
  22. oldTarget = null;
  23. // StartCoroutine(LoadARCamera(8));
  24. // StartCoroutine(ReturnShaPan(17));
  25. }
  26. /// <summary>
  27. /// 识别成功
  28. /// </summary>
  29. /// <param name="targetObj"> 识别成功后Target物体 </param>
  30. /// <param name="num"> 对应的VuforialTargetMove </param>
  31. /// <param name="pointnum"> VuforialTargetMove 对应的点 </param>
  32. public void TrackingFound(Transform targetObj, int num , int pointnum)
  33. {
  34. try
  35. {
  36. state = true;
  37. if (list_Target.Count < (num + 1) || list_Target.Count < 1)
  38. return;
  39. ReplaceSceneSpoit(targetObj, num, pointnum);
  40. }
  41. catch (System.Exception)
  42. {
  43. ErrorLogPanel.Instance.Show(" 识别模块出现未知错误 ");
  44. }
  45. }
  46. public void TrackingLost(int num)
  47. {
  48. try
  49. {
  50. state = false;
  51. if (list_Target.Count < (num + 1) || list_Target.Count < 1)
  52. return;
  53. list_Target[num].Close();
  54. // oldTargetobj = null;
  55. }
  56. catch (System.Exception)
  57. {
  58. ErrorLogPanel.Instance.Show(" 识别模块出现未知错误 ");
  59. }
  60. }
  61. public void ReplaceSceneSpoit(Transform targetObj, int num, int pointnum)
  62. {
  63. if (oldTarget == null)
  64. {
  65. oldTarget = list_Target[num];
  66. oldTarget.Show(targetObj, pointnum);
  67. }
  68. else if (oldTarget == list_Target[num])
  69. {
  70. // oldTarget.DirectClose();
  71. oldTarget.ReplaceShow(targetObj, pointnum);
  72. }
  73. else if (oldTarget != list_Target[num])
  74. {
  75. oldTarget.DirectClose();
  76. oldTarget = list_Target[num];
  77. oldTarget.Show(targetObj, pointnum);
  78. }
  79. GameManager.Instance.text2.text = oldTarget.name;
  80. }
  81. public void Close()
  82. {
  83. oldTarget = null;
  84. }
  85. IEnumerator LoadARCamera( float timer)
  86. {
  87. yield return new WaitForSeconds(timer);
  88. GameObject.Instantiate(Resources.Load("ARCamera")as GameObject );
  89. GameManager.Instance.text.text = "ARCamera 加载成功";
  90. // mrShaPan.transform.GetChild(0).GetComponent<Animator>().Play("ReturnMrRoomFXAnimation");
  91. // mrShaPan.SetActive(false);
  92. }
  93. /// <summary>
  94. /// 加载ARCamera
  95. /// </summary>
  96. public void LoadARCamera()
  97. {
  98. GameObject.Instantiate(Resources.Load("ARCamera") as GameObject);
  99. GameManager.Instance.text.text = "ARCamera 加载成功";
  100. }
  101. //IEnumerator ReturnShaPan( float timer)
  102. //{
  103. // yield return new WaitForSeconds(timer);
  104. // mrShaPan.SetActive(false);
  105. //}
  106. /// <summary>
  107. /// 退出显示
  108. /// </summary>
  109. public void ExitShow()
  110. {
  111. oldTarget = null;
  112. oldTargetobj = null;
  113. }
  114. public void SetEditor(bool state)
  115. {
  116. if(state )
  117. {
  118. for (int i = 0; i < list_Target.Count; i++)
  119. {
  120. list_Target[i].transform.position = Vector3.zero;
  121. list_Target[i].transform.eulerAngles = Vector3.zero;
  122. }
  123. }
  124. else
  125. {
  126. for (int i = 0; i < list_Target.Count; i++)
  127. {
  128. }
  129. }
  130. }
  131. }