TemplateModel.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using SC.XR.Unity.Module_InputSystem;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using UnityEngine;
  6. public class TemplateModel : BaseTemPlate
  7. {
  8. private GameObject m_ModelObj = null;
  9. protected override void OnEnable()
  10. {
  11. base.OnEnable();
  12. StartCoroutine(LoadModel());
  13. }
  14. private IEnumerator LoadModel()
  15. {
  16. yield return new WaitForSeconds(0.01f);
  17. if (GameManager.Instance.IsRuning && m_ModelObj == null)
  18. {
  19. Debug.Log(Data.name);
  20. Debug.Log(Data.localSavePath);
  21. AssetBundle ab = AssetBundle.LoadFromFile(Data.localSavePath);
  22. if (ab == null)
  23. {
  24. Debug.Log("Failed to load AssetBundle!");
  25. }
  26. else
  27. {
  28. var prefab = ab.LoadAsset<GameObject>(ab.LoadAllAssets<GameObject>()[0].name);
  29. m_ModelObj = Instantiate(prefab, transform);
  30. //if (ab.LoadAllAssets<GameObject>()[0].name == "MRVideo")
  31. //m_ModelObj.AddComponent<MovieScreen>();
  32. gameObject.AddComponent<ManipulationHandler>();
  33. gameObject.AddComponent<BoundingBox>();
  34. yield return new WaitForSeconds(0.3f);
  35. ab.Unload(false);
  36. HideCollider();
  37. }
  38. //var obj = DownloadManager.Instance.GetAbObj(Util.MD5Encrypt(Data.downloadPath));
  39. //if (obj != null)
  40. //{
  41. // m_ModelObj = Instantiate(obj, transform);
  42. // m_ModelObj.transform.localPosition = Vector3.zero;
  43. // m_ModelObj.gameObject.SetActive(true);
  44. //}
  45. }
  46. }
  47. protected override void OnAwake()
  48. {
  49. base.OnAwake();
  50. }
  51. public override void SetData(MaterialObjValue value, int updateTime)
  52. {
  53. base.SetData(value, updateTime);
  54. //if (gameObject.GetComponent<Collider>() != null)
  55. //{
  56. // Destroy(gameObject.GetComponent<Collider>());
  57. //}
  58. //下载列表中加入数据
  59. if (!GameManager.Instance.IsRuning)
  60. {
  61. DownloadManager.Instance.AddDownloadData(Data);
  62. Debug.Log(" SetData " + updateTime);
  63. }
  64. else
  65. {
  66. AssetBundle ab = AssetBundle.LoadFromFile(Data.localSavePath);
  67. if (ab == null)
  68. {
  69. Debug.Log("Failed to load AssetBundle!");
  70. return;
  71. }
  72. var prefab = ab.LoadAsset<GameObject>(ab.LoadAllAssets<GameObject>()[0].name);
  73. m_ModelObj = Instantiate(prefab, transform);
  74. ab.Unload(false);
  75. gameObject.AddComponent<ManipulationHandler>();
  76. gameObject.AddComponent<BoundingBox>();
  77. //var obj = DownloadManager.Instance.GetAbObj(Util.MD5Encrypt(Data.downloadPath));
  78. //if (obj != null)
  79. //{
  80. // m_ModelObj = Instantiate(obj, transform);
  81. // m_ModelObj.transform.localPosition = Vector3.zero;
  82. // m_ModelObj.gameObject.SetActive(true);
  83. //}
  84. }
  85. }
  86. public override void HideCollider()
  87. {
  88. base.HideCollider();
  89. }
  90. }