123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- 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);
- switch (prefab.name)
- {
- case "GHZ_OOBE_230721":
- GameObject obj = Resources.Load<GameObject>("GongYe");
- if(obj == null)
- {
- Debug.LogError(" GHZ_OOBE_230721 物体加载失败,请查看是否导入相关Packages ");
- obj = new GameObject();
-
- }
- m_ModelObj = GameObject.Instantiate(obj,transform);
- m_ModelObj.name = "GongYe";
- if (GameObject.Find("AudioManager") ==null)
- {
- GameObject audio = Resources.Load<GameObject>("AudioManager");
- if(audio ==null)
- {
- Debug.LogError(" GHZ_OOBE_230721 Packages内AudioManager组件丢失");
- audio = new GameObject();
- }
- GameObject Audio = GameObject.Instantiate(audio, transform);
- Audio.name = "AudioManager";
- }
- break;
- case "GHZ_XXXXXX_230721":
- break;
- default:
- m_ModelObj = Instantiate(prefab, transform);
- break;
- }
-
- //if (ab.LoadAllAssets<GameObject>()[0].name == "MRVideo")
- //m_ModelObj.AddComponent<MovieScreen>();
- gameObject.AddComponent<ManipulationHandler>();
- gameObject.AddComponent<BoundingBox>();
- gameObject.AddComponent<Patch_ModelController>();
- 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();
- }
- }
|