123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- using SC.XR.Unity.Module_InputSystem;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- public class TemplateModel : BaseTemPlate
- {
- private GameObject m_ModelObj = null;
- protected override void OnEnable()
- {
- base.OnEnable();
- StartCoroutine(LoadModel());
- }
- private IEnumerator LoadModel()
- {
- yield return new WaitForSeconds(0.01f);
- if (GameManager.Instance.IsRuning && m_ModelObj == null)
- {
- Debug.Log(Data.name);
- Debug.Log(Data.localSavePath);
- AssetBundle ab = AssetBundle.LoadFromFile(Data.localSavePath);
- if (ab == null)
- {
- Debug.Log("Failed to load AssetBundle!");
- }
- else
- {
- var prefab = ab.LoadAsset<GameObject>(ab.LoadAllAssets<GameObject>()[0].name);
-
- m_ModelObj = Instantiate(prefab, transform);
- //if (ab.LoadAllAssets<GameObject>()[0].name == "MRVideo")
- //m_ModelObj.AddComponent<MovieScreen>();
- gameObject.AddComponent<ManipulationHandler>();
- gameObject.AddComponent<BoundingBox>();
- yield return new WaitForSeconds(0.3f);
- ab.Unload(false);
- HideCollider();
- }
-
- //var obj = DownloadManager.Instance.GetAbObj(Util.MD5Encrypt(Data.downloadPath));
- //if (obj != null)
- //{
- // m_ModelObj = Instantiate(obj, transform);
- // m_ModelObj.transform.localPosition = Vector3.zero;
- // m_ModelObj.gameObject.SetActive(true);
- //}
- }
- }
- protected override void OnAwake()
- {
- base.OnAwake();
- }
- public override void SetData(MaterialObjValue value, int updateTime)
- {
-
- base.SetData(value, updateTime);
- //if (gameObject.GetComponent<Collider>() != null)
- //{
- // Destroy(gameObject.GetComponent<Collider>());
- //}
- //下载列表中加入数据
- if (!GameManager.Instance.IsRuning)
- {
- DownloadManager.Instance.AddDownloadData(Data);
- Debug.Log(" SetData " + updateTime);
- }
- else
- {
- AssetBundle ab = AssetBundle.LoadFromFile(Data.localSavePath);
- if (ab == null)
- {
- Debug.Log("Failed to load AssetBundle!");
- return;
- }
- var prefab = ab.LoadAsset<GameObject>(ab.LoadAllAssets<GameObject>()[0].name);
- m_ModelObj = Instantiate(prefab, transform);
- ab.Unload(false);
- gameObject.AddComponent<ManipulationHandler>();
- gameObject.AddComponent<BoundingBox>();
- //var obj = DownloadManager.Instance.GetAbObj(Util.MD5Encrypt(Data.downloadPath));
- //if (obj != null)
- //{
- // m_ModelObj = Instantiate(obj, transform);
- // m_ModelObj.transform.localPosition = Vector3.zero;
- // m_ModelObj.gameObject.SetActive(true);
- //}
- }
- }
- public override void HideCollider()
- {
- base.HideCollider();
- }
- }
|