public void LoadResource(AssetProxy proxy) { if (proxy == null) { return; } proxy.data = AutoGetAssetData(proxy.url); if (proxy.data.isLoaded) { proxy.AssetComplete(); return; } CoroutineUtils.StartCoroutine(DoLoadAsset(proxy)); }
public void Dispose() { if (!isDone) { needDispose = true; return; } if (mMainAsset != null) { mMainAsset.Dispose(); } for (int i = 0; i < mDependAssets.Count; ++i) { if (mDependAssets[i] != null) { mDependAssets[i].Dispose(); } } mMainAsset = null; mDependAssets.Clear(); }
public IEnumerator CreateACCoroutine(string path, string[] depends, CollectComplete collector = null) { mCollector = collector; mPath = path; mDepends = depends; AssetManager.Instance.RecordAssociate(path, depends); if (depends != null) { for (int i = 0; i < depends.Length; ++i) { string dep = depends[i]; AssetProxy proxy = new AssetProxy(dep); proxy.Work(); yield return(proxy.coroutine); mDependAssets.Add(proxy); } } if (path != null) { AssetProxy proxy = new AssetProxy(path); proxy.Work(); yield return(proxy.coroutine); mMainAsset = proxy; } isDone = true; if (needDispose) { Dispose(); } if (collector != null) { collector(this); } }
/// <summary> /// 函数实现的目的: /// 1 执行加载 /// 2 派发通知 /// 3 执行排队 /// </summary> /// <param name="assetProxy"></param> /// <returns></returns> public IEnumerator DoLoadAsset(AssetProxy assetProxy) { ///在加载: if (assetProxy.data.isLoading) { while (!assetProxy.abort && assetProxy.data.isLoading) { yield return(1); } if (assetProxy.abort) { yield break; } assetProxy.AssetComplete(); yield break; } ///排队等待加载: while (!hasAccess && !assetProxy.abort) { yield return(1); } if (assetProxy.abort) { yield break; } ///再检测一次防止,在这期间有多个同时出现的任务: if (assetProxy.data.isLoading) { while (!assetProxy.abort && assetProxy.data.isLoading) { yield return(1); } if (assetProxy.abort) { yield break; } assetProxy.AssetComplete(); yield break; } //如果这期间加载完成了也要返回 if (assetProxy.data.isLoaded) { assetProxy.AssetComplete(); yield break; } IncreaseLoadingWork(); //将权重刷到AssetData中 assetProxy.data.threadPriority = assetProxy.threadPriority; //执行加载 yield return(assetProxy.data.BeginDownLoad()); DecreaseLoadingWork(); assetProxy.AssetComplete(); }