/// <summary> /// 开始下载 /// </summary> /// <param name="proxy"></param> /// <returns></returns> protected override IEnumerator OnDownload(AssetDataProxy proxy) { if (proxy == null) { yield break; } proxy.Data.Status = AssetStatus.Status_Loading; WWW www = new WWW(proxy.Url); www.threadPriority = Strategy.ThreadPriority; proxy.Data.OnDownloadStart(www); yield return(www); proxy.Data.OnDonwloadFinish(); if (!string.IsNullOrEmpty(www.error)) { proxy.Data.Result = AssetResult.Result_Error; } else { proxy.Data.Result = AssetResult.Result_Succeed; } }
/// <summary> /// 加载 /// </summary> /// <param name="proxy"></param> public virtual void Load(AssetDataProxy proxy) { if (m_queueLoading != null) { m_queueLoading.Enqueue(proxy); } CoroutineUtil.StartCoroutine(OnLoading()); }
/// <summary> /// 加载资源 /// </summary> /// <param name="proxy"></param> public void LoadAsset(AssetDataProxy proxy) { if (proxy == null) { return; } proxy.Data = GetAsset(proxy.Url); if (proxy.Data.IsLoaded) { proxy.AssetComplete(); return; } Loader.Load(proxy); }
public void Dispose() { if (!m_isDone) { m_needDispose = true; return; } if (m_mainAsset != null) { m_mainAsset.Dispose(); } for (int i = 0; i < m_dependAssets.Count; ++i) { if (m_dependAssets[i] != null) { m_dependAssets[i].Dispose(); } } m_mainAsset = null; m_dependAssets.Clear(); }
public IEnumerator CreateACCoroutine(string path, string[] depends, CollectComplete collector = null) { m_collector = collector; m_path = path; m_depends = depends; AssetFactory.Instance.RecordAssociate(path, depends); if (depends != null) { for (int i = 0; i < depends.Length; ++i) { string dep = depends[i]; AssetDataProxy proxy = new AssetDataProxy(dep); proxy.OnWork(); yield return(proxy.Coroutine); m_dependAssets.Add(proxy); } } if (path != null) { AssetDataProxy proxy = new AssetDataProxy(path); proxy.OnWork(); yield return(proxy.Coroutine); m_mainAsset = proxy; } m_isDone = true; if (m_needDispose) { Dispose(); } if (collector != null) { collector(this); } }
/// <summary> /// 进入下载状态 /// </summary> /// <returns></returns> protected override IEnumerator OnLoading() { AssetDataProxy proxy = GetLoadProxy(); if (proxy == null) { yield break; } // 正在加载 if (proxy.Data.IsLoading) { while (!proxy.IsAbort && proxy.Data.IsLoading) { yield return(1); } if (proxy.IsAbort) { yield break; } proxy.AssetComplete(); yield break; } // 排队等待 while (!HasAccess && !proxy.IsAbort) { yield return(1); } if (proxy.IsAbort) { yield break; } // 再次检测 if (proxy.Data.IsLoading) { while (!proxy.IsAbort && proxy.Data.IsLoading) { yield return(1); } if (proxy.IsAbort) { yield break; } proxy.AssetComplete(); yield break; } // 加载完成 if (proxy.Data.IsLoaded) { proxy.AssetComplete(); yield break; } // 开始加载 IncreaseLoadingWork(); CoroutineUtil.StartCoroutine(OnDownload(proxy)); DecreaseLoadingWork(); proxy.AssetComplete(); }
/// <summary> /// 开始下载状态 /// </summary> /// <returns></returns> protected abstract IEnumerator OnDownload(AssetDataProxy proxy);
protected override IEnumerator OnDownload(AssetDataProxy proxy) { throw new NotImplementedException(); }
/// <summary> /// 进入加载 /// </summary> /// <param name="proxy"></param> public static void EnterLoad(AssetDataProxy proxy) { Instance.LoadAsset(proxy); }