VufroiaTrigger.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. Debug.Log("DGJ ===> 加载Database " + LoaclxmlFile);
  55. observer = VuforiaBehaviour.Instance.ObserverFactory.CreateBehavioursFromDatabase(LoaclxmlFile);
  56. try
  57. {
  58. }
  59. catch (System.Exception e)
  60. {
  61. }
  62. yield return observer;
  63. // Create an Image Target from the database.
  64. if(observer !=null)
  65. {
  66. foreach (string item2 in usi.SpotsList.Keys)
  67. {
  68. foreach (var item111 in usi.SpotsList[item2].modelList.Keys)
  69. {
  70. for (int ij = 0; ij < usi.SpotsList[item2].modelList[item111].materialList.Count; ij++)
  71. {
  72. Debug.Log("測試===2=》" + usi.SpotsList[item2].modelList[item111].materialList[ij].name);
  73. Debug.Log("測試===2=》" + usi.SpotsList[item2].id + "_" + DataManager.Instance.ProjectID.ToString() + "_" + usi.id);
  74. Debug.Log("測試===2=》" + usi.SpotsList[item2].triggerImageMark);
  75. }
  76. }
  77. }
  78. foreach (ObserverBehaviour item in observer)
  79. {
  80. foreach (string item2 in usi.SpotsList.Keys)
  81. {
  82. Debug.Log("HJJVufroia 正在匹配" + item.TargetName+"_"+ usi.SpotsList[item2].triggerImageMark);
  83. if (item.TargetName == usi.SpotsList[item2].triggerImageMark)
  84. {
  85. Debug.Log("HJJVufroia 场景匹配成功"+ item.TargetName);
  86. usi.SpotsList[item2].setObVuforia(item);
  87. }
  88. }
  89. }
  90. }
  91. UIManager.Instance.HideUI(UINameConfig.LoadingPanel);
  92. UserSceneUI.Instance.obj.GetComponent<UserChooseScene>().st.SetActive(true);
  93. }
  94. }