private Queue <DownLoadCoroutine> m_qCoroutineInFree = new Queue <DownLoadCoroutine>(); //Coroutine管理,保存空闲的Coroutine; /// <summary> /// 获取一个空闲Coroutine; /// </summary> private DownLoadCoroutine GetAssetLoadCoroutine(string strKey) { if (!m_AllAssets.ContainsKey(strKey)) { Debug.LogWarning("DownLoadControl GetDownLoadCoroutine, Don't Has Key: " + strKey + " ??"); return(null); } if (m_AllAssets[strKey].m_loadCoroutine != null) { Debug.LogWarning("DownLoadControl GetDownLoadCoroutine, Already has Coroutine : " + strKey); return(null); } DownLoadCoroutine gtFreeCoroutine = null; if (m_qCoroutineInFree.Count != 0) { gtFreeCoroutine = m_qCoroutineInFree.Dequeue();//踢出队列; } if (gtFreeCoroutine == null) { gtFreeCoroutine = m_objLoaderCoroutine.AddComponent <DownLoadCoroutine>(); } m_AllAssets[strKey].m_loadCoroutine = gtFreeCoroutine; return(gtFreeCoroutine); }
static public void RemoveDownLoad(string strName, Callback <object> callBack, bool isKeepDownLoading) { if (m_AssetPackMap.ContainsKey(strName)) { DownLoadPack pack = m_AssetPackMap[strName]; if (pack != null) { pack.m_AssetRefer--; pack.AssetInfo.m_callBack -= callBack; if (pack.m_AssetRefer <= 0) //可能会出现小于0的情况,下载到一半停止,资源没有被引用,计数为0可以被删. { pack.AssetInfo.m_callBack = null; //卸载完成callback一定会为null.之前的 CallBack -= 并不一定能确保CallBack被清空了. if (!isKeepDownLoading) { //不保持下载,正常卸载流程; if (pack.State != AssetState.Finish) //为下载完,被卸载,本地没有保存,已下载size不需要增加; { m_nDownLoadSize -= pack.AssetInfo.m_nSize; } DownLoadCoroutine freeCoroutine = pack.ReleaseDownLoadCoroutine(); RecycleDownLoadCoroutine(freeCoroutine); m_AssetPackMap.Remove(strName); if (m_AssetPackNameList.Contains(strName)) { m_AssetPackNameList.Remove(strName); } } } } } }
/// <summary> /// 释放一个在用的Coroutine; /// </summary> private static void RecycleDownLoadCoroutine(DownLoadCoroutine downLoadCoroutine) { if (downLoadCoroutine != null) { downLoadCoroutine.StopAllCoroutines(); //必须立即结束; m_qCoroutineInFree.Enqueue(downLoadCoroutine); //放入空闲队列里; } }
public void LoadAsset(DownLoadCoroutine coroutine) { if (coroutine != null) { m_DownLoadCoroutine = coroutine; coroutine.StartCoroutine(LoadAsset()); //开始一个新任务; } }
private void ReleaseDownLoadCoroutine() { if (m_roleBodyloaderCoroutine != null) { m_roleBodyloaderCoroutine.StopAllCoroutines(); Component.Destroy(m_roleBodyloaderCoroutine); m_roleBodyloaderCoroutine = null; } }
public void LoadBodyAsync(Callback <RoleBodyLoader, bool> callBack) { DownLoadCoroutine gtDLC = GetDownLoadCoroutine(); if (gtDLC != null) { m_callBackDownLoadFinish = callBack; gtDLC.StartCoroutine(LoadBody()); } }
/// <summary> /// 停止某个链接下载; /// </summary> static public void StopLoad(string strName) { if (m_AssetPackMap.ContainsKey(strName)) { DownLoadPack pack = m_AssetPackMap[strName]; if (pack != null) { DownLoadCoroutine freeCoroutine = pack.ReleaseDownLoadCoroutine(); RecycleDownLoadCoroutine(freeCoroutine); pack.Stop(); } } }
/// <summary> /// 内部下载接口; /// </summary> private void LoadAsset(string assetName, bool bResident, Callback <string> callBack, bool isOnlyDownLoad, DownLoadOrderType downLoadOrderType, bool isKeepLoading) { AssetPack assetPack = null; if (m_AllAssets.ContainsKey(assetName)) { assetPack = m_AllAssets[assetName]; if (!assetPack.m_IsResident) { if (bResident) { assetPack.m_IsResident = true; assetPack.m_AssetRefer = 0; } else { if (isKeepLoading) //如果外部设置为KeepLoading,那么资源会切换为KeepLoading状态; { assetPack.m_nKeepLoadingRefer++; } assetPack.m_AssetRefer++; } } assetPack.m_CallBack += callBack; if (assetPack.AssetReady) { if (callBack != null) { callBack(assetName); } } } else { assetPack = new AssetPack(assetName, bResident, isKeepLoading); m_AllAssets.Add(assetName, assetPack); assetPack.m_CallBack += callBack; DownLoadCoroutine gtDLC = GetAssetLoadCoroutine(assetName); if (gtDLC != null) { gtDLC.StartCoroutine(LoadingAsset(assetName, isOnlyDownLoad, downLoadOrderType)); } else { Debug.LogError("AssetLoader LoadAssetAsync,Coroutine Obj can not be null."); } } }
/// <summary> /// 释放一个在用的Coroutine; /// </summary> private void ReleaseDownLoadCoroutine(string strKey) { if (m_AllAssets.ContainsKey(strKey)) { DownLoadCoroutine downLoadCoroutine = m_AllAssets[strKey].m_loadCoroutine; m_AllAssets[strKey].m_loadCoroutine = null; if (downLoadCoroutine != null) { downLoadCoroutine.StopAllCoroutines(); //必须立即结束; m_qCoroutineInFree.Enqueue(downLoadCoroutine); //放入空闲队列里; } } }
/// <summary> /// 释放一个在用的Coroutine; /// </summary> public DownLoadCoroutine ReleaseDownLoadCoroutine() { if (m_DownLoadCoroutine != null) { DownLoadCoroutine coroutine = m_DownLoadCoroutine; m_DownLoadCoroutine.StopAllCoroutines(); //必须立即结束; m_DownLoadCoroutine = null; return(coroutine); } return(null); }
/// <summary> /// 获取一个空闲Coroutine; /// </summary> private static DownLoadCoroutine GetDownLoadCoroutine() { if (m_objLoaderCoroutine == null) { Debug.LogError("WWWDownLoader GetAssetLoadCoroutine,m_objLoaderCoroutine can not be null."); return(null); } DownLoadCoroutine gtFreeCoroutine = null; if (m_qCoroutineInFree.Count != 0) { gtFreeCoroutine = m_qCoroutineInFree.Dequeue(); //踢出队列; } if (gtFreeCoroutine == null) { gtFreeCoroutine = m_objLoaderCoroutine.AddComponent <DownLoadCoroutine>(); } return(gtFreeCoroutine); }
private DownLoadCoroutine GetDownLoadCoroutine() { if (m_roleBodyLoadCoroutineObj == null) { GameObject gtGroupObj = GameObject.Find("LoaderCoroutineGroup"); if (gtGroupObj == null) { gtGroupObj = new GameObject("LoaderCoroutineGroup"); GameObject.DontDestroyOnLoad(gtGroupObj); } m_roleBodyLoadCoroutineObj = new GameObject("RoleBodyLoadCoroutine");//Coroutine节点; m_roleBodyLoadCoroutineObj.transform.parent = gtGroupObj.transform; GameObject.DontDestroyOnLoad(m_roleBodyLoadCoroutineObj); } if (m_roleBodyloaderCoroutine == null) { m_roleBodyloaderCoroutine = m_roleBodyLoadCoroutineObj.AddComponent <DownLoadCoroutine>(); return(m_roleBodyloaderCoroutine); } return(null); }