public IEnumerator CreateObject(kResource kres, string bundle, string res, System.Action <Object> initHandler) { Object assect = null; LoadResource(kres, bundle, res, out assect); if (assect == null) { while (true) { // BUG: IF THE RESOURCE NOT FOUND THIS WILL BE LOOP FOREVER if (CheckBundleExist(bundle)) { LoadResource(kres, bundle, res, out assect); break; } yield return(new WaitForSeconds(0.1f)); } } // initHandler 是事件回调 if (assect != null) { if (initHandler != null) { initHandler(assect); } //Globals.It.BundleMgr.UnLoadBundle(bundle); } else { if (initHandler != null) { initHandler(null); } } }
// 通过路径加载 资源 public void LoadResource(kResource kres, string bundle, string res, out Object obj) { if (Globals.It.bUseLocalResources) // 通过 本地 加载 { string sPath = ""; switch (kres) { case kResource.Common: { sPath = "Common/" + res; break; } case kResource.Config: { sPath = Globals.It.sBundlePath + "/Config/" + res; break; } case kResource.View: { sPath = Globals.It.sBundlePath + "/Views/" + res; break; } case kResource.Effect: { sPath = Globals.It.sBundlePath + "/Effect/" + res; break; } } obj = Resources.Load(sPath); //m_Objects.Add(bundle, obj); } else // 通过 网络 加载 { if (m_Bundlers.ContainsKey(bundle)) // 已经加载过 { AssetBundle ab = m_Bundlers[bundle]; if (string.IsNullOrEmpty(res)) { obj = ab.mainAsset; } else { obj = ab.LoadAsset(res); } } else // 第一次加载,需要开启协程去下载 { obj = null; StartCoroutine(DoLoadOneBundle(bundle)); } } }