Exemple #1
0
 private static void OnLowMemoryCallBack()
 {
     Debug.LogWarning("低内存警告!!!");
     if (Application.platform != RuntimePlatform.Android)
     {
         FreeMemory();
         AssetsUnloadHandler.UnloadAll();
     }
 }
Exemple #2
0
    static void Update()
    {
        //内存管理
        MonitorMemorySize();

    #if UNITY_EDITOR
        if (Input.GetKeyDown(KeyCode.F12))
        {
            FreeMemory();
            AssetsUnloadHandler.UnloadAll();
        }
#endif
    }
    private void DrawLoadAssets()
    {
        long allSize = 0;

        foreach (var item in assetsCaches)
        {
            allSize += item.Value.GetTotalMemorySize();
        }
        GUILayout.BeginHorizontal();
        GUILayout.BeginVertical();
        GUILayout.Label("资源占用:" + (allSize / 1024f / 1024).ToString("F") + "MB");
        GUILayout.Space(4);
        EditorDrawGUIUtil.CanEdit = true;
        onlyShowNoRef             = (bool)EditorDrawGUIUtil.DrawBaseValue("是否只显示无引用资源", onlyShowNoRef);
        EditorDrawGUIUtil.CanEdit = false;
        GUILayout.EndVertical();
        GUILayout.BeginVertical();
        if (GUILayout.Button("清空对象池配置缓存"))
        {
            MemoryManager.FreeMemory();
        }
        if (GUILayout.Button("全部卸载(" + AssetsUnloadHandler.noUsedAssetsList.Count + ")"))
        {
            AssetsUnloadHandler.UnloadAll();
        }

        GUILayout.EndVertical();
        GUILayout.EndHorizontal();
        GUILayout.Space(4);
        EditorDrawGUIUtil.DrawScrollView(this, () =>
        {
            List <AssetsData> assetList = new List <AssetsData>(assetsCaches.Values);
            assetList.Sort((t0, t1) =>
            {
                if (t0.GetTotalMemorySize() > t1.GetTotalMemorySize())
                {
                    return(-1);
                }
                else if (t0.GetTotalMemorySize() < t1.GetTotalMemorySize())
                {
                    return(1);
                }

                return(0);
            });
            for (int i = 0; i < assetList.Count; i++)
            {
                AssetsData item = assetList[i];
                if (!string.IsNullOrEmpty(bundleSearchValue))
                {
                    if (!item.assetName.Contains(bundleSearchValue.ToLower()))
                    {
                        continue;
                    }
                }
                if (onlyShowNoRef && item.refCount > 0)
                {
                    continue;
                }
                DrawAssetsData(i, item);
            }
        }, "box");
    }