├── README.md ├── .gitignore ├── LICENSE └── Editor └── TextureArrayEditor.cs /README.md: -------------------------------------------------------------------------------- 1 | The TextureArrayEditor is a unity inspector designed to show you the content of a texture array in the project. Select the array in project it and get a preview. 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /[Ll]ibrary/ 2 | /[Tt]emp/ 3 | /[Oo]bj/ 4 | /[Bb]uild/ 5 | /[Bb]uilds/ 6 | /Assets/AssetStoreTools* 7 | 8 | # Visual Studio 2015 cache directory 9 | /.vs/ 10 | 11 | # Autogenerated VS/MD/Consulo solution and project files 12 | ExportedObj/ 13 | .consulo/ 14 | *.csproj 15 | *.unityproj 16 | *.sln 17 | *.suo 18 | *.tmp 19 | *.user 20 | *.userprefs 21 | *.pidb 22 | *.booproj 23 | *.svd 24 | *.pdb 25 | 26 | # Unity3D generated meta files 27 | *.pidb.meta 28 | 29 | # Unity3D Generated File On Crash Reports 30 | sysinfo.txt 31 | 32 | # Builds 33 | *.apk 34 | *.unitypackage 35 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 AwesomeTechnologies 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Editor/TextureArrayEditor.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEditor; 4 | using UnityEngine; 5 | 6 | namespace AwesomeTechnologies.MIT 7 | { 8 | [CustomEditor(typeof(Texture2DArray))] 9 | public class TextureArrayEditor : Editor 10 | { 11 | private readonly List _previewTextureList = new List(); 12 | 13 | public void OnEnable() 14 | { 15 | Texture2DArray texture2DArray = (Texture2DArray)target; 16 | 17 | for (int i = 0; i <= texture2DArray.depth - 1; i++) 18 | { 19 | 20 | // annoying to work around all the odd unity issues 21 | // copy to temp texture.. 22 | Texture2D tempTexture = new Texture2D(texture2DArray.width, texture2DArray.height, texture2DArray.format, true, true); 23 | Graphics.CopyTexture(texture2DArray, i, tempTexture, 0); 24 | tempTexture.Apply(); 25 | 26 | // blit to render target 27 | RenderTexture rt = RenderTexture.GetTemporary(256, 256, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); 28 | Graphics.Blit(tempTexture, rt); 29 | 30 | // read back from render target 31 | DestroyImmediate(tempTexture); 32 | tempTexture = new Texture2D(256, 256, TextureFormat.ARGB32, false, true); 33 | var old = RenderTexture.active; 34 | RenderTexture.active = rt; 35 | tempTexture.ReadPixels(new Rect(0, 0, 256, 256), 0, 0); 36 | tempTexture.Apply(); 37 | RenderTexture.active = old; 38 | 39 | // work around linear/gamma issue with GUI. 40 | tempTexture.LoadImage(tempTexture.EncodeToJPG()); 41 | tempTexture.Apply(); 42 | _previewTextureList.Add(tempTexture); 43 | } 44 | } 45 | 46 | public void OnDisable() 47 | { 48 | for (int i = 0; i <= _previewTextureList.Count - 1; i++) 49 | { 50 | DestroyImmediate(_previewTextureList[i]); 51 | } 52 | _previewTextureList.Clear(); 53 | } 54 | 55 | public override void OnInspectorGUI() 56 | { 57 | EditorGUILayout.LabelField("Texture array content"); 58 | 59 | Texture2DArray texture2DArray = (Texture2DArray)target; 60 | GUIContent[] imageButtons = new GUIContent[texture2DArray.depth]; 61 | 62 | for (int i = 0; i <= texture2DArray.depth - 1; i++) 63 | { 64 | if (_previewTextureList.Count > i) 65 | { 66 | imageButtons[i] = new GUIContent { image = _previewTextureList[i] }; 67 | } 68 | else 69 | { 70 | imageButtons[i] = new GUIContent { image = null }; 71 | } 72 | } 73 | int imageWidth = 120; 74 | int columns = Mathf.FloorToInt(EditorGUIUtility.currentViewWidth / imageWidth); 75 | int rows = Mathf.CeilToInt((float)imageButtons.Length / columns); 76 | int gridHeight = (rows) * imageWidth; 77 | GUILayout.SelectionGrid(0, imageButtons, columns, GUI.skin.label, GUILayout.MaxWidth(columns * imageWidth), GUILayout.MaxHeight(gridHeight)); 78 | 79 | texture2DArray.anisoLevel = EditorGUILayout.IntField("Anisotropic", texture2DArray.anisoLevel); 80 | texture2DArray.filterMode = (FilterMode)EditorGUILayout.EnumPopup("Filter Mode", texture2DArray.filterMode); 81 | texture2DArray.wrapMode = (TextureWrapMode)EditorGUILayout.EnumPopup("Wrap Mode", texture2DArray.wrapMode); 82 | texture2DArray.mipMapBias = EditorGUILayout.FloatField("Mip Map Bias", texture2DArray.mipMapBias); 83 | 84 | EditorGUILayout.LabelField("Texture count: " + texture2DArray.depth); 85 | EditorGUILayout.LabelField("Width: " + texture2DArray.width); 86 | EditorGUILayout.LabelField("Height: " + texture2DArray.height); 87 | EditorGUILayout.LabelField("Texture format: " + texture2DArray.format); 88 | 89 | } 90 | } 91 | } 92 | --------------------------------------------------------------------------------