public T LoadAsset <T>(string path, bool enable = true) where T : UnityEngine.Object { BundleLoader loader = BundleLoader.CreateLoader(path); if (loader.loadState == LoadState.Loading) { Debug.Log("can not load asset while it is async loading"); Debug.Log("asset name:" + path); return(null); } loader.Load(); if (loader.mainObject is T) { if (loader.mainObject is GameObject) { return(loader.Instantiate(enable) as T); } else { return(loader.mainObject as T); } } else { return(null); } }
/*void Update() * { * if (true) * { * //CheckNewLoaders(); * CheckQueue(); * } * } * * void CheckQueue() * { * while (waittingLoaders.Count > 0 && runningLoaders.Count < MAX_REQUEST) * { * LoadBundleAsync(waittingLoaders[0]); * runningLoaders.Add(waittingLoaders[0]); * waittingLoaders.RemoveAt(0); * } * }*/ void LoadBundleAsync(BundleLoader loader) { if (!loader.mainObject) { loader.LoadAsync(); } }
public static BundleLoader CreateLoader(string resPath, BundleLoader theLoaderDependsOnMe = null) { string bundleName = resPath.ToLower(); BundleLoader loader = null; if (!allLoader.TryGetValue(bundleName, out loader)) { loader = new BundleLoader(bundleName); allLoader[bundleName] = loader; } return(loader); }
public void LoadAsync(string path, Action <BundleLoader> onLoadAssetComplete = null) { BundleLoader loader = BundleLoader.CreateLoader(path); if (loader.mainObject) { onLoadAssetComplete(loader); } else { loader.onComplete += onLoadAssetComplete; } loader.LoadAsync(); }