/// <summary> /// 删除资源 /// </summary> /// <param name="res"></param> private static void DeleteSpriteResource(ref ResNode res, bool Immediate) { if (null == res || !isVaild || res.GetRefCount() <= 0) { return; } //先看看是不是通用资源 if (IsCommonAssets(res)) { res.Release(); return; } //只要有一个需要理解卸载,那么就得立刻卸载 if (!res.UnLoadImmediate) { res.UnLoadImmediate = Immediate; } int guid = res.instanceID; //有这个资源 if (m_SpriteTable.ContainsKey(guid)) { int refCount = res.Release(); //这个资源已经没有人引用了 if (refCount <= 0) { m_SpriteTable[guid] = null; m_SpriteTable.Remove(guid); if (!res.UnLoadImmediate) { CacheSpriteResource(res); } else { if (m_UISpriteCacheTable.ContainsKey(guid)) { m_UISpriteCacheTable.Remove(guid); } UnLoadResource(ref res); } } } else { Debug.LogError("要卸载的资源不是Sprite,忽略此资源,有可能会存在资源泄露!:" + res.AssetBundleName + "," + res.AssetName); } res = null; }
public static void DeletePrefab(ref ResNode res, bool Immediate = true) { if (null == res || !isVaild || res.GetRefCount() <= 0) { return; } //先看看是不是通用资源 if (IsCommonAssets(res)) { res.Release(); return; } if (!res.UnLoadImmediate) { res.UnLoadImmediate = Immediate; } //有这个资源 if (m_PrefabResTable.ContainsKey(res.instanceID)) { int refCount = res.Release(); //这个资源已经没有人引用了 if (refCount <= 0) { DeletePrefabResource(ref res, Immediate); } } else { Debug.LogError("要卸载的资源不是预制体,忽略此资源,有可能会存在资源泄露!:" + res.AssetBundleName + "," + res.AssetName); } res = null; }
/// <summary> /// 删除异步加载的资源,与GetFBXResourceAsync对应 /// </summary> /// <param name="res"></param> /// <param name="callBack"></param> private static void DeleteAnimationClipResourceAsync(ref ResNode res, System.Action <ResConfigData, ResNode, System.Object> callBack, bool Immediate) { if (null == res || !isVaild || res.GetRefCount() <= 0) { return; } //先看看是不是通用资源 if (IsCommonAssets(res)) { res.Release(); RemoveFromDelayCallBackList(res, callBack); return; } //只要有一个需要理解卸载,那么就得立刻卸载 if (!res.UnLoadImmediate) { res.UnLoadImmediate = Immediate; } //编辑器下没有异步 if (!isOnRunTimeMode) { RemoveFromDelayCallBackList(res, callBack); DeleteAnimationClipResource(ref res, Immediate); return; } int guid = res.instanceID; //有这个资源 if (m_AnimationClipResTable.ContainsKey(guid)) { int refCount = res.Release(); //这个资源已经没有人引用了 if (refCount <= 0) { RemoveAllResCallBack(m_ResCallBackTable, res); RemoveAllDelayCallBackList(res); m_AnimationClipResTable[guid] = null; m_AnimationClipResTable.Remove(guid); if (!res.UnLoadImmediate) { CacheAnimationClipResource(res); } else { if (m_AnimationClipCacheResTable.ContainsKey(guid)) { m_AnimationClipCacheResTable.Remove(guid); } UnLoadResource(ref res); } } else { RemoveResCallBack(m_ResCallBackTable, res, callBack); RemoveFromDelayCallBackList(res, callBack); } } else { Debug.LogError("要卸载的资源不是AnimationClip,忽略此资源,有可能会存在资源泄露!:" + res.AssetBundleName + "," + res.AssetName); } res = null; }
private static void DeletePrefabAsync(ref ResNode res, System.Action <ResConfigData, ResNode, System.Object> callBack, bool Immediate = true) { if (null == res || !isVaild || res.GetRefCount() <= 0) { return; } //先看看是不是通用资源 if (IsCommonAssets(res)) { res.Release(); RemoveFromDelayCallBackList(res, callBack); return; } int guid = res.instanceID; //表里面有这个预制体的话,说明依赖是加载成功了的。但是预制体本体可能加载完成,也可能是在加载中 if (m_PrefabResTable.ContainsKey(guid)) { int refCount = res.Release(); //这个资源已经没有人引用了 if (refCount <= 0) { RemoveAllDelayCallBackList(res); RemoveAllResCallBack(m_PrefabRequestTable, res); DeletePrefabResourceAsync(ref res, PrefabResourceCallBack, Immediate); } else { RemoveFromDelayCallBackList(res, callBack); RemoveResCallBack(m_PrefabRequestTable, res, callBack); } } else { //如果没有在预制体表里的,说明还处于依赖加载中 if (m_AsyncLoadingDependicensPrefabResNode.ContainsKey(guid)) { int refCount = res.Release(); //这个资源已经没有人引用了 if (refCount <= 0) { UnLoadDependenicesAsync(guid); //m_NeedToDeletePrefab.Add(guid); m_AsyncLoadingDependicensPrefabResNode.Remove(guid); RemoveAllDelayCallBackList(res); RemoveAllResCallBack(m_PrefabRequestTable, res); res.Clear(); } else { RemoveFromDelayCallBackList(res, callBack); RemoveResCallBack(m_PrefabRequestTable, res, callBack); } } else { Debug.LogError("要卸载的资源不是预制体,忽略此资源,有可能会存在资源泄露!:" + res.AssetBundleName + "," + res.AssetName); } } res = null; }