Esempio n. 1
0
        public void UpdateAssetMemoryUsage(MemoryType memoryTypeFlags = (MemoryType)2147483647)
        {
            int  num  = 0;
            long num2 = 0L;

            foreach (KeyValuePair <Type, Metric <int> > item in engineTypeToMetric)
            {
                item.Value.UpdateValueIncrementalReset();
            }
            UnityEngine.Object[] array = Resources.FindObjectsOfTypeAll(typeof(UnityEngine.Object));
            num += array.Length;
            foreach (UnityEngine.Object @object in array)
            {
                Type baseEngineType = getBaseEngineType(@object.GetType());
                if (!engineTypeToMetric.TryGetValue(baseEngineType, out var value))
                {
                    value = OtherAssetMemory;
                }
                int num3 = (int)Profiler.GetRuntimeMemorySizeLong(@object);
                value.UpdateValueIncremental(value.Value + num3);
                num2 += num3;
            }
            AssetMemory.UpdateValue((int)num2);
            AssetCount.UpdateValue(num);
        }
Esempio n. 2
0
    public static void Reassign()
    {
        GameObject gameObject = Selection.activeGameObject;

        if (gameObject == null)
        {
            Debug.Log("You have nothing selected!");
            return;
        }

        Image[] images = gameObject.GetComponentsInChildren <Image>();

        foreach (Image image in images)
        {
            AssetMemory memory = image.GetComponent <AssetMemory>();
            if (memory != null && !memory.assetName.Equals("") && memory.assetType == nameof(Sprite))
            {
                string[] found = AssetDatabase.FindAssets(memory.assetName + " t:sprite");
                foreach (string path in found)
                {
                    Sprite sprite = AssetDatabase.LoadAssetAtPath <Sprite>(AssetDatabase.GUIDToAssetPath(path));
                    if (sprite.name.Equals(memory.assetName))
                    {
                        image.sprite = sprite;
                        DestroyImmediate(memory);
                        EditorUtility.SetDirty(image.gameObject);

                        break;
                    }
                }
            }
        }

        Text[] texts = gameObject.GetComponentsInChildren <Text>();

        foreach (Text text in texts)
        {
            AssetMemory memory = text.GetComponent <AssetMemory>();
            if (memory != null && !memory.assetName.Equals("") && memory.assetType == nameof(Font))
            {
                string[] found = AssetDatabase.FindAssets(memory.assetName + " t:font");
                foreach (string path in found)
                {
                    Font font = AssetDatabase.LoadAssetAtPath <Font>(AssetDatabase.GUIDToAssetPath(path));
                    if (font.name.Equals(memory.assetName))
                    {
                        text.font = font;
                        DestroyImmediate(memory);
                        EditorUtility.SetDirty(text.gameObject);

                        break;
                    }
                }
            }
        }
    }
Esempio n. 3
0
    public static void Riddance()
    {
        GameObject gameObject = Selection.activeGameObject;

        if (gameObject == null)
        {
            Debug.Log("You have nothing selected!");
            return;
        }

        Sprite defSprite = Sprite.Create(Texture2D.whiteTexture, new Rect(0, 0, 4, 4), new Vector2(0.5f, 0.5f));
        Font   defFont   = Resources.GetBuiltinResource <Font>("Arial.ttf");

        Image[] images = gameObject.GetComponentsInChildren <Image>();

        foreach (Image image in images)
        {
            if (image.sprite != null)
            {
                string name = image.sprite.name;

                AssetMemory memory = image.gameObject.AddComponent <AssetMemory>();

                memory.assetName = name;
                memory.assetType = nameof(Sprite);
                image.sprite     = defSprite;
                EditorUtility.SetDirty(image);
            }
        }

        Text[] texts = gameObject.GetComponentsInChildren <Text>();

        foreach (Text text in texts)
        {
            if (text.font != null)
            {
                string name = text.font.name;

                AssetMemory memory = text.gameObject.AddComponent <AssetMemory>();

                memory.assetName = name;
                memory.assetType = nameof(Font);
                text.font        = defFont;
                EditorUtility.SetDirty(text);
            }
        }
    }