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(ab.LoadAllAssets()[0].name); m_ModelObj = Instantiate(prefab, transform); //if (ab.LoadAllAssets()[0].name == "MRVideo") //m_ModelObj.AddComponent(); gameObject.AddComponent(); gameObject.AddComponent(); 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() != null) //{ // Destroy(gameObject.GetComponent()); //} //下载列表中加入数据 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(ab.LoadAllAssets()[0].name); m_ModelObj = Instantiate(prefab, transform); ab.Unload(false); gameObject.AddComponent(); gameObject.AddComponent(); //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(); } }