private void DrawUnloadAssets() { GUILayout.Space(4); EditorDrawGUIUtil.DrawScrollView(this, () => { List <UnloadAssetInfo> assetList = AssetsUnloadHandler.noUsedAssetsList; for (int i = 0; i < assetList.Count; i++) { UnloadAssetInfo item = assetList[i]; if (!string.IsNullOrEmpty(bundleSearchValue)) { if (!item.assetsName.Contains(bundleSearchValue.ToLower())) { continue; } } EditorDrawGUIUtil.DrawFoldout(item, "(" + item.useTimes + ")" + item.assetsName + "(" + item.GetFrequency() + ")", () => { DrawAssetsData(i, item.assets); }); } }, "box"); }
private static UnloadAssetInfo MakeUseLogic(string assetName, AssetsData assets = null, bool isHaveDependencies = true) { UnloadAssetInfo info = null; if (noUsedAssetsDic.ContainsKey(assetName)) { info = noUsedAssetsDic[assetName]; noUsedAssetsDic.Remove(assetName); if (noUsedAssetsList.Contains(info)) { noUsedAssetsList.Remove(info); } usedAssetsDic.Add(assetName, info); } else if (usedAssetsDic.ContainsKey(assetName)) { info = usedAssetsDic[assetName]; } else { info = new UnloadAssetInfo(isHaveDependencies, assets); usedAssetsDic.Add(assetName, info); //noUsedAssetsList.Add(info); } if (assets != null) { info.assets = assets; } info.useTimes++; return(info); }
public static void UnloadOne() { if (noUsedAssetsList.Count > 0) { UnloadAssetInfo info = noUsedAssetsList[0]; noUsedAssetsList.RemoveAt(0); if (unloadBundleQue.ContainsKey(info.assetsName)) { unloadBundleQue.Remove(info.assetsName); } ResourceManager.ReleaseByPath(info.assets.assetPath); } }
/// <summary> /// 记录资源的加载 /// </summary> /// <param name="assets"></param> public static void MarkUseAssets(AssetsData assets, bool isHaveDependencies) { UnloadAssetInfo info = MakeUseLogic(assets.assetName, assets, isHaveDependencies); //无依赖的资源进入卸载Bundle压缩包的队列 if (assets.AssetBundle != null && !isHaveDependencies) { info.unloadBundleTime = 5; if (!unloadBundleQue.ContainsKey(info.assetsName)) { unloadBundleQue.Add(info.assetsName, info); } } }
private static int SortNoUsedAssetsInfo(UnloadAssetInfo x, UnloadAssetInfo y) { //自资源废弃到现在的时间 / 资源使用次数 float freqX = x.GetFrequency(); float freqY = y.GetFrequency(); if (freqX < freqY) { return(1); } else if (freqX > freqY) { return(-1); } return(0); }
/// <summary> /// 当资源在游戏中无引用时,传过来记录 /// </summary> /// <param name="assets"></param> public static void DiscardAssets(AssetsData assets) { if (!usedAssetsDic.ContainsKey(assets.assetName)) { //Debug.LogError("资源未加载=>:" + assets.assetPath); return; } UnloadAssetInfo info = null; info = usedAssetsDic[assets.assetName]; usedAssetsDic.Remove(assets.assetName); info.discardTime = Time.realtimeSinceStartup; noUsedAssetsDic.Add(info.assetsName, info); noUsedAssetsList.Add(info); noUsedAssetsList.Sort(SortNoUsedAssetsInfo); }