From 9555c6aa7682a59d43e65052a1566d4d87f37249 Mon Sep 17 00:00:00 2001 From: SolidAlloy Date: Wed, 24 Feb 2021 12:37:10 +0200 Subject: [PATCH 1/3] Removed the Icons folder --- Editor/Icons.meta | 3 - Editor/Icons/HierarchyFolderIcon.cs | 172 ----------------- Editor/Icons/HierarchyFolderIcon.cs.meta | 11 -- Editor/Icons/ReplaceColor Shader.shader | 21 -- Editor/Icons/ReplaceColor Shader.shader.meta | 10 - Editor/Icons/TextureHelper.cs | 191 ------------------- Editor/Icons/TextureHelper.cs.meta | 3 - 7 files changed, 411 deletions(-) delete mode 100644 Editor/Icons.meta delete mode 100644 Editor/Icons/HierarchyFolderIcon.cs delete mode 100644 Editor/Icons/HierarchyFolderIcon.cs.meta delete mode 100644 Editor/Icons/ReplaceColor Shader.shader delete mode 100644 Editor/Icons/ReplaceColor Shader.shader.meta delete mode 100644 Editor/Icons/TextureHelper.cs delete mode 100644 Editor/Icons/TextureHelper.cs.meta diff --git a/Editor/Icons.meta b/Editor/Icons.meta deleted file mode 100644 index 85e73a5..0000000 --- a/Editor/Icons.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 9b9b359874c54b8e9968bce99b84b1cd -timeCreated: 1613920209 \ No newline at end of file diff --git a/Editor/Icons/HierarchyFolderIcon.cs b/Editor/Icons/HierarchyFolderIcon.cs deleted file mode 100644 index 6286677..0000000 --- a/Editor/Icons/HierarchyFolderIcon.cs +++ /dev/null @@ -1,172 +0,0 @@ -#if UNITY_2019_1_OR_NEWER -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using UnityEditor; -using UnityEditor.IMGUI.Controls; -using UnityEngine; -using UnityHierarchyFolders.Runtime; -using Object = UnityEngine.Object; - -namespace UnityHierarchyFolders.Editor -{ - public static class HierarchyFolderIcon - { -#if UNITY_2020_1_OR_NEWER - private const string _openedFolderPrefix = "FolderOpened"; -#else - private const string _openedFolderPrefix = "OpenedFolder"; -#endif - private const string _closedFolderPrefix = "Folder"; - - private static Texture2D _openFolderTexture; - private static Texture2D _closedFolderTexture; - private static Texture2D _openFolderSelectedTexture; - private static Texture2D _closedFolderSelectedTexture; - - private static bool _isInitialized; - private static bool _hasProcessedFrame = true; - - // Reflected members - [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Special naming scheme")] - private static PropertyInfo prop_sceneHierarchy; - [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Special naming scheme")] - private static PropertyInfo prop_treeView; - [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Special naming scheme")] - private static PropertyInfo prop_data; - [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Special naming scheme")] - private static PropertyInfo prop_selectedIcon; - [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Special naming scheme")] - private static PropertyInfo prop_objectPPTR; - - [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Special naming scheme")] - private static MethodInfo meth_getRows; - [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Special naming scheme")] - private static MethodInfo meth_isExpanded; - [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Special naming scheme")] - private static MethodInfo meth_getAllSceneHierarchyWindows; - - private static (Texture2D open, Texture2D closed)[] _coloredFolderIcons; - public static (Texture2D open, Texture2D closed) ColoredFolderIcons(int i) => _coloredFolderIcons[i]; - - public static int IconColumnCount => IconColors.GetLength(0); - public static int IconRowCount => IconColors.GetLength(1); - - private static readonly Color[,] IconColors = { - {new Color(0.09f, 0.57f, 0.82f), new Color(0.05f, 0.34f, 0.48f),}, - {new Color(0.09f, 0.67f, 0.67f), new Color(0.05f, 0.42f, 0.42f),}, - {new Color(0.23f, 0.73f, 0.36f), new Color(0.15f, 0.41f, 0.22f),}, - {new Color(0.55f, 0.35f, 0.71f), new Color(0.35f, 0.24f, 0.44f),}, - {new Color(0.78f, 0.27f, 0.55f), new Color(0.52f, 0.15f, 0.35f),}, - {new Color(0.80f, 0.66f, 0.10f), new Color(0.56f, 0.46f, 0.02f),}, - {new Color(0.91f, 0.49f, 0.13f), new Color(0.62f, 0.33f, 0.07f),}, - {new Color(0.91f, 0.30f, 0.24f), new Color(0.77f, 0.15f, 0.09f),}, - {new Color(0.35f, 0.49f, 0.63f), new Color(0.24f, 0.33f, 0.42f),}, - }; - - [InitializeOnLoadMethod] - private static void Startup() - { - EditorApplication.update += ResetFolderIcons; - EditorApplication.hierarchyWindowItemOnGUI += RefreshFolderIcons; - } - - private static void InitIfNeeded() - { - if (_isInitialized) { return; } - - _openFolderTexture = (Texture2D)EditorGUIUtility.IconContent($"{_openedFolderPrefix} Icon").image; - _closedFolderTexture = (Texture2D)EditorGUIUtility.IconContent($"{_closedFolderPrefix} Icon").image; - - // We could use the actual white folder icons but I prefer the look of the tinted white folder icon - // To use the actual white version: - // texture = (Texture2D) EditorGUIUtility.IconContent($"{OpenedFolderPrefix | ClosedFolderPrefix} On Icon").image; - _openFolderSelectedTexture = TextureHelper.GetWhiteTexture(_openFolderTexture, $"{_openedFolderPrefix} Icon White"); - _closedFolderSelectedTexture = TextureHelper.GetWhiteTexture(_closedFolderTexture, $"{_closedFolderPrefix} Icon White"); - - _coloredFolderIcons = new (Texture2D, Texture2D)[] { (_openFolderTexture, _closedFolderTexture) }; - - for (int row = 0; row < IconRowCount; row++) - { - for (int column = 0; column < IconColumnCount; column++) - { - int index = 1 + column + row * IconColumnCount; - var color = IconColors[column, row]; - - var openFolderIcon = TextureHelper.GetTintedTexture(_openFolderSelectedTexture, - color, $"{_openFolderSelectedTexture.name} {index}"); - var closedFolderIcon = TextureHelper.GetTintedTexture(_closedFolderSelectedTexture, - color, $"{_closedFolderSelectedTexture.name} {index}"); - - ArrayUtility.Add(ref _coloredFolderIcons, (openFolderIcon, closedFolderIcon)); - } - } - - // reflection - - const BindingFlags BindingAll = BindingFlags.Public - | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance; - - var assembly = typeof(SceneView).Assembly; - - var type_sceneHierarchyWindow = assembly.GetType("UnityEditor.SceneHierarchyWindow"); - meth_getAllSceneHierarchyWindows = type_sceneHierarchyWindow.GetMethod("GetAllSceneHierarchyWindows", BindingAll); - prop_sceneHierarchy = type_sceneHierarchyWindow.GetProperty("sceneHierarchy"); - - var type_sceneHierarchy = assembly.GetType("UnityEditor.SceneHierarchy"); - prop_treeView = type_sceneHierarchy.GetProperty("treeView", BindingAll); - - var type_treeViewController = assembly.GetType("UnityEditor.IMGUI.Controls.TreeViewController"); - prop_data = type_treeViewController.GetProperty("data", BindingAll); - - var type_iTreeViewDataSource = assembly.GetType("UnityEditor.IMGUI.Controls.ITreeViewDataSource"); - meth_getRows = type_iTreeViewDataSource.GetMethod("GetRows"); - meth_isExpanded = type_iTreeViewDataSource.GetMethod("IsExpanded", new Type[] { typeof(TreeViewItem) }); - - var type_gameObjectTreeViewItem = assembly.GetType("UnityEditor.GameObjectTreeViewItem"); - prop_selectedIcon = type_gameObjectTreeViewItem.GetProperty("selectedIcon", BindingAll); - prop_objectPPTR = type_gameObjectTreeViewItem.GetProperty("objectPPTR", BindingAll); - - _isInitialized = true; - } - - private static void ResetFolderIcons() - { - InitIfNeeded(); - _hasProcessedFrame = false; - } - - private static void RefreshFolderIcons(int instanceid, Rect selectionrect) - { - if (_hasProcessedFrame) { return; } - - _hasProcessedFrame = true; - - var windows = ((IEnumerable)meth_getAllSceneHierarchyWindows.Invoke(null, Array.Empty())).Cast().ToList(); - foreach (var window in windows) - { - object sceneHierarchy = prop_sceneHierarchy.GetValue(window); - object treeView = prop_treeView.GetValue(sceneHierarchy); - object data = prop_data.GetValue(treeView); - - var rows = (IList)meth_getRows.Invoke(data, Array.Empty()); - foreach (var item in rows) - { - var itemObject = (Object)prop_objectPPTR.GetValue(item); - if (!Folder.TryGetIconIndex(itemObject, out int colorIndex)) { continue; } - - bool isExpanded = (bool)meth_isExpanded.Invoke(data, new object[] { item }); - - var icons = ColoredFolderIcons(Mathf.Clamp(colorIndex, 0, _coloredFolderIcons.Length - 1)); - - item.icon = isExpanded ? icons.open : icons.closed; - - prop_selectedIcon.SetValue(item, isExpanded ? _openFolderSelectedTexture : _closedFolderSelectedTexture); - } - } - } - } -} -#endif \ No newline at end of file diff --git a/Editor/Icons/HierarchyFolderIcon.cs.meta b/Editor/Icons/HierarchyFolderIcon.cs.meta deleted file mode 100644 index 94a703e..0000000 --- a/Editor/Icons/HierarchyFolderIcon.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: d6f29c3d38f5ea94dbfbf44facaeaaca -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Editor/Icons/ReplaceColor Shader.shader b/Editor/Icons/ReplaceColor Shader.shader deleted file mode 100644 index a442a67..0000000 --- a/Editor/Icons/ReplaceColor Shader.shader +++ /dev/null @@ -1,21 +0,0 @@ -Shader "UI/Replace color" { - -Properties -{ - _Color ("Replace Color", Color) = (1,1,1) - _MainTex ("Texture", 2D) = "white" -} - -SubShader -{ - Pass - { - SetTexture [_MainTex] - { - ConstantColor [_Color] - combine constant + texture, texture - } - } -} - -} diff --git a/Editor/Icons/ReplaceColor Shader.shader.meta b/Editor/Icons/ReplaceColor Shader.shader.meta deleted file mode 100644 index 3852e47..0000000 --- a/Editor/Icons/ReplaceColor Shader.shader.meta +++ /dev/null @@ -1,10 +0,0 @@ -fileFormatVersion: 2 -guid: 7b9019de4b525b349a48678a64d7983a -ShaderImporter: - externalObjects: {} - defaultTextures: [] - nonModifiableTextures: [] - preprocessorOverride: 0 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Editor/Icons/TextureHelper.cs b/Editor/Icons/TextureHelper.cs deleted file mode 100644 index 5ca3ad7..0000000 --- a/Editor/Icons/TextureHelper.cs +++ /dev/null @@ -1,191 +0,0 @@ -// This software includes third-party software subject to the associated copyrights, as follows: -// -// Name: SolidUtilities -// Repo: https://github.com/SolidAlloy/SolidUtilities -// License: MIT (https://github.com/SolidAlloy/SolidUtilities/blob/master/LICENSE) -// Copyright (c) 2020 SolidAlloy - -namespace UnityHierarchyFolders.Editor -{ - using System; - using JetBrains.Annotations; - using UnityEngine; - - /// Helps to create new textures. - internal static class TextureHelper - { - private static readonly Color _fullyTransparent = new Color(1f, 1f, 1f, 0f); - - private static Material _tintMaterial; - private static Material _colorReplaceMaterial; - - public static Texture2D GetTintedTexture(Texture2D original, Color tint, string name) - { - return GetTextureWithMaterial(original, GetTintMaterial(tint), name); - } - - public static Texture2D GetWhiteTexture(Texture2D original, string name) - { - return GetTextureWithMaterial(original, GetColorReplaceMaterial(Color.white), name); - } - - private static Material GetTintMaterial(Color tint) - { - if (_tintMaterial == null) - _tintMaterial = new Material(Shader.Find("UI/Default")); - - _tintMaterial.color = tint; - return _tintMaterial; - } - - private static Material GetColorReplaceMaterial(Color color) - { - if (_colorReplaceMaterial == null) - _colorReplaceMaterial = new Material(Shader.Find("UI/Replace color")); - - _colorReplaceMaterial.color = color; - return _colorReplaceMaterial; - } - - private static Texture2D GetTextureWithMaterial(Texture2D original, Material material, string name) - { - Texture2D newTexture; - - using (new SRGBWriteScope(true)) - { - using (var temporary = new TemporaryActiveTexture(original.width, original.height, 0)) - { - GL.Clear(false, true, _fullyTransparent); - - Graphics.Blit(original, temporary, material); - - newTexture = new Texture2D(original.width, original.width, TextureFormat.ARGB32, false, true) - { - name = name, - filterMode = FilterMode.Bilinear, - hideFlags = HideFlags.DontSave - }; - - newTexture.ReadPixels(new Rect(0f, 0f, original.width, original.width), 0, 0); - newTexture.alphaIsTransparency = true; - newTexture.Apply(); - } - } - - return newTexture; - } - - /// - /// Temporarily sets to the passed value, then returns it back. - /// - [PublicAPI] - public readonly struct SRGBWriteScope : IDisposable - { - private readonly bool _previousValue; - - /// Temporarily sets to true, then executes the action. - /// Temporary value of . - /// - /// using (new SRGBWriteScope(true)) - /// { - /// GL.Clear(false, true, new Color(1f, 1f, 1f, 0f)); - /// Graphics.Blit(Default, temporary, material); - /// }); - /// - public SRGBWriteScope(bool enableWrite) - { - _previousValue = GL.sRGBWrite; - GL.sRGBWrite = enableWrite; - } - - public void Dispose() - { - GL.sRGBWrite = _previousValue; - } - } - - /// - /// Creates a temporary texture, sets it as active in , then removes the changes - /// and sets the previous active texture back automatically. - /// - /// - /// - /// using (var temporaryActiveTexture = new TemporaryActiveTexture(icon.width, icon.height, 0)) - /// { - /// Graphics.Blit(icon, temporary, material); - /// }); - /// - [PublicAPI] - public class TemporaryActiveTexture : IDisposable - { - private readonly RenderTexture _previousActiveTexture; - private readonly TemporaryRenderTexture _value; - - /// - /// Creates a temporary texture, sets it as active in , then removes it - /// and sets the previous active texture back automatically. - /// - /// Width of the temporary texture in pixels. - /// Height of the temporary texture in pixels. - /// Depth buffer of the temporary texture. - /// - /// - /// using (var temporaryActiveTexture = new TemporaryActiveTexture(icon.width, icon.height, 0)) - /// { - /// Graphics.Blit(icon, temporary, material); - /// }); - /// - public TemporaryActiveTexture(int width, int height, int depthBuffer) - { - _previousActiveTexture = RenderTexture.active; - _value = new TemporaryRenderTexture(width, height, depthBuffer); - RenderTexture.active = _value; - } - - public static implicit operator RenderTexture(TemporaryActiveTexture temporaryTexture) => temporaryTexture._value; - - public void Dispose() - { - _value.Dispose(); - RenderTexture.active = _previousActiveTexture; - } - } - - /// Creates a temporary texture that can be used and then removed automatically. - /// - /// - /// using (var temporaryTexture = new TemporaryRenderTexture(icon.width, icon.height, 0)) - /// { - /// Graphics.Blit(icon, temporaryTexture, material); - /// }); - /// - [PublicAPI] - public class TemporaryRenderTexture : IDisposable - { - private readonly RenderTexture _value; - - /// Creates a temporary texture that can be used and then removed automatically. - /// Width of the temporary texture in pixels. - /// Height of the temporary texture in pixels. - /// Depth buffer of the temporary texture. - /// - /// - /// using (var temporaryTexture = new TemporaryRenderTexture(icon.width, icon.height, 0)) - /// { - /// Graphics.Blit(icon, temporaryTexture, material); - /// }); - /// - public TemporaryRenderTexture(int width, int height, int depthBuffer) - { - _value = RenderTexture.GetTemporary(width, height, depthBuffer); - } - - public static implicit operator RenderTexture(TemporaryRenderTexture temporaryRenderTexture) => temporaryRenderTexture._value; - - public void Dispose() - { - RenderTexture.ReleaseTemporary(_value); - } - } - } -} \ No newline at end of file diff --git a/Editor/Icons/TextureHelper.cs.meta b/Editor/Icons/TextureHelper.cs.meta deleted file mode 100644 index 631a335..0000000 --- a/Editor/Icons/TextureHelper.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 1d329b59d6a342b995af79657ee830da -timeCreated: 1613913214 \ No newline at end of file From 0f7bd6e53db038bf7eb793401f4d34924b6a1616 Mon Sep 17 00:00:00 2001 From: SolidAlloy Date: Wed, 24 Feb 2021 12:39:15 +0200 Subject: [PATCH 2/3] Bumped the package version to 0.3.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 10a9ea5..2101733 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.xsduan.hierarchy-folders", "displayName": "Hierarchy Folders", - "version": "0.3.0", + "version": "0.3.1", "unity": "2018.1", "description": "Self-deleting Folder objects for the heirarchy.", "keywords": [ From 82a5f6f8ff69f56ccca16ba4979fcefaeaa097a6 Mon Sep 17 00:00:00 2001 From: SolidAlloy Date: Thu, 25 Feb 2021 11:44:37 +0200 Subject: [PATCH 3/3] Made the foldout label clickable in the folder inspector Fix of a small annoying detail --- Editor/FolderEditor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Editor/FolderEditor.cs b/Editor/FolderEditor.cs index 39b0c17..fa4e3f2 100644 --- a/Editor/FolderEditor.cs +++ b/Editor/FolderEditor.cs @@ -13,7 +13,7 @@ public class FolderEditor : UnityEditor.Editor public override bool RequiresConstantRepaint() => true; public override void OnInspectorGUI() { - this._expanded = EditorGUILayout.Foldout(this._expanded, "Icon Color"); + this._expanded = EditorGUILayout.Foldout(this._expanded, "Icon Color", true); if (this._expanded) { this.RenderColorPicker(); } }