destroyed proj
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Borodar.RainbowHierarchy
|
||||
{
|
||||
public abstract class CoreDraggablePopupWindow : EditorWindow
|
||||
{
|
||||
private Vector2 _offset;
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Static
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// Returns the first DraggablePopupWindow of type T which is currently on the screen.
|
||||
/// If there is none, creates and shows new window and returns the instance of it.
|
||||
/// </summary>
|
||||
[SuppressMessage("ReSharper", "PossibleNullReferenceException")]
|
||||
protected static T GetDraggableWindow<T>() where T : CoreDraggablePopupWindow
|
||||
{
|
||||
var array = Resources.FindObjectsOfTypeAll(typeof(T)) as T[];
|
||||
var t = (array.Length <= 0) ? null : array[0];
|
||||
|
||||
return t ? t : CreateInstance<T>();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Messages
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// Callback for drawing GUI controls for the popup window.
|
||||
/// </summary>
|
||||
[SuppressMessage("ReSharper", "InvertIf")]
|
||||
protected virtual void OnGUI()
|
||||
{
|
||||
var e = Event.current;
|
||||
|
||||
// Close the window if ESC is pressed
|
||||
if (e.type == EventType.KeyUp && e.keyCode == KeyCode.Escape) Close();
|
||||
|
||||
// calculate offset for the mouse cursor when start dragging
|
||||
if (e.button == 0 && e.type == EventType.MouseDown)
|
||||
{
|
||||
_offset = position.position - GUIUtility.GUIToScreenPoint(e.mousePosition);
|
||||
}
|
||||
|
||||
// drag window
|
||||
if (e.button == 0 && e.type == EventType.MouseDrag && IsDragModifierPressed(e))
|
||||
{
|
||||
var mousePos = GUIUtility.GUIToScreenPoint(e.mousePosition);
|
||||
position = new Rect(mousePos + _offset, position.size);
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Protected
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// Show draggable editor window with popup-style framing.
|
||||
/// </summary>
|
||||
protected void Show<T>(Rect inPosition, bool focus = true) where T : CoreDraggablePopupWindow
|
||||
{
|
||||
minSize = inPosition.size;
|
||||
position = inPosition;
|
||||
|
||||
ShowPopup();
|
||||
if (focus) Focus();
|
||||
}
|
||||
|
||||
protected abstract bool IsDragModifierPressed(Event e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa4a4fb896b20d149b676e21370adc8b
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 106670
|
||||
packageName: Rainbow Hierarchy 2
|
||||
packageVersion: 2.6.2
|
||||
assetPath: Assets/Plugins/Borodar/RainbowHierarchy/Scripts/Editor/Windows/CoreDraggablePopupWindow.cs
|
||||
uploadId: 716077
|
||||
@@ -0,0 +1,150 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Borodar.RainbowHierarchy
|
||||
{
|
||||
public class HierarchyBackgroundsPopup : HierarchySelectionPopup<HierarchyBackground>
|
||||
{
|
||||
private static readonly Vector2 WINDOW_SIZE = new Vector2(390f, 214f);
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Properties
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
protected override Vector2 WindowSize => WINDOW_SIZE;
|
||||
protected override int GridColumns => 4;
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Public
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
public static HierarchyBackgroundsPopup GetDraggableWindow()
|
||||
{
|
||||
return GetDraggableWindow<HierarchyBackgroundsPopup>();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Protected
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
protected override void DrawButtons(Rect rect)
|
||||
{
|
||||
DrawCategoryButton(rect, "All");
|
||||
|
||||
rect.y += LINE_HEIGHT * 9f + SPACING * 6f;
|
||||
DrawCustomButton(rect);
|
||||
rect.y += LINE_HEIGHT + SPACING;
|
||||
DrawNoneButton(rect);
|
||||
}
|
||||
|
||||
protected override void DrawIcons(Rect rect)
|
||||
{
|
||||
GUILayout.BeginArea(rect);
|
||||
ScrollPos = BeginScrollView(ScrollPos);
|
||||
|
||||
var predicate = GetCategoryPredicate();
|
||||
var icons = Enum.GetValues(typeof(HierarchyBackground))
|
||||
.Cast<HierarchyBackground>()
|
||||
.Where(predicate)
|
||||
.ToList();
|
||||
|
||||
GUILayout.BeginVertical();
|
||||
DrawIconsGrid(icons);
|
||||
GUILayout.EndVertical();
|
||||
|
||||
EditorGUILayout.EndScrollView();
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
|
||||
protected override void DrawIconButton(HierarchyBackground backgroundType)
|
||||
{
|
||||
var rect = EditorGUILayout.GetControlRect(GUILayout.Width(66), GUILayout.Height(22));
|
||||
if (GUI.Button(rect, GUIContent.none, "grey_border"))
|
||||
{
|
||||
AssignBackgroundByType(HierarchyRule, backgroundType);
|
||||
}
|
||||
|
||||
var backgroundTex = HierarchyBackgroundsStorage.GetBackground(backgroundType);
|
||||
DrawPreview(rect, backgroundTex);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Helpers
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
private void DrawCategoryButton(Rect rect, string text)
|
||||
{
|
||||
if (!GUI.Button(rect, text, "MiniToolbarButtonLeft")) return;
|
||||
ApplyIconsCategory();
|
||||
}
|
||||
|
||||
private void DrawCustomButton(Rect rect)
|
||||
{
|
||||
if (!GUI.Button(rect, "Custom", "minibutton")) return;
|
||||
AssignBackgroundByType(HierarchyRule, HierarchyBackground.Custom);
|
||||
}
|
||||
|
||||
private void DrawNoneButton(Rect rect)
|
||||
{
|
||||
if (!GUI.Button(rect, "None", "minibutton")) return;
|
||||
ResetBackgroundToDefault(HierarchyRule);
|
||||
}
|
||||
|
||||
private static Func<HierarchyBackground, bool> GetCategoryPredicate()
|
||||
{
|
||||
return icon => (int) icon >= 1000 && (int) icon < 50000;
|
||||
}
|
||||
|
||||
private static void DrawPreview(Rect rect, Texture icon)
|
||||
{
|
||||
rect.x += 1f;
|
||||
rect.y += 1f;
|
||||
rect.width = PREVIEW_SIZE_LARGE;
|
||||
rect.height = PREVIEW_SIZE_SMALL + 4f;
|
||||
|
||||
GUI.Label(rect, "Folder", "CenteredLabel");
|
||||
GUI.DrawTexture(rect, icon);
|
||||
}
|
||||
|
||||
private void ApplyIconsCategory()
|
||||
{
|
||||
ScrollPos = Vector2.zero;
|
||||
}
|
||||
|
||||
private void AssignBackgroundByType(dynamic rule, HierarchyBackground type)
|
||||
{
|
||||
if (IsRuleSerialized)
|
||||
{
|
||||
rule.FindPropertyRelative("BackgroundType").intValue = (int) type;
|
||||
rule.FindPropertyRelative("BackgroundTexture").objectReferenceValue = null;
|
||||
ApplyPropertyChangesAndClose(rule);
|
||||
}
|
||||
else
|
||||
{
|
||||
rule.BackgroundType = type;
|
||||
rule.BackgroundTexture = null;
|
||||
CloseAndRepaintParent();
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetBackgroundToDefault(dynamic rule)
|
||||
{
|
||||
if (IsRuleSerialized)
|
||||
{
|
||||
rule.FindPropertyRelative("BackgroundType").intValue = (int) HierarchyBackground.None;
|
||||
rule.FindPropertyRelative("BackgroundTexture").objectReferenceValue = null;
|
||||
rule.FindPropertyRelative("IsBackgroundRecursive").boolValue = false;
|
||||
ApplyPropertyChangesAndClose(rule);
|
||||
}
|
||||
else
|
||||
{
|
||||
rule.BackgroundType = HierarchyBackground.None;
|
||||
rule.BackgroundTexture = null;
|
||||
rule.IsBackgroundRecursive = false;
|
||||
CloseAndRepaintParent();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ddb7dcc055c8d2b4295bdbd5843af4d6
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 106670
|
||||
packageName: Rainbow Hierarchy 2
|
||||
packageVersion: 2.6.2
|
||||
assetPath: Assets/Plugins/Borodar/RainbowHierarchy/Scripts/Editor/Windows/HierarchyBackgroundsPopup.cs
|
||||
uploadId: 716077
|
||||
@@ -0,0 +1,250 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Borodar.RainbowHierarchy
|
||||
{
|
||||
public class HierarchyIconsPopup : HierarchySelectionPopup<HierarchyIcon>
|
||||
{
|
||||
private static readonly Vector2 WINDOW_SIZE = new Vector2(325f, 214f);
|
||||
|
||||
private HierarchyIconCategory _category;
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Properties
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
protected override Vector2 WindowSize => WINDOW_SIZE;
|
||||
protected override int GridColumns => 6;
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Public
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
public static HierarchyIconsPopup GetDraggableWindow()
|
||||
{
|
||||
return GetDraggableWindow<HierarchyIconsPopup>();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Protected
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
protected override void DrawButtons(Rect rect)
|
||||
{
|
||||
rect.height = WindowSize.y - 60f;
|
||||
GUILayout.BeginArea(rect);
|
||||
ScrollPos2 = BeginScrollView(ScrollPos2);
|
||||
|
||||
GUILayout.BeginVertical();
|
||||
DrawCategoryButton("All", HierarchyIconCategory.All);
|
||||
DrawCategoryButton("Colors", HierarchyIconCategory.Colors);
|
||||
DrawCategoryButton("General", HierarchyIconCategory.General);
|
||||
DrawCategoryButton("Animation", HierarchyIconCategory.Animation);
|
||||
DrawCategoryButton("AR", HierarchyIconCategory.AR);
|
||||
DrawCategoryButton("Assets", HierarchyIconCategory.Assets);
|
||||
DrawCategoryButton("Audio", HierarchyIconCategory.Audio);
|
||||
DrawCategoryButton("Collab", HierarchyIconCategory.Collab);
|
||||
DrawCategoryButton("Console", HierarchyIconCategory.Console);
|
||||
DrawCategoryButton("Effects", HierarchyIconCategory.Effects);
|
||||
DrawCategoryButton("Events", HierarchyIconCategory.Events);
|
||||
DrawCategoryButton("Folders", HierarchyIconCategory.Folders);
|
||||
DrawCategoryButton("Layouts", HierarchyIconCategory.Layouts);
|
||||
DrawCategoryButton("Light", HierarchyIconCategory.Light);
|
||||
DrawCategoryButton("Meshes", HierarchyIconCategory.Meshes);
|
||||
DrawCategoryButton("Misc", HierarchyIconCategory.Miscellaneous);
|
||||
DrawCategoryButton("Navigation", HierarchyIconCategory.Navigation);
|
||||
DrawCategoryButton("Network", HierarchyIconCategory.Network);
|
||||
DrawCategoryButton("Physics2D", HierarchyIconCategory.Physics2D);
|
||||
DrawCategoryButton("Physics", HierarchyIconCategory.Physics);
|
||||
DrawCategoryButton("Playables", HierarchyIconCategory.Playables);
|
||||
DrawCategoryButton("Rendering", HierarchyIconCategory.Rendering);
|
||||
DrawCategoryButton("Tilemap", HierarchyIconCategory.Tilemap);
|
||||
DrawCategoryButton("UI", HierarchyIconCategory.UI);
|
||||
DrawCategoryButton("Video", HierarchyIconCategory.Video);
|
||||
GUILayout.EndVertical();
|
||||
|
||||
EditorGUILayout.EndScrollView();
|
||||
GUILayout.EndArea();
|
||||
|
||||
rect.y = WindowSize.y - LINE_HEIGHT * 2f - 5f;
|
||||
rect.height = LINE_HEIGHT;
|
||||
DrawCustomButton(rect);
|
||||
rect.y += LINE_HEIGHT + SPACING;
|
||||
DrawNoneButton(rect);
|
||||
}
|
||||
|
||||
protected override void DrawIcons(Rect rect)
|
||||
{
|
||||
GUILayout.BeginArea(rect);
|
||||
ScrollPos = BeginScrollView(ScrollPos);
|
||||
|
||||
var predicate = GetCategoryPredicate(_category);
|
||||
var icons = Enum.GetValues(typeof(HierarchyIcon))
|
||||
.Cast<HierarchyIcon>()
|
||||
.Where(predicate)
|
||||
.ToList();
|
||||
|
||||
GUILayout.BeginVertical();
|
||||
DrawIconsGrid(icons);
|
||||
GUILayout.EndVertical();
|
||||
|
||||
EditorGUILayout.EndScrollView();
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
|
||||
protected override void DrawIconButton(HierarchyIcon iconType)
|
||||
{
|
||||
var rect = EditorGUILayout.GetControlRect(
|
||||
GUILayout.Width(PREVIEW_SIZE_SMALL + PADDING * 4f),
|
||||
GUILayout.Height(PREVIEW_SIZE_SMALL + PADDING * 4f));
|
||||
|
||||
if (GUI.Button(rect, GUIContent.none, "grey_border"))
|
||||
{
|
||||
AssignIconByType(HierarchyRule, iconType);
|
||||
}
|
||||
|
||||
var iconTex = HierarchyIconsStorage.GetIcon(iconType);
|
||||
DrawPreview(rect, iconTex);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Helpers
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
private void DrawCategoryButton(string text, HierarchyIconCategory category)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
var isButtonPressed = GUILayout.Button(text, "MiniToolbarButtonLeft");
|
||||
GUILayout.Space(2f);
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.Space(2f);
|
||||
|
||||
if (!isButtonPressed) return;
|
||||
ApplyIconsCategory(category);
|
||||
}
|
||||
|
||||
|
||||
private void DrawNoneButton(Rect rect)
|
||||
{
|
||||
if (!GUI.Button(rect, "None", "minibutton")) return;
|
||||
|
||||
ResetIconToDefault(HierarchyRule);
|
||||
}
|
||||
|
||||
private void DrawCustomButton(Rect rect)
|
||||
{
|
||||
if (!GUI.Button(rect, "Custom", "minibutton")) return;
|
||||
AssignIconByType(HierarchyRule, HierarchyIcon.Custom);
|
||||
}
|
||||
|
||||
private static Func<HierarchyIcon, bool> GetCategoryPredicate(HierarchyIconCategory category)
|
||||
{
|
||||
switch (category)
|
||||
{
|
||||
case HierarchyIconCategory.All:
|
||||
return icon => icon != HierarchyIcon.None && icon != HierarchyIcon.Custom;
|
||||
case HierarchyIconCategory.Colors:
|
||||
return icon => (int) icon >= 1000 && (int) icon < 50000;
|
||||
case HierarchyIconCategory.General:
|
||||
return icon => (int) icon >= 100000 && (int) icon < 117000;
|
||||
case HierarchyIconCategory.Animation:
|
||||
return icon => (int) icon >= 117000 && (int) icon < 120000;
|
||||
case HierarchyIconCategory.AR:
|
||||
return icon => (int) icon >= 120000 && (int) icon < 125000;
|
||||
case HierarchyIconCategory.Assets:
|
||||
return icon => (int) icon >= 125000 && (int) icon < 130000;
|
||||
case HierarchyIconCategory.Audio:
|
||||
return icon => (int) icon >= 130000 && (int) icon < 138500;
|
||||
case HierarchyIconCategory.Collab:
|
||||
return icon => (int) icon >= 138500 && (int) icon < 139100;
|
||||
case HierarchyIconCategory.Console:
|
||||
return icon => (int) icon >= 139100 && (int) icon < 139500;
|
||||
case HierarchyIconCategory.Effects:
|
||||
return icon => (int) icon >= 139500 && (int) icon < 150000;
|
||||
case HierarchyIconCategory.Events:
|
||||
return icon => (int) icon >= 150000 && (int) icon < 158000;
|
||||
case HierarchyIconCategory.Folders:
|
||||
return icon => (int) icon >= 158000 && (int) icon < 160000;
|
||||
case HierarchyIconCategory.Layouts:
|
||||
return icon => (int) icon >= 160000 && (int) icon < 169500;
|
||||
case HierarchyIconCategory.Light:
|
||||
return icon => (int) icon >= 169500 && (int) icon < 170000;
|
||||
case HierarchyIconCategory.Meshes:
|
||||
return icon => (int) icon >= 170000 && (int) icon < 180000;
|
||||
case HierarchyIconCategory.Miscellaneous:
|
||||
return icon => (int) icon >= 180000 && (int) icon < 200000;
|
||||
case HierarchyIconCategory.Navigation:
|
||||
return icon => (int) icon >= 200000 && (int) icon < 210000;
|
||||
case HierarchyIconCategory.Network:
|
||||
return icon => (int) icon >= 210000 && (int) icon < 230000;
|
||||
case HierarchyIconCategory.Physics2D:
|
||||
return icon => (int) icon >= 230000 && (int) icon < 260000;
|
||||
case HierarchyIconCategory.Physics:
|
||||
return icon => (int) icon >= 260000 && (int) icon < 280000;
|
||||
case HierarchyIconCategory.Playables:
|
||||
return icon => (int) icon >= 280000 && (int) icon < 290000;
|
||||
case HierarchyIconCategory.Rendering:
|
||||
return icon => (int) icon >= 290000 && (int) icon < 310000;
|
||||
case HierarchyIconCategory.Tilemap:
|
||||
return icon => (int) icon >= 310000 && (int) icon < 320000;
|
||||
case HierarchyIconCategory.UI:
|
||||
return icon => (int) icon >= 320000 && (int) icon < 340000;
|
||||
case HierarchyIconCategory.Video:
|
||||
return icon => (int) icon >= 340000 && (int) icon < 350000;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
private static void DrawPreview(Rect rect, Texture icon)
|
||||
{
|
||||
rect.x += PADDING * 2f;
|
||||
rect.y += PADDING * 2f;
|
||||
rect.width = rect.height = PREVIEW_SIZE_SMALL;
|
||||
|
||||
GUI.DrawTexture(rect, icon);
|
||||
}
|
||||
|
||||
private void ApplyIconsCategory(HierarchyIconCategory category)
|
||||
{
|
||||
_category = category;
|
||||
ScrollPos = Vector2.zero;
|
||||
}
|
||||
|
||||
private void AssignIconByType(dynamic rule, HierarchyIcon type)
|
||||
{
|
||||
if (IsRuleSerialized)
|
||||
{
|
||||
rule.FindPropertyRelative("IconType").intValue = (int) type;
|
||||
rule.FindPropertyRelative("IconTexture").objectReferenceValue = null;
|
||||
ApplyPropertyChangesAndClose(rule);
|
||||
}
|
||||
else
|
||||
{
|
||||
rule.IconType = type;
|
||||
rule.IconTexture = null;
|
||||
CloseAndRepaintParent();
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetIconToDefault(dynamic rule)
|
||||
{
|
||||
if (IsRuleSerialized)
|
||||
{
|
||||
rule.FindPropertyRelative("IconType").intValue = (int) HierarchyIcon.None;
|
||||
rule.FindPropertyRelative("IconTexture").objectReferenceValue = null;
|
||||
rule.FindPropertyRelative("IsIconRecursive").boolValue = false;
|
||||
ApplyPropertyChangesAndClose(rule);
|
||||
}
|
||||
else
|
||||
{
|
||||
rule.IconType = HierarchyIcon.None;
|
||||
rule.IconTexture = null;
|
||||
rule.IsIconRecursive = false;
|
||||
CloseAndRepaintParent();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e76b1a25e9c44ea47b8d5197d04bdbdb
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 106670
|
||||
packageName: Rainbow Hierarchy 2
|
||||
packageVersion: 2.6.2
|
||||
assetPath: Assets/Plugins/Borodar/RainbowHierarchy/Scripts/Editor/Windows/HierarchyIconsPopup.cs
|
||||
uploadId: 716077
|
||||
@@ -0,0 +1,377 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using static Borodar.RainbowHierarchy.ColorHelper;
|
||||
using KeyType = Borodar.RainbowHierarchy.HierarchyRule.KeyType;
|
||||
|
||||
namespace Borodar.RainbowHierarchy
|
||||
{
|
||||
public class HierarchyPopupWindow : CoreDraggablePopupWindow
|
||||
{
|
||||
private const float PADDING = 8f;
|
||||
private const float SPACING = 2f;
|
||||
private const float LINE_HEIGHT = 18f;
|
||||
private const float LABELS_WIDTH = 80f;
|
||||
private const float BUTTON_WIDTH = 55f;
|
||||
private const float ICON_WIDTH_SMALL = 16f;
|
||||
|
||||
private const float WINDOW_WIDTH = 300f;
|
||||
private const float WINDOW_HEIGHT = 176f;
|
||||
|
||||
private static readonly Vector2 WINDOW_SIZE = new(WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||
|
||||
private Rect _windowRect;
|
||||
private Rect _backgroundRect;
|
||||
|
||||
private List<GameObject> _selectedObjects;
|
||||
private GameObject _currentObject;
|
||||
private HierarchyRulesetV2 _ruleset;
|
||||
private HierarchyRule _currentRule;
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Public
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
public static HierarchyPopupWindow GetDraggableWindow()
|
||||
{
|
||||
return GetDraggableWindow<HierarchyPopupWindow>();
|
||||
}
|
||||
|
||||
public void ShowWithParams(Vector2 inPosition, List<GameObject> selectedObjects, int firstSelected)
|
||||
{
|
||||
_selectedObjects = selectedObjects;
|
||||
|
||||
var scene = selectedObjects[0].scene;
|
||||
_ruleset = HierarchyRulesetV2.GetRulesetByScene(scene, true);
|
||||
|
||||
_currentObject = selectedObjects[firstSelected];
|
||||
|
||||
var rule = _ruleset.GetRule(_currentObject);
|
||||
|
||||
_currentRule = rule == null ?
|
||||
new HierarchyRule(KeyType.Object, _currentObject, _currentObject.name) :
|
||||
new HierarchyRule(rule);
|
||||
|
||||
_currentRule.GameObject = _currentObject;
|
||||
|
||||
// Resize
|
||||
|
||||
var customIconHeight = (_currentRule.HasCustomIcon()) ? LINE_HEIGHT : 0f;
|
||||
var customBackgroundHeight = (_currentRule.HasCustomBackground()) ? LINE_HEIGHT : 0f;
|
||||
|
||||
var rect = new Rect(inPosition, WINDOW_SIZE)
|
||||
{
|
||||
height = WINDOW_HEIGHT + customIconHeight + customBackgroundHeight
|
||||
};
|
||||
|
||||
_windowRect = new Rect(Vector2.zero, rect.size);
|
||||
_backgroundRect = new Rect(Vector2.one, rect.size - new Vector2(2f, 2f));
|
||||
|
||||
Show<HierarchyPopupWindow>(rect);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Messages
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
protected override void OnGUI()
|
||||
{
|
||||
if (_currentRule == null) { Close(); return; }
|
||||
|
||||
base.OnGUI();
|
||||
|
||||
ChangeWindowSize(_currentRule.HasCustomIcon(), _currentRule.HasCustomBackground());
|
||||
var rect = _windowRect;
|
||||
|
||||
// Window Background
|
||||
|
||||
var borderColor = EditorGUIUtility.isProSkin ? POPUP_BORDER_CLR_PRO : POPUP_BORDER_CLR_FREE;
|
||||
EditorGUI.DrawRect(_windowRect, borderColor);
|
||||
|
||||
var backgroundColor = EditorGUIUtility.isProSkin ? POPUP_BACKGROUND_CLR_PRO : POPUP_BACKGROUND_CLR_FREE;
|
||||
EditorGUI.DrawRect(_backgroundRect, backgroundColor);
|
||||
|
||||
// Body
|
||||
|
||||
DrawTypeAndKey(ref rect);
|
||||
DrawPriority(ref rect);
|
||||
DrawIcon(ref rect);
|
||||
DrawBackground(ref rect);
|
||||
DrawButtons(ref rect);
|
||||
DrawSeparators(ref rect);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Protected
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
protected override bool IsDragModifierPressed(Event e)
|
||||
{
|
||||
return HierarchyPreferences.IsDragModifierPressed(e);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Helpers
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
private void DrawTypeAndKey(ref Rect rect)
|
||||
{
|
||||
rect.x += 0.5f * PADDING;
|
||||
rect.y += PADDING;
|
||||
rect.width = LABELS_WIDTH - PADDING;
|
||||
rect.height = LINE_HEIGHT;
|
||||
|
||||
_currentRule.Type = (KeyType) EditorGUI.EnumPopup(rect, _currentRule.Type);
|
||||
|
||||
rect.x += LABELS_WIDTH;
|
||||
rect.y = _windowRect.y + PADDING;
|
||||
rect.width = _windowRect.width - LABELS_WIDTH - PADDING;
|
||||
|
||||
GUI.enabled = false;
|
||||
if (_selectedObjects.Count == 1)
|
||||
if (_currentRule.Type == KeyType.Object)
|
||||
{
|
||||
EditorGUI.ObjectField(rect, _currentObject, typeof(GameObject), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUI.TextField(rect, _currentObject.name);
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUI.TextField(rect, GUIContent.none, _selectedObjects.Count + " selected");
|
||||
}
|
||||
GUI.enabled = true;
|
||||
}
|
||||
|
||||
private void DrawPriority(ref Rect rect)
|
||||
{
|
||||
rect.x = 0.5f * PADDING;
|
||||
rect.y += LINE_HEIGHT + 3f;
|
||||
EditorGUI.LabelField(rect, "Priority");
|
||||
|
||||
rect.width = _windowRect.width - LABELS_WIDTH - PADDING;
|
||||
rect.x += LABELS_WIDTH;
|
||||
_currentRule.Priority = EditorGUI.IntField(rect, GUIContent.none, _currentRule.Priority);
|
||||
}
|
||||
|
||||
private void DrawIcon(ref Rect rect)
|
||||
{
|
||||
rect.x = 0.5f * PADDING;
|
||||
rect.y += LINE_HEIGHT + 1.5f * PADDING + 1f;
|
||||
EditorGUI.LabelField(rect, "Icon");
|
||||
|
||||
rect.y += LINE_HEIGHT + SPACING;
|
||||
rect.width = ICON_WIDTH_SMALL;
|
||||
rect.height = ICON_WIDTH_SMALL;
|
||||
if (_currentRule.HasIcon())
|
||||
{
|
||||
var texture = (_currentRule.HasCustomIcon())
|
||||
? _currentRule.IconTexture
|
||||
: HierarchyIconsStorage.GetIcon(_currentRule.IconType);
|
||||
|
||||
GUI.DrawTexture(rect, texture);
|
||||
}
|
||||
|
||||
rect.x += LABELS_WIDTH;
|
||||
rect.y -= LINE_HEIGHT + 1.5f * SPACING;
|
||||
rect.width = _windowRect.width - LABELS_WIDTH - PADDING;
|
||||
rect.height = LINE_HEIGHT;
|
||||
DrawIconsPopup(rect, _currentRule);
|
||||
|
||||
// Custom Icon Field
|
||||
if (_currentRule.HasCustomIcon())
|
||||
{
|
||||
rect.y += LINE_HEIGHT + 2f * SPACING;
|
||||
_currentRule.IconTexture = (Texture2D) EditorGUI.ObjectField(rect, _currentRule.IconTexture, typeof(Texture2D), false);
|
||||
}
|
||||
|
||||
rect.y += _currentRule.HasCustomIcon() ? LINE_HEIGHT + 0.2f * SPACING : LINE_HEIGHT + SPACING;
|
||||
_currentRule.IsIconRecursive = EditorGUI.Toggle(rect, _currentRule.IsIconRecursive);
|
||||
|
||||
rect.x += ICON_WIDTH_SMALL;
|
||||
EditorGUI.LabelField(rect, "Recursive");
|
||||
}
|
||||
|
||||
private void DrawBackground(ref Rect rect)
|
||||
{
|
||||
rect.x = 0.5f * PADDING;
|
||||
rect.y += LINE_HEIGHT + SPACING * 3;
|
||||
EditorGUI.LabelField(rect, "Background");
|
||||
|
||||
rect.y += LINE_HEIGHT + SPACING;
|
||||
rect.width = ICON_WIDTH_SMALL * 3f;
|
||||
rect.height = ICON_WIDTH_SMALL;
|
||||
if (_currentRule.HasBackground())
|
||||
{
|
||||
var texture = (_currentRule.HasCustomBackground())
|
||||
? _currentRule.BackgroundTexture
|
||||
: HierarchyBackgroundsStorage.GetBackground(_currentRule.BackgroundType);
|
||||
|
||||
GUI.DrawTexture(rect, texture);
|
||||
}
|
||||
|
||||
rect.x += LABELS_WIDTH;
|
||||
rect.y -= LINE_HEIGHT + 1.5f * SPACING;
|
||||
rect.width = _windowRect.width - LABELS_WIDTH - PADDING;
|
||||
rect.height = LINE_HEIGHT;
|
||||
DrawBackgroundsPopup(rect, _currentRule);
|
||||
|
||||
// Custom Icon Field
|
||||
if (_currentRule.HasCustomBackground())
|
||||
{
|
||||
rect.y += LINE_HEIGHT + 2f * SPACING;
|
||||
_currentRule.BackgroundTexture =
|
||||
(Texture2D) EditorGUI.ObjectField(rect, _currentRule.BackgroundTexture, typeof(Texture2D), false);
|
||||
}
|
||||
|
||||
rect.y += _currentRule.HasCustomBackground() ? LINE_HEIGHT + 0.2f * SPACING : LINE_HEIGHT + SPACING;
|
||||
_currentRule.IsBackgroundRecursive = EditorGUI.Toggle(rect, _currentRule.IsBackgroundRecursive);
|
||||
|
||||
rect.x += ICON_WIDTH_SMALL;
|
||||
EditorGUI.LabelField(rect, "Recursive");
|
||||
}
|
||||
|
||||
private void DrawButtons(ref Rect rect)
|
||||
{
|
||||
rect.x = PADDING;
|
||||
rect.y = position.height - LINE_HEIGHT - 0.75f * PADDING;
|
||||
rect.width = ICON_WIDTH_SMALL;
|
||||
ButtonSettings(rect);
|
||||
|
||||
rect.x += ICON_WIDTH_SMALL + 0.75f * PADDING;
|
||||
ButtonFilter(rect);
|
||||
|
||||
rect.x += ICON_WIDTH_SMALL + 0.75f * PADDING;
|
||||
ButtonDefault(rect);
|
||||
|
||||
rect.x = WINDOW_WIDTH - 2f * (BUTTON_WIDTH + PADDING);
|
||||
rect.width = BUTTON_WIDTH;
|
||||
ButtonCancel(rect);
|
||||
|
||||
rect.x = WINDOW_WIDTH - BUTTON_WIDTH - PADDING;
|
||||
ButtonApply(rect);
|
||||
}
|
||||
|
||||
private void DrawSeparators(ref Rect rect)
|
||||
{
|
||||
var color1 = (EditorGUIUtility.isProSkin) ? SEPARATOR_CLR_1_PRO : SEPARATOR_CLR_1_FREE;
|
||||
var color2 = (EditorGUIUtility.isProSkin) ? SEPARATOR_CLR_2_PRO : SEPARATOR_CLR_2_FREE;
|
||||
|
||||
// First separator
|
||||
rect.x = 0.5f * PADDING;
|
||||
rect.y = 2f * LINE_HEIGHT + 16f;
|
||||
rect.width = WINDOW_WIDTH - PADDING;
|
||||
rect.height = 1f;
|
||||
EditorGUI.DrawRect(rect, color1);
|
||||
rect.y += 1;
|
||||
EditorGUI.DrawRect(rect, color2);
|
||||
|
||||
// Second separator
|
||||
rect.y = position.height - LINE_HEIGHT - 11f;
|
||||
EditorGUI.DrawRect(rect, color1);
|
||||
rect.y += 1;
|
||||
EditorGUI.DrawRect(rect, color2);
|
||||
}
|
||||
|
||||
private void ButtonSettings(Rect rect)
|
||||
{
|
||||
var icon = HierarchyEditorUtility.GetSettingsButtonIcon();
|
||||
if (!GUI.Button(rect, new GUIContent(icon, "All Rules"), GUIStyle.none)) return;
|
||||
Selection.activeObject = _ruleset;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void ButtonFilter(Rect rect)
|
||||
{
|
||||
var icon = HierarchyEditorUtility.GetFilterButtonIcon();
|
||||
if (!GUI.Button(rect, new GUIContent(icon, "Object Rules"), GUIStyle.none)) return;
|
||||
|
||||
HierarchyRulesetEditorV2.ShowInspector(_ruleset, _currentObject);
|
||||
Close();
|
||||
}
|
||||
|
||||
private void ButtonDefault(Rect rect)
|
||||
{
|
||||
var icon = HierarchyEditorUtility.GetDeleteButtonIcon();
|
||||
if (!GUI.Button(rect, new GUIContent(icon, "Revert to Default"), GUIStyle.none)) return;
|
||||
|
||||
_currentRule.Priority = 0;
|
||||
|
||||
_currentRule.IconType = HierarchyIcon.None;
|
||||
_currentRule.IconTexture = null;
|
||||
_currentRule.IsIconRecursive = false;
|
||||
|
||||
_currentRule.BackgroundType = HierarchyBackground.None;
|
||||
_currentRule.BackgroundTexture = null;
|
||||
_currentRule.IsBackgroundRecursive = false;
|
||||
}
|
||||
|
||||
private void ButtonCancel(Rect rect)
|
||||
{
|
||||
if (!GUI.Button(rect, "Cancel")) return;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void ButtonApply(Rect rect)
|
||||
{
|
||||
if (!GUI.Button(rect, "Apply")) return;
|
||||
|
||||
var currentScene = _currentObject.scene;
|
||||
var ruleset = HierarchyRulesetV2.GetRulesetByScene(currentScene, true);
|
||||
|
||||
foreach (var selectedObject in _selectedObjects)
|
||||
{
|
||||
// objects can be selected across multiple scenes
|
||||
if (currentScene != selectedObject.scene)
|
||||
{
|
||||
currentScene = selectedObject.scene;
|
||||
ruleset = HierarchyRulesetV2.GetRulesetByScene(currentScene, true);
|
||||
}
|
||||
|
||||
_currentRule.GameObject = _currentRule.Type == KeyType.Name ? null : selectedObject;
|
||||
_currentRule.Name = _currentRule.Type == KeyType.Name ? selectedObject.name : null;
|
||||
|
||||
Undo.RecordObject(ruleset, "Rainbow Hierarchy Ruleset Changes");
|
||||
ruleset.UpdateRule(selectedObject, _currentRule);
|
||||
}
|
||||
|
||||
Close();
|
||||
}
|
||||
|
||||
private void ChangeWindowSize(bool hasCustomIcon, bool hasCustomBackground)
|
||||
{
|
||||
var rect = position;
|
||||
var customIconHeight = (hasCustomIcon) ? LINE_HEIGHT + 1f : 0f;
|
||||
var customBackgroundHeight = (hasCustomBackground) ? LINE_HEIGHT + 1f : 0f;
|
||||
|
||||
var resizeHeight = WINDOW_HEIGHT + customIconHeight + customBackgroundHeight;
|
||||
if (resizeHeight == rect.height) return;
|
||||
|
||||
rect.height = resizeHeight;
|
||||
position = rect;
|
||||
|
||||
_windowRect.height = rect.height;
|
||||
_backgroundRect.height = rect.height - 2f;
|
||||
}
|
||||
|
||||
private void DrawIconsPopup(Rect rect, HierarchyRule rule)
|
||||
{
|
||||
var menuName = (_currentRule.HasCustomIcon()) ? "Custom" : _currentRule.IconType.ToString();
|
||||
if (!GUI.Button(rect, new GUIContent(menuName), "MiniPopup")) return;
|
||||
|
||||
var window = HierarchyIconsPopup.GetDraggableWindow();
|
||||
window.ShowWithParams(position.position + rect.position, rule, this);
|
||||
}
|
||||
|
||||
private void DrawBackgroundsPopup(Rect rect, HierarchyRule rule)
|
||||
{
|
||||
var menuName = _currentRule.HasCustomBackground() ? "Custom" : _currentRule.BackgroundType.ToString();
|
||||
if (!GUI.Button(rect, new GUIContent(menuName), "MiniPopup")) return;
|
||||
|
||||
var window = HierarchyBackgroundsPopup.GetDraggableWindow();
|
||||
window.ShowWithParams(position.position + rect.position, rule, this);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 45b1cbaf79679e04ab0123ee46b27e60
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 106670
|
||||
packageName: Rainbow Hierarchy 2
|
||||
packageVersion: 2.6.2
|
||||
assetPath: Assets/Plugins/Borodar/RainbowHierarchy/Scripts/Editor/Windows/HierarchyPopupWindow.cs
|
||||
uploadId: 716077
|
||||
@@ -0,0 +1,172 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using static Borodar.RainbowHierarchy.ColorHelper;
|
||||
|
||||
namespace Borodar.RainbowHierarchy
|
||||
{
|
||||
public abstract class HierarchySelectionPopup<T> : CoreDraggablePopupWindow where T : System.Enum
|
||||
{
|
||||
protected const float PADDING = 4f;
|
||||
protected const float SPACING = 1f;
|
||||
protected const float LINE_HEIGHT = 18f;
|
||||
protected const float LABELS_WIDTH = 90f;
|
||||
protected const float PREVIEW_SIZE_SMALL = 16f;
|
||||
protected const float PREVIEW_SIZE_LARGE = 64f;
|
||||
|
||||
protected Vector2 ScrollPos;
|
||||
protected Vector2 ScrollPos2;
|
||||
protected dynamic HierarchyRule;
|
||||
protected bool IsRuleSerialized;
|
||||
|
||||
private EditorWindow _parent;
|
||||
private Rect _windowRect;
|
||||
private Rect _backgroundRect;
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Properties
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
protected abstract Vector2 WindowSize { get; }
|
||||
protected abstract int GridColumns { get; }
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Public
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
public void ShowWithParams(Vector2 inPosition, dynamic hierarchyRule, EditorWindow parent = null)
|
||||
{
|
||||
var rect = new Rect(inPosition, WindowSize);
|
||||
_windowRect = new Rect(Vector2.zero, rect.size);
|
||||
_backgroundRect = new Rect(Vector2.one, rect.size - new Vector2(2f, 2f));
|
||||
|
||||
HierarchyRule = hierarchyRule;
|
||||
_parent = parent;
|
||||
IsRuleSerialized = parent == null;
|
||||
|
||||
Show<HierarchyPopupWindow>(rect);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Messages
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
protected override void OnGUI()
|
||||
{
|
||||
base.OnGUI();
|
||||
|
||||
if (focusedWindow != this) Close();
|
||||
|
||||
var rect = _windowRect;
|
||||
|
||||
DrawBackground();
|
||||
|
||||
rect.x = PADDING;
|
||||
rect.y = PADDING;
|
||||
rect.width = WindowSize.x - LABELS_WIDTH - 2f * PADDING;
|
||||
rect.height = WindowSize.y - 2f * PADDING;
|
||||
|
||||
DrawIcons(rect);
|
||||
|
||||
rect.x += rect.width + 1f;
|
||||
rect.width = 2f;
|
||||
|
||||
DrawSeparators(rect);
|
||||
|
||||
rect.x += rect.width + PADDING * 1.5f;
|
||||
rect.y += 1f;
|
||||
rect.width = LABELS_WIDTH - PADDING * 2.5f;
|
||||
rect.height = LINE_HEIGHT;
|
||||
|
||||
DrawButtons(rect);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Protected
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
protected void CloseAndRepaintParent()
|
||||
{
|
||||
_parent.Repaint();
|
||||
Close();
|
||||
}
|
||||
|
||||
protected void ApplyPropertyChangesAndClose(SerializedProperty projectItem)
|
||||
{
|
||||
var serializedObject = projectItem.serializedObject;
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
HierarchyRulesetV2.OnRulesetChangeCallback();
|
||||
Close();
|
||||
}
|
||||
|
||||
protected static Vector2 BeginScrollView(Vector2 scrollPos)
|
||||
{
|
||||
return EditorGUILayout.BeginScrollView(scrollPos, false, true,
|
||||
GUIStyle.none, GUI.skin.verticalScrollbar, GUI.skin.scrollView);
|
||||
}
|
||||
|
||||
protected override bool IsDragModifierPressed(Event e)
|
||||
{
|
||||
return HierarchyPreferences.IsDragModifierPressed(e);
|
||||
}
|
||||
|
||||
protected void DrawIconsGrid(IReadOnlyList<T> icons)
|
||||
{
|
||||
var count = icons.Count();
|
||||
var rows = Mathf.Ceil((float) count / GridColumns);
|
||||
|
||||
for (var i = 0; i < rows; i++)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
for (var j = 0; j < GridColumns; j++)
|
||||
{
|
||||
var id = i * GridColumns + j;
|
||||
if (id >= count)
|
||||
{
|
||||
GUILayout.FlexibleSpace();
|
||||
break;
|
||||
}
|
||||
|
||||
DrawIconButton(icons[id]);
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void DrawIconButton(T icon);
|
||||
|
||||
protected abstract void DrawButtons(Rect rect);
|
||||
|
||||
protected abstract void DrawIcons(Rect rect);
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Helpers
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
private void DrawBackground()
|
||||
{
|
||||
var isProSkin = EditorGUIUtility.isProSkin;
|
||||
|
||||
var borderColor = isProSkin ? POPUP_BORDER_CLR_PRO : POPUP_BORDER_CLR_FREE;
|
||||
EditorGUI.DrawRect(_windowRect, borderColor);
|
||||
|
||||
var backgroundColor = isProSkin ? POPUP_BACKGROUND_CLR_PRO : POPUP_BACKGROUND_CLR_FREE;
|
||||
EditorGUI.DrawRect(_backgroundRect, backgroundColor);
|
||||
}
|
||||
|
||||
private void DrawSeparators(Rect rect)
|
||||
{
|
||||
var color1 = (EditorGUIUtility.isProSkin) ? SEPARATOR_CLR_1_PRO : SEPARATOR_CLR_1_FREE;
|
||||
var color2 = (EditorGUIUtility.isProSkin) ? SEPARATOR_CLR_2_PRO : SEPARATOR_CLR_2_FREE;
|
||||
|
||||
rect.x += 0.5f * PADDING;
|
||||
rect.y = 1f;
|
||||
rect.width = 1f;
|
||||
rect.height = WindowSize.y - 2f;
|
||||
EditorGUI.DrawRect(rect, color1);
|
||||
rect.x += 1f;
|
||||
EditorGUI.DrawRect(rect, color2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bfd081adec187c342b1da7d0af61f011
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 106670
|
||||
packageName: Rainbow Hierarchy 2
|
||||
packageVersion: 2.6.2
|
||||
assetPath: Assets/Plugins/Borodar/RainbowHierarchy/Scripts/Editor/Windows/HierarchySelectionPopup.cs
|
||||
uploadId: 716077
|
||||
Reference in New Issue
Block a user