static IEnumerator DoLoadFromFile(LoadRequest req) { yield return(null); Object obj = UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/" + req.path, req.resType); req.DoCallBack(obj); }
public void LoadObject(LoadRequest loadobj) { if (IsMobile()) { if (!bundleTable.ContainsKey(loadobj.bundleName)) { Debug.Log("Bundle Don't Exist" + loadobj.bundleName + loadobj.path); return; } int index = (int)bundleTable[loadobj.bundleName]; BundleGlobalItem item = bundles[index]; if (item == null) { Debug.Log("Load Object Failed!=" + loadobj.path); return; } if (loadobj.isScene) { item.lstCB.Add(loadobj); item.loading = true; loadingObjs.Add(item); } else { if (item.bundle != null && loadobj.priority == 1) { Object callback_obj = null; string path = loadobj.path; System.Type resType = loadobj.resType; if (loadobj.resType != typeof(AssetBundle)) { callback_obj = item.bundle.LoadAsset(loadobj.resName, resType); } loadobj.DoCallBack(callback_obj); } else { item.lstCB.Add(loadobj); if (!item.loading) { item.loading = true; if (loadobj.priority == 1) { loadingObjsFast.Add(item); } else if (loadobj.priority == 0) { loadingObjs.Add(item); } else { loadingObjsSlow.Add(item); } } } } } else { if (loadobj.isScene) { string bundlePath = loadobj.bundleName; //检查手机加载路径的正确性,如果错误 日志提示.. if (!bundlePath.EndsWith(".unity3d")) { Debug.LogError("Level Path Isn't correct!(" + bundlePath + ")!"); } else { string strPath = bundlePath.Replace(".unity3d", ""); Object obj = UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/" + strPath, typeof(Object)); if (obj == null) { Debug.LogError("Level Path Isn't correct!(" + bundlePath + ")!"); } else { Resources.UnloadAsset(obj); } } Application.LoadLevel(loadobj.resName); } else { if (loadobj.resType != typeof(AssetBundle)) { StartCoroutine(DoLoadFromFile(loadobj)); } } } }
IEnumerator DoLoadObject(LoadRequest req, Object obj) { yield return(0); req.DoCallBack(obj); }
IEnumerator updateLoad() { while (true) { if (loadingObjs.Count == 0 && loadingObjsFast.Count == 0 && loadingObjsSlow.Count == 0) { yield return(0); } else { BundleGlobalItem item = PopLoadItem(); if (item.itemInfo == null) { item.loading = false; foreach (LoadRequest obj in item.lstCB) { obj.callbackFunc(null, null); } ; item.lstCB.Clear(); yield return(0); continue; } if (item.itemInfo.isScene) { Hashtable UnloadTable = new Hashtable(); UnloadTable.Add(item, 0); if (item.itemInfo.dependency != null) { foreach (int dependId in item.itemInfo.dependency) { UnloadTable.Add(bundles[dependId], 0); } } UnloadNormalBundle(UnloadTable); if (item.itemInfo.dependency != null) { foreach (int dependId in item.itemInfo.dependency) { if (bundles[dependId].bundle == null) { yield return(0); } LoadBundle(dependId); } } string bundleName = item.lstCB[0].bundleName; int i = (int)bundleTable[item.itemInfo.bundlePath]; if (bundles[i].bundle == null) { yield return(0); } LoadBundle(i); string sceneName = item.lstCB[0].resName; item.lstCB.Clear(); AsyncOperation op = Application.LoadLevelAsync(sceneName); yield return(op); item.loading = false; } else { if (item != null) { if (item.itemInfo.dependency != null) { foreach (int dependId in item.itemInfo.dependency) { bool bSkip = false; if (bundles[dependId].bundle == null) { bSkip = true; } LoadBundle(dependId); if (bSkip) { yield return(0); } } } if (item.bundle == null) { string bundlename = item.itemInfo.bundlePath; item.bundle = AssetBundle.LoadFromFile(FixedPath(bundlename)); yield return(0); } item.loading = false; while (item.lstCB.Count > 0) { LoadRequest obj = item.lstCB[0]; item.lstCB.RemoveAt(0); Object callback_obj = null; string path = obj.path; System.Type resType = obj.resType; if (obj.resType == typeof(AssetBundle)) { // 尝试载入这个BUNDLE的所有资源,避免在使用时加载. //item.bundle.LoadAll(); continue; } if (obj.priority == 1) { callback_obj = item.bundle.LoadAsset(obj.resName, resType); } else { AssetBundleRequest req = item.bundle.LoadAssetAsync(obj.resName, resType); yield return(req); callback_obj = req.asset; } obj.DoCallBack(callback_obj); if (obj.priority != 1) { yield return(0); } } ; } } } } }