ImageTargetManager.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. //using System;
  2. //using System.Collections;
  3. //using System.Collections.Generic;
  4. //using System.IO;
  5. //using UnityEngine;
  6. //using UnityEngine.UI;
  7. ////using Vuforia;
  8. //using QFramework;
  9. ///// <summary>
  10. ///// 识别图管理器
  11. ///// </summary>
  12. //public class ImageTargetManager : MonoSingleton<ImageTargetManager>
  13. //{
  14. // public Text logtest;
  15. // public Text errortext;
  16. // // public List<GameObject> listShowObj;
  17. // /// <summary>
  18. // /// 识别图加载完成
  19. // /// </summary>
  20. // public event Action<string[]> ImageTargerLoadedEvent;
  21. // /// <summary>
  22. // /// 本地文件路径
  23. // /// </summary>
  24. // private string m_localFilePath;
  25. // /// <summary>
  26. // /// 是否加载过
  27. // /// </summary>
  28. // private bool m_isLoaded;
  29. // /// <summary>
  30. // /// 数据集
  31. // /// </summary>
  32. // private DataSet m_dataSet = null;
  33. // /// <summary>
  34. // /// 识别器
  35. // /// </summary>
  36. // private ObjectTracker m_tracker;
  37. // /// <summary>
  38. // /// 识别图集合对象
  39. // /// </summary>
  40. // private ImageTargetBehaviour[] m_imageTargetBehaviours;
  41. // private void Start()
  42. // {
  43. // // Debug.Log(" Inited " + m_isLoaded);
  44. // m_isLoaded = false;
  45. // //TODO 识别图相关信息加载
  46. // //VuforiaBehaviour.Instance.RegisterVuforiaInitializedCallback(VuforiaInitedCallBack);
  47. // try
  48. // {
  49. // VuforiaARController.Instance.RegisterVuforiaInitializedCallback(VuforiaInitedCallBack);
  50. // VuforiaARController.Instance.RegisterVuforiaStartedCallback(VuforiaStaredtCallBack);
  51. // }
  52. // catch (Exception e)
  53. // {
  54. // errortext.text = e.Message;
  55. // }
  56. // }
  57. // /// <summary>
  58. // /// 高通初始化完毕回调
  59. // /// </summary>
  60. // void VuforiaInitedCallBack()
  61. // {
  62. // m_localFilePath = Application.persistentDataPath + "/StreamingAssets/Vuforia/" + AppConfigConst.IMAGE_TARGET_FILE_NAME + ".xml";
  63. // Debug.Log( " Inited@@@ "+m_localFilePath+" " +File.Exists(m_localFilePath));
  64. // logtest.text = " Inited@@@ " + m_localFilePath + " " + File.Exists(m_localFilePath);
  65. // if (File.Exists(m_localFilePath))
  66. // {
  67. // //Load Local
  68. // StartCoroutine(LoadLocalFile());
  69. // }
  70. // else
  71. // {
  72. // //Load NetWork
  73. // //StartCoroutine(LoadNetworkFile());
  74. // }
  75. // }
  76. // void VuforiaStaredtCallBack()
  77. // {
  78. // errortext.text = CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO).ToString(); //auto focus
  79. // }
  80. // /// <summary>
  81. // /// 加载网络配置文件
  82. // /// </summary>
  83. // /// <returns></returns>
  84. // private IEnumerator LoadNetworkFile()
  85. // {
  86. // WWW wwwdat = new WWW(AppConfigConst.IMAGE_TARGET_FILE_PATH + AppConfigConst.IMAGE_TARGET_FILE_NAME + ".dat");
  87. // yield return wwwdat;
  88. // Debug.Log(wwwdat.url);
  89. // WWW wwwxml = new WWW(AppConfigConst.IMAGE_TARGET_FILE_PATH + AppConfigConst.IMAGE_TARGET_FILE_NAME + ".xml");
  90. // yield return wwwxml;
  91. // File.WriteAllBytes(Application.persistentDataPath + "/" + AppConfigConst.IMAGE_TARGET_FILE_NAME + ".dat", wwwdat.bytes);
  92. // File.WriteAllBytes(Application.persistentDataPath + "/" + AppConfigConst.IMAGE_TARGET_FILE_NAME + ".xml", wwwxml.bytes);
  93. // StartCoroutine(LoadLocalFile());
  94. // }
  95. // /// <summary>
  96. // /// 加载本地配置文件
  97. // /// </summary>
  98. // /// <returns></returns>
  99. // IEnumerator LoadLocalFile()
  100. // {
  101. // bool isVuforiaEnabled = VuforiaRuntimeUtilities.IsVuforiaEnabled();
  102. // Debug.Log(isVuforiaEnabled);
  103. // logtest.text = "isVuforiaEnabled " + isVuforiaEnabled + " m_isLoaded " + m_isLoaded;
  104. // if (isVuforiaEnabled && m_isLoaded == false)
  105. // {
  106. // if (m_dataSet == null)
  107. // {
  108. // m_tracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
  109. // m_dataSet = m_tracker.CreateDataSet();
  110. // }
  111. // Debug.Log("LoadData " + m_localFilePath);
  112. // logtest.text = "LoadData " + m_localFilePath;
  113. // ObjectTracker objectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();
  114. // objectTracker.Stop();
  115. // // logtest.text = " startLoadData";
  116. // if (m_dataSet.Load(m_localFilePath, VuforiaUnity.StorageType.STORAGE_ABSOLUTE))
  117. // {
  118. // Debug.Log("LoadData OVer " + m_localFilePath);
  119. // logtest.text = "LoadData OVer " + m_localFilePath;
  120. // m_isLoaded = true;
  121. // errortext.text =
  122. // m_tracker.ActivateDataSet(m_dataSet).ToString();
  123. // objectTracker.Start();
  124. // UpdateImageTarget();
  125. // }
  126. // else
  127. // {
  128. // // logtest.text = "LoadData Error " + m_dataSet.Load(m_localFilePath, VuforiaUnity.StorageType.STORAGE_ABSOLUTE);
  129. // m_isLoaded = false;
  130. // }
  131. // }
  132. // WWW www = new WWW("file:///" + m_localFilePath);
  133. // yield return www;
  134. // }
  135. // /// <summary>
  136. // /// 修改Imagetarget 的名称
  137. // /// </summary>
  138. // void UpdateImageTarget()
  139. // {
  140. // List<string> imagetargetNameList = new List<string>();
  141. // m_imageTargetBehaviours = FindObjectsOfType<ImageTargetBehaviour>();
  142. // logtest.text = m_imageTargetBehaviours.Length.ToString();
  143. // for (int i = 0; i < m_imageTargetBehaviours.Length; i++)
  144. // {
  145. // ImageTargetBehaviour imageTargetBehaviour = m_imageTargetBehaviours[i];
  146. // logtest.text = logtest.text+" "+ m_imageTargetBehaviours[i].name;
  147. // imageTargetBehaviour.name = "ImageTarget_" + imageTargetBehaviour.ImageTarget.Name;
  148. // //imageTargetBehaviour.gameObject.AddComponent<DefaultTrackableEventHandler>();
  149. // //读取 DefaultTrackableEventHandler.lua
  150. // imageTargetBehaviour.gameObject.AddComponent<DefaultTrackableEventHandler>();
  151. // // imageTargetBehaviour.gameObject.AddComponent<LuaTrackableEventHandler>();
  152. // imageTargetBehaviour.gameObject.AddComponent<TurnOffBehaviour>();
  153. // imageTargetBehaviour.gameObject.AddComponent<VuforialFindImageAction>();
  154. // imagetargetNameList.Add(imageTargetBehaviour.name);
  155. // //listShowObj[i].transform.parent = imageTargetBehaviour.transform;
  156. // //listShowObj[i].transform.localPosition = Vector3.zero;
  157. // VuforialFindImageAction imageaction = imageTargetBehaviour.gameObject.GetComponent<VuforialFindImageAction>();
  158. // GameObject obj = new GameObject("Cube");
  159. // obj.transform.parent = imageaction.transform;
  160. // obj.transform.localEulerAngles = new Vector3(90, 0, 0);
  161. // obj.transform.localPosition = Vector3.zero;
  162. // imageaction.num = i;
  163. // imageaction.targetObj = obj.transform;
  164. // imageaction.pointObj = 0;
  165. // }
  166. // OnImageTargerLoadedEvent(imagetargetNameList.ToArray());
  167. // }
  168. // /// <summary>
  169. // /// 获取所有的识别图对象
  170. // /// </summary>
  171. // /// <returns></returns>
  172. // public ImageTargetBehaviour[] GetImageTargetBehaviours()
  173. // {
  174. // return m_imageTargetBehaviours;
  175. // }
  176. // protected virtual void OnImageTargerLoadedEvent(string[] obj)
  177. // {
  178. // var handler = ImageTargerLoadedEvent;
  179. // if (handler != null)
  180. // {
  181. // handler(obj);
  182. // }
  183. // }
  184. //}