public override void Initialize() { var path = Helper.GetInternalPath(name.ToLower()); _request = AssetBundle.LoadFromFileAsync(path); if (_request == null) { error = name + " LoadFromFileAsync falied."; } var items = Bundles.GetBundleDependencies(name.ToLower()); if (items != null && items.Length > 0) { for (int i = 0, I = items.Length; i < I; i++) { var item = items[i]; if (Bundles.IsCyclicDependsLoaded(item)) { Debug.LogWarning("Cyclic dependence " + name); } else { dependencies.Add(Bundles.LoadAsync(item)); } } } }
public override void Initialize() { var path = Helper.GetDataPath(name.ToLower()); if (Bundles.IsInternal(name)) { path = "file:///" + Helper.GetInternalPath(name); } _request = UnityWebRequestAssetBundle.GetAssetBundle(path, Bundles.GetHash128(name), 0); _request.SendWebRequest(); if (_request == null) { error = name + " LoadFromFileAsync falied."; } var items = Bundles.GetBundleDependencies(name.ToLower()); if (items != null && items.Length > 0) { for (int i = 0, I = items.Length; i < I; i++) { var item = items[i]; if (Bundles.IsCyclicDependsLoaded(item)) { Debug.LogWarning("Cyclic dependence " + name); } else { dependencies.Add(Bundles.LoadAsync(item)); } } } }
public override void Initialize() { var path = Helper.GetInternalPath(name); _assetBundle = AssetBundle.LoadFromFile(path); if (_assetBundle == null) { error = name + " LoadFromFile failed."; } var items = Bundles.GetBundleDependencies(name.ToLower()); if (items != null && items.Length > 0) { for (int i = 0, I = items.Length; i < I; i++) { var item = items[i]; if (Bundles.IsCyclicDependsLoaded(item)) { #if UNITY_EDITOR Debug.LogWarning("Cyclic dependence " + name); #endif } else { dependencies.Add(Bundles.Load(item)); } } } }
public override void Initialize() { if (string.IsNullOrEmpty(bundlePath)) { Debug.LogError("bundlePath is Null <= " + assetPath); return; } request = Bundles.Load(bundlePath, true); asset = request?.LoadAsset(assetPath, assetType); }
static IEnumerator UpgradeAssets(Action <float, float> dealcb, Action <float, float> overcb) { long allsize = 0; float cursize = 0; #if UNITY_EDITOR if (LoadType != AssetType.LocalAsset) #endif { var bundles = Bundles.GetChangedList(); foreach (var b in bundles) { allsize += b.Value.bundleSize; } if (allsize > 0) { var nbundles = new Dictionary <string, float>(); int Mx = 8; int count = Mx; long curTime = System.DateTime.UtcNow.Ticks; foreach (var b in bundles) { count--; AB.Assets.ObtainNetwork(b.Value, (bundleName, bundleProgress, bundleOver) => { if (bundleOver) { count++; } bundleProgress = bundleProgress < 0 ? 0 : bundleProgress; nbundles[bundleName] = bundles[bundleName].bundleSize * bundleProgress; cursize = 0; foreach (var nb in nbundles) { cursize += nb.Value; } dealcb?.Invoke(cursize, allsize); }); while (count <= 0) { yield return(new WaitForEndOfFrame()); } } while (count < Mx) { yield return(new WaitForEndOfFrame()); } Debug.Log("Upgrade Assets UseTime:" + (System.DateTime.UtcNow.Ticks - curTime)); } } overcb?.Invoke(cursize, allsize); }
public override void Initialize() { loadInited = true; if (string.IsNullOrEmpty(bundlePath)) { loadState = 2; Debug.LogError("bundlePath is Null <= " + assetPath); return; } request = Bundles.LoadAsync(bundlePath, true); }
static Asset LoadInternal(string path, System.Type type, bool asyncMode) { path = path.ToLower(); Asset asset = assets.Find(obj => { return(obj.assetPath == path); }); if (asset == null) { var bundleName = Bundles.GetBundleName(path); #if UNITY_EDITOR if (LoadType == AssetType.LocalAsset) { asset = new Asset(path, bundleName?.bundleName, type); } else #endif if (true) { if (asyncMode) { asset = new BundleAssetAsync(path, bundleName?.bundleName, type); } else { asset = new BundleAsset(path, bundleName?.bundleName, type); } } //处理正在卸载的情况 if (AsyncOperationUnloadUnusedAssets != null) { var tick = DateTime.Now.Ticks; Debug.Log("Wait UnloadUnusedAssets Begin"); if (asyncMode) { Instance.StartCoroutine(Instance.AssetInitialize(asset)); } else { while (!AsyncOperationUnloadUnusedAssets.isDone) { Thread.Yield(); } } Debug.Log("Wait UnloadUnusedAssets End use :" + (DateTime.Now.Ticks - tick)); } else { asset.Initialize(); } assets.Add(asset); } asset.Load(); return(asset); }
public static IEnumerator Initialize() { #if UNITY_EDITOR var ins = Instance; if (LoadType == AssetType.LocalAsset) { Bundles.InitializeForEditor(); } else #endif yield return(InitializeBundle()); }
public virtual void Initialize() { var path = Helper.GetDataPath(name.ToLower()); //使用了Caching的资源 AssetBundle.LoadFromFile 找不到路径,这里直接阻塞等待加载完成, //按照官方文档上说的,对已经Cache的资源UnityWebRequest.GetAssetBundle 和 AssetBundle.LoadFromFile 功能一样,都会立刻返回 var _request = UnityWebRequestAssetBundle.GetAssetBundle(path, Bundles.GetHash128(name), 0); _request.SendWebRequest(); while (!_request.isDone) { Thread.Yield(); } _assetBundle = DownloadHandlerAssetBundle.GetContent(_request); _request.Dispose(); if (_assetBundle == null) { error = name + " LoadFromFile failed."; } var items = Bundles.GetBundleDependencies(name.ToLower()); if (items != null && items.Length > 0) { for (int i = 0, I = items.Length; i < I; i++) { var item = items [i]; if (Bundles.IsCyclicDependsLoaded(item)) { #if UNITY_EDITOR Debug.LogWarning("Cyclic dependence " + name); #endif } else { dependencies.Add(Bundles.Load(item)); } } } }
void Update() { bool loading = false; for (int i = 0; i < assets.Count; i++) { var asset = assets[i]; if (asset.isDone) { asset.Update(); if (asset.references <= 0) { asset.Dispose(); asset = null; assets.RemoveAt(i); i--; } } else { loading = true; } } if (!loading) { Bundles.Update(); times += Time.deltaTime; if (times > 120) { times = 0; if (AsyncOperationUnloadUnusedAssets == null) { StartCoroutine(UnloadUnusedAssets()); } } } }
static IEnumerator InitializeBundle() { yield return(Bundles.Initialize()); }
public static bool Exists(string path) { path = path.ToLower(); return(Bundles.GetBundleName(path) != null); }