public void GetBundle(string bundleName, Action <string, Bundle> callback, ELoadPriority priority, bool isRaw = true, bool isWeb = false) { Bundle bundle = null; if (mDicBundle.TryGetValue(bundleName, out bundle)) { callback(bundleName, bundle); } else { string[] depends = BundleMap.Instance.GetDependence(bundleName); if (depends.Length > 0) { int dependsCount = depends.Length; for (int i = 0; i < depends.Length; ++i) { string dependBundleName = depends[i]; GetBundle(dependBundleName, (cbName, cbBundle) => { if (--dependsCount <= 0) { LoadBundle(bundleName, callback, priority, isRaw, isWeb); } }, priority); } } else { LoadBundle(bundleName, callback, priority, isRaw, isWeb); } } }
public T GetAsset <T>(string path, bool async = true, ELoadPriority priority = ELoadPriority.Default) where T : UnityEngine.Object { T t = null; switch (LoadSrc) { case ELoadSrc.DataBase: #if UNITY_EDITOR EditorResMgr.Inst.GetAsset(path, (name, obj) => { t = obj as T; }); break; #endif case ELoadSrc.Resources: ResourceLoaderMgr.Instance.LoadAsset(path, (name, obj) => { t = obj as T; }, async, priority); break; case ELoadSrc.AssetBundle: AssetPool.Instance.GetAsset(path, (name, obj) => { t = obj as T; }, async, priority); break; default: break; } return(t); }
public void GetBytesFile(string name, Action <string, byte[]> func, ELoadPriority priority = ELoadPriority.Default, bool isRaw = true, bool isWeb = false) { System.Object obj = null; if (mDicObject.TryGetValue(name, out obj)) { func(name, obj as byte[]); } else { Debug.LogError("load bytes " + name); WWWLoaderMgr.Instance.LoadWWW(name, name, (cbName, cbWWW) => { Debug.LogError("on load bytes " + name); if (cbWWW.bytes == null) { Debug.LogError("get bytes from WWW, but www.bytes == null."); } else { mDicObject.Add(name, cbWWW.bytes); func(cbName, cbWWW.bytes); } }, priority, isRaw, isWeb); } }
public void GetAsset(string name, Action <string, UnityEngine.Object> func, ELoadPriority priority = ELoadPriority.Default) { UnityEngine.Object obj = null; string fullName = ""; if (!mDicFilePath.TryGetValue(name, out fullName)) { foreach (string file in UnityEditor.AssetDatabase.GetAllAssetPaths()) { string fileName = Path.GetFileName(file); if (fileName == name) { fullName = file; mDicFilePath.Add(name, fullName); break; } } } if (string.IsNullOrEmpty(fullName)) { Debug.LogError("Can't find any asset named " + name); } else { obj = AssetDatabaseLoad(fullName); if (func != null) { func(name, obj); } } }
public static WWWLoader CreateInstance(string name, string originName, ELoadPriority priority, bool isRaw, bool isWeb) { WWWLoader loader = new WWWLoader(); loader.mName = name; loader.mOriginName = originName; loader.mWWW = WWWUtil.CreateWWW(name, isRaw, isWeb); loader.LoadPriority = priority; return(loader); }
public void LoadAsset(Asset asset, bool async, ELoadPriority priority) { AssetLoader loader = _GetAssetLoader(asset.Name); if (loader == null) { loader = AssetLoader.CreateInstance(asset, async); mWaitAsset.Add(loader); string bundleName = AssetMap.Instance.GetBundleName(asset.Name); BundlePool.Instance.GetBundle(bundleName, (cbBundleName, cbBundle) => { loader.OnLoadBundle(cbBundleName, cbBundle); }, priority); Update(); } }
public void GetWWWFile(string name, Action <string, WWW> func, ELoadPriority priority = ELoadPriority.Default, bool isRaw = true, bool isWeb = false) { System.Object obj = null; if (mDicObject.TryGetValue(name, out obj)) { func(name, obj as WWW); } else { Debug.LogError("load www " + name); WWWLoaderMgr.Instance.LoadWWW(name, name, (cbName, cbWWW) => { Debug.LogError("on load www " + name); mDicObject.Add(name, cbWWW); func(cbName, cbWWW); }, priority, isRaw, isWeb); } }
private void LoadBundle(string bundleName, Action <string, Bundle> callback, ELoadPriority priority, bool isRaw, bool isWeb) { Bundle bundle = null; string md5Name = BundleMap.Instance.GetMd5Name(bundleName); Debug.LogError("load bundle " + bundleName + " : " + md5Name); WWWLoaderMgr.Instance.LoadWWW(md5Name, bundleName, (cbBundleName, cbWWW) => { if (bundleName.Contains("ui_font")) { int xx = 0; ++xx; } Debug.LogError("on load bundle ok " + bundleName); if (!mDicBundle.TryGetValue(bundleName, out bundle)) { bundle = Bundle.CreateInstance(bundleName); mDicBundle.Add(bundleName, bundle); } bundle.OnLoadWWW(bundleName, cbWWW); callback(bundleName, bundle); }, priority, isRaw, isWeb); }
public void LoadAsset(string path, Action <string, UnityEngine.Object> callback, bool async, ELoadPriority priority) { int dotIdx = path.IndexOf('.'); if (dotIdx >= 0) { path = path.Remove(dotIdx); } ResourceLoader loader = _GetResourceLoader(path); if (loader == null) { loader = ResourceLoader.CreateInstance(path, callback, async); mWaitAsset.Add(loader); Update(); } }
public void LoadWWW(string name, string originName, Action <string, WWW> callback, ELoadPriority priority, bool isRaw, bool isWeb) { if (string.IsNullOrEmpty(name)) { Debug.LogError("load www but name is empty or null."); return; } WWWLoader loader = _GetWWWLoader(name); if (loader == null) { loader = WWWLoader.CreateInstance(name, originName, priority, isRaw, isWeb); mWaitList.Add(loader); } loader.AddCallback(callback); }
public void GetAsset(string name, Action <string, UnityEngine.Object> callback, bool async = true, ELoadPriority priority = ELoadPriority.Default) { Asset asset = null; if (mDicAsset.TryGetValue(name, out asset)) { if (callback != null) { if (asset.AssetValid) { callback(name, asset.GetObject()); } else { asset.AddCallback(callback); } } } else { Debug.LogError("get asset " + name); asset = Asset.CreateInstance(name); if (name.Contains(".ttf") || name.Contains(".TTF")) { int xx = 0; ++xx; } asset.AddCallback(callback); mDicAsset.Add(name, asset); AssetLoaderMgr.Instance.LoadAsset(asset, async, priority); } }