Created
March 1, 2016 17:04
-
-
Save Giacom/634d90d5918f9b9c4c67 to your computer and use it in GitHub Desktop.
A Unity Editor script to list all the atlases in your project and to show their file sizes when built.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #if UNITY_EDITOR | |
| using UnityEngine; | |
| using System.Collections; | |
| using UnityEditor; | |
| using UnityEditor.Sprites; | |
| using System.Collections.Generic; | |
| using System; | |
| [ExecuteInEditMode] | |
| public class ViewAtlasSize : EditorWindow { | |
| private Vector2 scrollPosition; | |
| [MenuItem("Window/View Atlas Sizes")] | |
| public static void Init() { | |
| ViewAtlasSize window = (ViewAtlasSize)EditorWindow.GetWindow (typeof (ViewAtlasSize)); | |
| window.titleContent.text = "Atlas Sizes"; | |
| window.Show(); | |
| } | |
| public void OnGUI () { | |
| GUILayout.Label ("Atlas Sizes\n", EditorStyles.boldLabel); | |
| scrollPosition = GUILayout.BeginScrollView(scrollPosition); | |
| for (int i = 0; i < Packer.atlasNames.Length; i++) { | |
| string atlas = Packer.atlasNames[i]; | |
| List<Texture2D[]> atlasTextures = new List<Texture2D[]>(); | |
| atlasTextures.Add(Packer.GetTexturesForAtlas(atlas)); | |
| //atlasTextures.Add(Packer.GetAlphaTexturesForAtlas(atlas)); | |
| GUILayout.Label("\t" + atlas, EditorStyles.label); | |
| foreach (Texture2D[] textures in atlasTextures) { | |
| foreach (Texture2D texture in textures) { | |
| if (texture == null) { | |
| return; | |
| } | |
| GUILayout.Label("\t\t" + texture.name + "(" + texture.format.ToString() + ")" + " - " + GetMemorySize(texture) + "MB"); | |
| } | |
| } | |
| } | |
| GUILayout.EndScrollView(); | |
| } | |
| [MenuItem("Assets/Get File Size")] | |
| public static void PrintFileSize() { | |
| if (Selection.activeObject == null && Selection.activeObject.GetType() == typeof(Texture2D)) { | |
| return; | |
| } | |
| Debug.LogError(Selection.activeObject.name + " - " + GetMemorySize((Texture2D)Selection.activeObject) + "MB"); | |
| } | |
| private static float GetMemorySize(Texture2D texture) { | |
| return (float)Math.Round(((double)(texture.GetRawTextureData().Length) / 1000000), 2); | |
| } | |
| } | |
| #endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment