VufroiaTrigger.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using LitJson;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using UnityEngine;
  6. using Vuforia;
  7. public class VufroiaTrigger
  8. {
  9. public JsonData msg;
  10. public UserSceneItem usi;
  11. public string xmlFile;
  12. public string datFile;
  13. public static string LoaclxmlFile;
  14. public static string LoacldatFile;
  15. bool isData;
  16. bool isXML;
  17. public void init()
  18. {
  19. xmlFile = msg["vuforiaXML"].ToString();
  20. datFile = msg["vuforiaDat"].ToString();
  21. LoaclxmlFile = Application.persistentDataPath + "/StreamingAssets/Vuforia/GHZVuforia.xml";
  22. LoacldatFile = Application.persistentDataPath + "/StreamingAssets/Vuforia/GHZVuforia.dat";
  23. Debug.Log(" DGJ ===> " + LoaclxmlFile);
  24. Debug.Log(" DGJ ===> " + LoacldatFile);
  25. LoadManager.Instance.loadVuforia(xmlFile, datFile,(bool b)=> {
  26. isXML = true;
  27. if(isData)
  28. {
  29. GameScene.Instance.StartCoroutine(loadVuforia());
  30. }
  31. }, (bool b) => {
  32. isData = true;
  33. if (isXML)
  34. {
  35. GameScene.Instance.StartCoroutine(loadVuforia());
  36. }
  37. });
  38. }
  39. public void Clear()
  40. {
  41. isData = false;
  42. isXML = false;
  43. if (observer != null)
  44. {
  45. foreach (ObserverBehaviour item in observer)
  46. {
  47. GameManager.Instance.destroyGo(item.gameObject);
  48. }
  49. }
  50. }
  51. IEnumerable<ObserverBehaviour> observer = null;
  52. IEnumerator loadVuforia()
  53. {
  54. isData = false;
  55. isXML = false;
  56. Debug.Log("DGJ ===> 加载Database " + LoaclxmlFile);
  57. observer = VuforiaBehaviour.Instance.ObserverFactory.CreateBehavioursFromDatabase(LoaclxmlFile);
  58. try
  59. {
  60. }
  61. catch (System.Exception e)
  62. {
  63. }
  64. yield return observer;
  65. // Create an Image Target from the database.
  66. if(observer !=null)
  67. {
  68. foreach (string item2 in usi.SpotsList.Keys)
  69. {
  70. foreach (var item111 in usi.SpotsList[item2].modelList.Keys)
  71. {
  72. for (int ij = 0; ij < usi.SpotsList[item2].modelList[item111].materialList.Count; ij++)
  73. {
  74. Debug.Log("測試===2=》" + usi.SpotsList[item2].modelList[item111].materialList[ij].name);
  75. Debug.Log("測試===2=》" + usi.SpotsList[item2].id + "_" + DataManager.Instance.ProjectID.ToString() + "_" + usi.id);
  76. Debug.Log("測試===2=》" + usi.SpotsList[item2].triggerImageMark);
  77. }
  78. }
  79. }
  80. foreach (ObserverBehaviour item in observer)
  81. {
  82. foreach (string item2 in usi.SpotsList.Keys)
  83. {
  84. Debug.Log("HJJVufroia 正在匹配" + item.TargetName+"_"+ usi.SpotsList[item2].triggerImageMark);
  85. if (item.TargetName == usi.SpotsList[item2].triggerImageMark)
  86. {
  87. Debug.Log("HJJVufroia 场景匹配成功"+ item.TargetName);
  88. usi.SpotsList[item2].setObVuforia(item);
  89. }
  90. }
  91. }
  92. }
  93. UIManager.Instance.HideUI(UINameConfig.LoadingPanel);
  94. UserSceneUI.Instance.obj.GetComponent<UserChooseScene>().st.SetActive(true);
  95. }
  96. }