update CCK to 3.10, fixing unity 2021 crash :)
This commit is contained in:
parent
48a978fa2a
commit
d11e0fb3a9
492 changed files with 2165204 additions and 437687 deletions
426
Assets/ABI.CCK/Scripts/Editor/GUIExtensions/EditorGUIExtensions.cs
Executable file
426
Assets/ABI.CCK/Scripts/Editor/GUIExtensions/EditorGUIExtensions.cs
Executable file
|
@ -0,0 +1,426 @@
|
|||
#if UNITY_EDITOR
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using ABI.CCK.Scripts.Editor.Tools;
|
||||
using UnityEditor;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
public static partial class EditorGUIExtensions
|
||||
{
|
||||
private const float DEFAULT_DROPDOWN_BUTTON_WIDTH = 35;
|
||||
private static readonly Dictionary<string, GUIContent> s_iconContentCache = new();
|
||||
private static int s_lastSelectedValue = -1;
|
||||
|
||||
#region Specialized EditorGUI
|
||||
|
||||
public delegate void AppendAdditionalMenuItemsDelegate(GenericMenuBuilder genericMenuBuilder, ReorderableList list);
|
||||
public static void UtilityMenu(Rect rect, ReorderableList list, SerializedProperty property = null, AppendAdditionalMenuItemsDelegate appendAdditionalMenuItems = null)
|
||||
{
|
||||
Rect dropdownButtonRect = new(rect.x + rect.width - 21, rect.y, 20, EditorGUIUtility.singleLineHeight);
|
||||
if (!EditorGUI.DropdownButton(dropdownButtonRect, GUIContent.none, FocusType.Passive))
|
||||
return;
|
||||
|
||||
GenericMenuBuilder genericMenuBuilder = new();
|
||||
ClipboardUtils.AppendToMenu(genericMenuBuilder, list, property); // default for all uses atm
|
||||
if (appendAdditionalMenuItems != null)
|
||||
{
|
||||
genericMenuBuilder.AddSeparator();
|
||||
appendAdditionalMenuItems.Invoke(genericMenuBuilder, list);
|
||||
}
|
||||
genericMenuBuilder.DropDown(dropdownButtonRect);
|
||||
}
|
||||
|
||||
public static string AdvancedDropdownInput(
|
||||
Rect rect,
|
||||
string currentValue,
|
||||
List<string> dropdownItems,
|
||||
string label,
|
||||
string defaultTitle,
|
||||
GUIContent buttonContent = null)
|
||||
{
|
||||
if (buttonContent == null)
|
||||
{
|
||||
buttonContent = dropdownItems.Contains(currentValue)
|
||||
? GetCachedIconContent("d_Search Icon")
|
||||
: GetCachedIconContent("console.erroricon.sml");
|
||||
}
|
||||
|
||||
string title = (dropdownItems.Count == 0 ? defaultTitle : currentValue);
|
||||
return CustomDropdown(rect, label, currentValue, dropdownItems.ToArray(), buttonContent, DEFAULT_DROPDOWN_BUTTON_WIDTH, title);
|
||||
}
|
||||
|
||||
public static string AdvancedDropdownInput(
|
||||
Rect rect,
|
||||
string currentValue,
|
||||
List<string> dropdownItems,
|
||||
string title,
|
||||
GUIContent buttonContent = null)
|
||||
{
|
||||
if (buttonContent == null)
|
||||
{
|
||||
buttonContent = dropdownItems.Contains(currentValue)
|
||||
? GetCachedIconContent("d_Search Icon")
|
||||
: GetCachedIconContent("console.erroricon.sml");
|
||||
}
|
||||
|
||||
return CustomDropdown(rect, currentValue, dropdownItems.ToArray(), buttonContent, DEFAULT_DROPDOWN_BUTTON_WIDTH, title);
|
||||
}
|
||||
|
||||
public static string AdvancedDropdownInput(
|
||||
Rect rect,
|
||||
string currentValue,
|
||||
string[] dropdownItems,
|
||||
string title,
|
||||
GUIContent buttonContent = null)
|
||||
{
|
||||
if (buttonContent == null)
|
||||
{
|
||||
buttonContent = dropdownItems.Contains(currentValue)
|
||||
? GetCachedIconContent("d_Search Icon")
|
||||
: GetCachedIconContent("console.erroricon.sml");
|
||||
}
|
||||
|
||||
return CustomDropdown(rect, currentValue, dropdownItems, buttonContent, DEFAULT_DROPDOWN_BUTTON_WIDTH, title);
|
||||
}
|
||||
|
||||
// bit lazy ig
|
||||
public static void LimitSliderSided(string label, ref Vector2 limits, float hardLimitMin, float hardLimitMax)
|
||||
{
|
||||
var originalLabelWidth = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth = 150;
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.LabelField(label, GUILayout.Width(originalLabelWidth - 16));
|
||||
limits.x = EditorGUILayout.FloatField(limits.x, GUILayout.Width(50));
|
||||
GUILayout.Space(-13);
|
||||
EditorGUILayout.MinMaxSlider(ref limits.x, ref limits.y, hardLimitMin, hardLimitMax);
|
||||
GUILayout.Space(-13);
|
||||
limits.y = EditorGUILayout.FloatField(limits.y, GUILayout.Width(50));
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
EditorGUIUtility.labelWidth = originalLabelWidth;
|
||||
}
|
||||
|
||||
public static void LimitSliderSided(ref Rect rect, float spacing, string label, ref Vector2 limits, float hardLimitMin, float hardLimitMax)
|
||||
{
|
||||
// Save the original label width and adjust it for your custom drawing
|
||||
var originalLabelWidth = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth = 150;
|
||||
|
||||
// Calculate positions and sizes for custom drawing elements within the rect
|
||||
float labelWidth = originalLabelWidth - 16;
|
||||
float fieldWidth = 50;
|
||||
float sliderWidth = rect.width - labelWidth - fieldWidth * 2 - spacing * 4;
|
||||
float currentY = rect.y;
|
||||
|
||||
// Label
|
||||
Rect labelRect = new Rect(rect.x, currentY, labelWidth, EditorGUIUtility.singleLineHeight);
|
||||
GUI.Label(labelRect, label);
|
||||
|
||||
// Field for limits.x
|
||||
Rect fieldXRect = new Rect(labelRect.xMax + spacing, currentY, fieldWidth, EditorGUIUtility.singleLineHeight);
|
||||
limits.x = EditorGUI.FloatField(fieldXRect, limits.x);
|
||||
|
||||
// MinMaxSlider
|
||||
Rect sliderRect = new Rect(fieldXRect.xMax + spacing, currentY, sliderWidth, EditorGUIUtility.singleLineHeight);
|
||||
EditorGUI.MinMaxSlider(sliderRect, ref limits.x, ref limits.y, hardLimitMin, hardLimitMax);
|
||||
|
||||
// Field for limits.y
|
||||
Rect fieldYRect = new Rect(sliderRect.xMax + spacing, currentY, fieldWidth, EditorGUIUtility.singleLineHeight);
|
||||
limits.y = EditorGUI.FloatField(fieldYRect, limits.y);
|
||||
|
||||
// Reset the original label width
|
||||
EditorGUIUtility.labelWidth = originalLabelWidth;
|
||||
|
||||
// Adjust rect.y for the next control, if you're drawing multiple controls in sequence
|
||||
rect.y += spacing;
|
||||
}
|
||||
|
||||
public static void LimitSliderSidedProp(string label, SerializedProperty limitsProp, float hardLimitMin, float hardLimitMax) {
|
||||
Vector2 limits = limitsProp.vector2Value;
|
||||
LimitSliderSided(label, ref limits, hardLimitMin, hardLimitMax);
|
||||
limitsProp.vector2Value = limits;
|
||||
}
|
||||
|
||||
public static void LimitSliderSidedFloats(string label, SerializedProperty floatMin, SerializedProperty floatMax, float hardLimitMin, float hardLimitMax) {
|
||||
Vector2 limits = new(floatMin.floatValue, floatMax.floatValue);
|
||||
LimitSliderSided(label, ref limits, hardLimitMin, hardLimitMax);
|
||||
floatMin.floatValue = limits.x;
|
||||
floatMax.floatValue = limits.y;
|
||||
}
|
||||
|
||||
public static void LimitSliderSidedFloats(ref Rect rect, float spacing, string label, SerializedProperty floatMin, SerializedProperty floatMax, float hardLimitMin, float hardLimitMax) {
|
||||
Vector2 limits = new(floatMin.floatValue, floatMax.floatValue);
|
||||
LimitSliderSided(ref rect, spacing, label, ref limits, hardLimitMin, hardLimitMax);
|
||||
floatMin.floatValue = limits.x;
|
||||
floatMax.floatValue = limits.y;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CustomPopup
|
||||
|
||||
public static string CustomPopup(Rect rect, string label, string currentItem, string[] items,
|
||||
string title = null)
|
||||
{
|
||||
// TODO: temp fix
|
||||
int currentIndex = Array.IndexOf(items, currentItem);
|
||||
currentIndex = CustomPopup(rect, label, currentIndex, items, title);
|
||||
return currentIndex >= 0 && currentIndex < items.Length ? items[currentIndex] : CVRCommon.NONE_OR_EMPTY;
|
||||
}
|
||||
|
||||
public static string CustomPopup(Rect rect, string currentItem, string[] items,
|
||||
string title = null)
|
||||
{
|
||||
// TODO: temp fix
|
||||
int currentIndex = Array.IndexOf(items, currentItem);
|
||||
currentIndex = CustomPopup(rect, currentIndex, items, title);
|
||||
return currentIndex >= 0 && currentIndex < items.Length ? items[currentIndex] : CVRCommon.NONE_OR_EMPTY;
|
||||
}
|
||||
|
||||
public static int CustomPopup(Rect rect, string label, int currentItem, string[] items, string title = null)
|
||||
{
|
||||
int controlId = GUIUtility.GetControlID(FocusType.Passive);
|
||||
|
||||
// Use label width to position the dropdown appropriately
|
||||
float labelWidth = EditorGUIUtility.labelWidth;
|
||||
|
||||
Rect labelRect = new Rect(rect.x, rect.y, labelWidth, rect.height);
|
||||
Rect buttonRect = new Rect(rect.x + labelWidth, rect.y, rect.width - labelWidth, rect.height);
|
||||
|
||||
EditorGUI.LabelField(labelRect, label);
|
||||
|
||||
string current = currentItem >= 0 && currentItem < items.Length ? items[currentItem] : CVRCommon.NONE_OR_EMPTY;
|
||||
if (EditorGUI.DropdownButton(buttonRect, new GUIContent(current), FocusType.Passive))
|
||||
{
|
||||
GUIUtility.keyboardControl = controlId;
|
||||
new CustomAdvancedDropdown(new AdvancedDropdownState(), items, title, selected =>
|
||||
{
|
||||
s_lastSelectedValue = selected;
|
||||
}).Show(buttonRect); // We'll show the dropdown right where our buttonRect is
|
||||
}
|
||||
|
||||
if (controlId == GUIUtility.keyboardControl && s_lastSelectedValue != -1)
|
||||
{
|
||||
currentItem = s_lastSelectedValue;
|
||||
s_lastSelectedValue = -1;
|
||||
}
|
||||
|
||||
return currentItem;
|
||||
}
|
||||
|
||||
// CustomPopup but no label
|
||||
public static int CustomPopup(Rect rect, int currentItem, string[] items, string title = null)
|
||||
{
|
||||
int controlId = GUIUtility.GetControlID(FocusType.Passive);
|
||||
|
||||
Rect buttonRect = new Rect(rect.x, rect.y, rect.width, rect.height);
|
||||
|
||||
string current = currentItem >= 0 && currentItem < items.Length ? items[currentItem] : CVRCommon.NONE_OR_EMPTY;
|
||||
if (EditorGUI.DropdownButton(buttonRect, new GUIContent(current), FocusType.Passive))
|
||||
{
|
||||
GUIUtility.keyboardControl = controlId;
|
||||
new CustomAdvancedDropdown(new AdvancedDropdownState(), items, title, selected =>
|
||||
{
|
||||
s_lastSelectedValue = selected;
|
||||
}).Show(buttonRect); // We'll show the dropdown right where our buttonRect is
|
||||
}
|
||||
|
||||
if (controlId == GUIUtility.keyboardControl && s_lastSelectedValue != -1)
|
||||
{
|
||||
currentItem = s_lastSelectedValue;
|
||||
s_lastSelectedValue = -1;
|
||||
}
|
||||
|
||||
return currentItem;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region CustomDropdown
|
||||
|
||||
public static string CustomDropdown(
|
||||
Rect rect,
|
||||
string label,
|
||||
string currentItem,
|
||||
string[] items,
|
||||
string title = null)
|
||||
{
|
||||
GUIContent defaultButtonContent = items.Contains(currentItem)
|
||||
? GetCachedIconContent("d_Search Icon")
|
||||
: GetCachedIconContent("console.erroricon.sml");
|
||||
|
||||
return CustomDropdown(rect, label, currentItem, items, defaultButtonContent, DEFAULT_DROPDOWN_BUTTON_WIDTH, title);
|
||||
}
|
||||
|
||||
public static string CustomDropdown(
|
||||
Rect rect,
|
||||
string label,
|
||||
string currentItem,
|
||||
string[] items,
|
||||
GUIContent buttonContent,
|
||||
string title = null)
|
||||
{
|
||||
return CustomDropdown(rect, label, currentItem, items, buttonContent, DEFAULT_DROPDOWN_BUTTON_WIDTH, title);
|
||||
}
|
||||
|
||||
private static string CustomDropdown(
|
||||
Rect rect,
|
||||
string label,
|
||||
string currentItem,
|
||||
string[] items,
|
||||
GUIContent buttonContent,
|
||||
float dropdownButtonWidth,
|
||||
string title)
|
||||
{
|
||||
float labelWidth = 2f + EditorGUIUtility.labelWidth;
|
||||
float indentOffset = 15 * EditorGUI.indentLevel;
|
||||
|
||||
Rect textFieldRect = new Rect(rect.x + labelWidth - indentOffset, rect.y, rect.width - labelWidth + indentOffset - dropdownButtonWidth, rect.height);
|
||||
Rect buttonRect = new Rect(rect.x + rect.width - dropdownButtonWidth, rect.y, dropdownButtonWidth, rect.height);
|
||||
Rect dropdownRect = new Rect(rect.x + labelWidth, rect.y, rect.width - labelWidth, rect.height);
|
||||
|
||||
EditorGUI.LabelField(new Rect(rect.x, rect.y, labelWidth, rect.height), label);
|
||||
currentItem = EditorGUI.TextField(textFieldRect, currentItem);
|
||||
|
||||
return CustomDropdown(currentItem, items, title, buttonRect, dropdownRect, buttonContent);
|
||||
}
|
||||
|
||||
private static string CustomDropdown(
|
||||
Rect rect,
|
||||
string currentItem,
|
||||
string[] items,
|
||||
GUIContent buttonContent,
|
||||
float dropdownButtonWidth,
|
||||
string title)
|
||||
{
|
||||
float indentOffset = 15 * EditorGUI.indentLevel;
|
||||
Rect textFieldRect = new Rect(rect.x - indentOffset, rect.y, rect.width + indentOffset - dropdownButtonWidth, rect.height);
|
||||
Rect buttonRect = new Rect(rect.x + rect.width - dropdownButtonWidth, rect.y, dropdownButtonWidth, rect.height);
|
||||
Rect dropdownRect = new Rect(rect.x, rect.y, rect.width, rect.height);
|
||||
|
||||
currentItem = EditorGUI.TextField(textFieldRect, currentItem);
|
||||
return CustomDropdown(currentItem, items, title, buttonRect, dropdownRect, buttonContent);
|
||||
}
|
||||
|
||||
private static string CustomDropdown(
|
||||
string currentItem,
|
||||
string[] items,
|
||||
string title,
|
||||
Rect buttonRect,
|
||||
Rect dropdownRect,
|
||||
GUIContent buttonContent)
|
||||
{
|
||||
int controlId = GUIUtility.GetControlID(FocusType.Passive);
|
||||
|
||||
if (EditorGUI.DropdownButton(buttonRect, buttonContent, FocusType.Passive))
|
||||
{
|
||||
GUIUtility.keyboardControl = controlId;
|
||||
new CustomAdvancedDropdown(new AdvancedDropdownState(), items, title, selected =>
|
||||
{
|
||||
s_lastSelectedValue = selected;
|
||||
}).Show(dropdownRect);
|
||||
}
|
||||
|
||||
if (controlId == GUIUtility.keyboardControl && s_lastSelectedValue != -1)
|
||||
{
|
||||
currentItem = items[s_lastSelectedValue];
|
||||
s_lastSelectedValue = -1;
|
||||
}
|
||||
|
||||
return currentItem;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
public static GUIContent GetCachedIconContent(string iconName)
|
||||
{
|
||||
if (s_iconContentCache.TryGetValue(iconName, out GUIContent iconContent))
|
||||
return iconContent;
|
||||
|
||||
iconContent = EditorGUIUtility.IconContent(iconName);
|
||||
s_iconContentCache[iconName] = iconContent;
|
||||
return iconContent;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Custom GUI
|
||||
|
||||
private class CustomAdvancedDropdown : AdvancedDropdown
|
||||
{
|
||||
private readonly Action<int> _onItemSelected;
|
||||
private readonly string[] _items;
|
||||
private readonly string _title;
|
||||
|
||||
internal CustomAdvancedDropdown(AdvancedDropdownState state, string[] items, string title, Action<int> onItemSelected) : base(state)
|
||||
{
|
||||
_items = items ?? Array.Empty<string>();
|
||||
_title = title ?? "Items";
|
||||
_onItemSelected = onItemSelected;
|
||||
}
|
||||
|
||||
internal new void Show(Rect rect)
|
||||
{
|
||||
minimumSize = new Vector2(rect.width, 200f);
|
||||
|
||||
// We have to set the maximumSize through reflection, cause unity is cool
|
||||
typeof(AdvancedDropdown).GetProperty("maximumSize", BindingFlags.NonPublic | BindingFlags.Instance)
|
||||
?.SetValue(this, new Vector2(rect.width, 400f));
|
||||
|
||||
base.Show(rect);
|
||||
}
|
||||
|
||||
protected override AdvancedDropdownItem BuildRoot()
|
||||
{
|
||||
AdvancedDropdownItem root = new AdvancedDropdownItem(_title);
|
||||
|
||||
for (var itemIdx = 0; itemIdx < _items.Length; itemIdx++)
|
||||
{
|
||||
var item = _items[itemIdx];
|
||||
AdvancedDropdownItem current = root;
|
||||
string[] parts = item.Split('/');
|
||||
|
||||
for (int i = 0; i < parts.Length; i++)
|
||||
{
|
||||
string name = parts[i];
|
||||
AdvancedDropdownItem child = current.children.FirstOrDefault(c => c.name == name);
|
||||
|
||||
if (child == null)
|
||||
{
|
||||
child = new AdvancedDropdownItem(name)
|
||||
{
|
||||
id = itemIdx // id is based on itteration order
|
||||
};
|
||||
if (name == item && name == _title)
|
||||
child.icon = GetCachedIconContent("d_FilterSelectedOnly").image as Texture2D;
|
||||
|
||||
current.AddChild(child);
|
||||
}
|
||||
|
||||
current = child;
|
||||
}
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
protected override void ItemSelected(AdvancedDropdownItem item)
|
||||
{
|
||||
base.ItemSelected(item);
|
||||
_onItemSelected?.Invoke(item.id);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endif
|
11
Assets/ABI.CCK/Scripts/Editor/GUIExtensions/EditorGUIExtensions.cs.meta
Executable file
11
Assets/ABI.CCK/Scripts/Editor/GUIExtensions/EditorGUIExtensions.cs.meta
Executable file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bb7564b297385b242aff07896a00c0b0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
68
Assets/ABI.CCK/Scripts/Editor/GUIExtensions/EnumFilter.cs
Executable file
68
Assets/ABI.CCK/Scripts/Editor/GUIExtensions/EnumFilter.cs
Executable file
|
@ -0,0 +1,68 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
public static class EnumFilter
|
||||
{
|
||||
public static TEnum FilteredEnumPopup<TEnum, TAttribute>(TEnum enumValue)
|
||||
where TEnum : struct, Enum
|
||||
where TAttribute : Attribute
|
||||
{
|
||||
return FilteredEnumPopup<TEnum, TAttribute>(enumValue, $"{typeof(TEnum).Name}:");
|
||||
}
|
||||
|
||||
public static TEnum FilteredEnumPopup<TEnum, TAttribute>(TEnum enumValue, string label)
|
||||
where TEnum : struct, Enum
|
||||
where TAttribute : Attribute
|
||||
{
|
||||
if (!typeof(TEnum).IsEnum)
|
||||
throw new ArgumentException("TEnum must be an enumerated type");
|
||||
|
||||
var allValues = Enum.GetValues(typeof(TEnum)).Cast<TEnum>();
|
||||
|
||||
var filteredValues = allValues
|
||||
.Where(enumVal => enumVal.GetType().GetField(enumVal.ToString())
|
||||
.GetCustomAttributes(typeof(TAttribute), false).Length > 0)
|
||||
.ToList();
|
||||
|
||||
var filteredNames = filteredValues.Select(enumVal => enumVal.ToString()).ToList();
|
||||
if (!filteredValues.Contains(enumValue))
|
||||
{
|
||||
filteredValues.Add(enumValue);
|
||||
filteredNames.Add(enumValue.ToString());
|
||||
EditorGUILayout.HelpBox($"The current selection ({enumValue}) is not valid for the current context!", MessageType.Warning);
|
||||
}
|
||||
|
||||
int currentIndex = filteredNames.IndexOf(enumValue.ToString());
|
||||
int selectedIndex = EditorGUILayout.Popup(label, currentIndex, filteredNames.ToArray());
|
||||
|
||||
return selectedIndex >= 0 && selectedIndex < filteredValues.Count
|
||||
? filteredValues[selectedIndex]
|
||||
: enumValue;
|
||||
}
|
||||
|
||||
public static TEnum FilteredEnumPopup<TEnum>(Rect position, TEnum enumValue, List<TEnum> supportedTypes)
|
||||
where TEnum : struct, Enum
|
||||
{
|
||||
if (!typeof(TEnum).IsEnum)
|
||||
throw new ArgumentException("TEnum must be an enumerated type");
|
||||
|
||||
// If enumValue is not in supportedTypes, default to the first supported type
|
||||
if (!supportedTypes.Contains(enumValue))
|
||||
enumValue = supportedTypes[0];
|
||||
|
||||
var displayNames = supportedTypes.Select(e => e.ToString()).ToArray();
|
||||
int currentIndex = Array.IndexOf(displayNames, enumValue.ToString());
|
||||
|
||||
int selectedIndex = EditorGUI.Popup(position, currentIndex, displayNames);
|
||||
|
||||
return selectedIndex >= 0 && selectedIndex < supportedTypes.Count
|
||||
? supportedTypes[selectedIndex]
|
||||
: enumValue;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/ABI.CCK/Scripts/Editor/GUIExtensions/EnumFilter.cs.meta
Executable file
11
Assets/ABI.CCK/Scripts/Editor/GUIExtensions/EnumFilter.cs.meta
Executable file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3591fd7065cd3f74c8eb35bd84571e25
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
30
Assets/ABI.CCK/Scripts/Editor/GUIExtensions/GenericMenuBuilder.cs
Executable file
30
Assets/ABI.CCK/Scripts/Editor/GUIExtensions/GenericMenuBuilder.cs
Executable file
|
@ -0,0 +1,30 @@
|
|||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
public class GenericMenuBuilder
|
||||
{
|
||||
private readonly GenericMenu _menu = new GenericMenu();
|
||||
|
||||
public void AddMenuItem(string itemName, bool condition, GenericMenu.MenuFunction callback)
|
||||
{
|
||||
if (condition)
|
||||
_menu.AddItem(new GUIContent(itemName), false, callback);
|
||||
else
|
||||
_menu.AddDisabledItem(new GUIContent(itemName));
|
||||
}
|
||||
|
||||
public void AddSeparator(string path = "")
|
||||
{
|
||||
_menu.AddSeparator(path);
|
||||
}
|
||||
|
||||
public void DropDown(Rect position)
|
||||
{
|
||||
_menu.DropDown(position);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
11
Assets/ABI.CCK/Scripts/Editor/GUIExtensions/GenericMenuBuilder.cs.meta
Executable file
11
Assets/ABI.CCK/Scripts/Editor/GUIExtensions/GenericMenuBuilder.cs.meta
Executable file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 90c5b79018f4de14790c3dc5d98c2c33
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
73
Assets/ABI.CCK/Scripts/Editor/GUIExtensions/MultiProgressBar.cs
Executable file
73
Assets/ABI.CCK/Scripts/Editor/GUIExtensions/MultiProgressBar.cs
Executable file
|
@ -0,0 +1,73 @@
|
|||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
public static partial class EditorGUIExtensions
|
||||
{
|
||||
private static readonly int s_ProgressBarHashCode = "s_ProgressBarHash".GetHashCode();
|
||||
private static readonly GUIStyle s_BarBack = new GUIStyle("ProgressBarBack");
|
||||
private static readonly GUIStyle s_BarBarBlue = new GUIStyle("ProgressBarBar");
|
||||
private static readonly GUIStyle s_BarBarYellow;
|
||||
private static readonly GUIStyle s_BarBarRed;
|
||||
private static readonly GUIStyle s_BarText = new GUIStyle("ProgressBarText");
|
||||
|
||||
static EditorGUIExtensions()
|
||||
{
|
||||
// Custom progress bar
|
||||
s_BarBarYellow = new GUIStyle(s_BarBarBlue);
|
||||
InitTextureForStyle(s_BarBarYellow, Color.yellow);
|
||||
s_BarBarRed = new GUIStyle(s_BarBarBlue);
|
||||
InitTextureForStyle(s_BarBarRed, Color.red);
|
||||
}
|
||||
|
||||
public static void MultiProgressBar(Rect position, float value1, float value2, string text)
|
||||
{
|
||||
if (Event.current.GetTypeForControl(GUIUtility.GetControlID(s_ProgressBarHashCode, FocusType.Keyboard,
|
||||
position)) != EventType.Repaint)
|
||||
return;
|
||||
|
||||
s_BarBack.Draw(position, false, false, false, false);
|
||||
|
||||
GUIStyle styleForValue1 = value1 > 1f ? s_BarBarRed : s_BarBarBlue;
|
||||
GUIStyle styleForValue2 = value2 > 1f ? s_BarBarRed : s_BarBarYellow;
|
||||
|
||||
value1 = Mathf.Clamp01(value1);
|
||||
value2 = Mathf.Clamp01(value2);
|
||||
|
||||
Rect position1 = new Rect(position);
|
||||
Rect position2 = new Rect(position);
|
||||
position1.width *= value1;
|
||||
position2.width *= value2;
|
||||
|
||||
if (value1 > value2)
|
||||
{
|
||||
if (value1 > 0f) styleForValue1.Draw(position1, false, false, false, false);
|
||||
if (value2 > 0f) styleForValue2.Draw(position2, false, false, false, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value2 > 0f) styleForValue2.Draw(position2, false, false, false, false);
|
||||
if (value1 > 0f) styleForValue1.Draw(position1, false, false, false, false);
|
||||
}
|
||||
|
||||
s_BarText.Draw(position, text, false, false, false, false);
|
||||
}
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private static void InitTextureForStyle(GUIStyle style, Color color)
|
||||
{
|
||||
Texture2D texture = new Texture2D(1, 3);
|
||||
texture.SetPixel(0, 0, color + new Color(0.1f, 0.1f, 0f, 0f));
|
||||
texture.SetPixel(0, 1, color);
|
||||
texture.SetPixel(0, 2, color - new Color(0.1f, 0.1f, 0f, 0f));
|
||||
texture.Apply();
|
||||
style.normal.background = texture;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
#endif
|
11
Assets/ABI.CCK/Scripts/Editor/GUIExtensions/MultiProgressBar.cs.meta
Executable file
11
Assets/ABI.CCK/Scripts/Editor/GUIExtensions/MultiProgressBar.cs.meta
Executable file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 00903c392d8785e4fa80ab1ee6403922
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
177
Assets/ABI.CCK/Scripts/Editor/GUIExtensions/SharedComponentGUI.cs
Executable file
177
Assets/ABI.CCK/Scripts/Editor/GUIExtensions/SharedComponentGUI.cs
Executable file
|
@ -0,0 +1,177 @@
|
|||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ABI.CCK.Scripts.Editor
|
||||
{
|
||||
// Shared between all Custom Editors for CCK Components specifically
|
||||
public static class SharedComponentGUI
|
||||
{
|
||||
public static readonly GUIStyle s_BoldLabelStyle;
|
||||
public static readonly GUIStyle s_BoldFoldoutStyle;
|
||||
|
||||
static SharedComponentGUI()
|
||||
{
|
||||
// Foldout scope styles
|
||||
s_BoldLabelStyle = new GUIStyle(EditorStyles.label) { fontStyle = FontStyle.Bold };
|
||||
s_BoldFoldoutStyle = new GUIStyle(EditorStyles.foldout) { fontStyle = FontStyle.Bold };
|
||||
}
|
||||
|
||||
public static void Separator()
|
||||
{
|
||||
GUILayout.Space(2);
|
||||
GUILayout.Box("", EditorStyles.helpBox, GUILayout.ExpandWidth(true), GUILayout.Height(2));
|
||||
GUILayout.Space(2);
|
||||
}
|
||||
|
||||
public static bool InnerFoldout(ref bool foldoutState, string label, GUIStyle style = null)
|
||||
{
|
||||
return foldoutState = EditorGUILayout.Foldout(foldoutState, label, true, style ?? EditorStyles.foldout);
|
||||
}
|
||||
|
||||
public static bool InnerFoldout(ref bool foldoutState, GUIContent label, GUIStyle style = null)
|
||||
{
|
||||
return foldoutState = EditorGUILayout.Foldout(foldoutState, label, true, style ?? EditorStyles.foldout);
|
||||
}
|
||||
|
||||
public class LabelScope : GUI.Scope
|
||||
{
|
||||
// Magic numbers
|
||||
private const float LabelHeight = 24.0f;
|
||||
private const float IndentX = 8.0f;
|
||||
private const float VerticalSpacingAdjust = -26.0f;
|
||||
|
||||
public LabelScope(string label, GUIStyle style = null)
|
||||
{
|
||||
InitLabelScope(new GUIContent(label), style ?? s_BoldLabelStyle);
|
||||
}
|
||||
|
||||
public LabelScope(GUIContent label, GUIStyle style = null)
|
||||
{
|
||||
InitLabelScope(label, style ?? s_BoldLabelStyle);
|
||||
}
|
||||
|
||||
private void InitLabelScope(GUIContent label, GUIStyle style)
|
||||
{
|
||||
// Label
|
||||
Rect labelRect = GUILayoutUtility.GetRect(1.0f, LabelHeight);
|
||||
EditorGUI.HelpBox(labelRect, "", MessageType.None);
|
||||
labelRect.x += IndentX;
|
||||
labelRect.width -= IndentX;
|
||||
EditorGUI.LabelField(labelRect, label, style);
|
||||
|
||||
// Content
|
||||
GUILayout.Space(VerticalSpacingAdjust);
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(LabelHeight);
|
||||
}
|
||||
|
||||
protected override void CloseScope()
|
||||
{
|
||||
GUILayout.Space(3f);
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
}
|
||||
|
||||
public class FoldoutScope : GUI.Scope
|
||||
{
|
||||
// Magic numbers
|
||||
private const float FoldoutHeight = 24.0f;
|
||||
private const float IndentX = 18.0f;
|
||||
private const float VerticalSpacingAdjust = -26.0f;
|
||||
|
||||
public FoldoutScope(ref bool foldoutState, string label, GUIStyle style = null)
|
||||
{
|
||||
InitFoldoutScope(ref foldoutState, new GUIContent(label), style ?? s_BoldFoldoutStyle);
|
||||
}
|
||||
|
||||
public FoldoutScope(ref bool foldoutState, GUIContent label, GUIStyle style = null)
|
||||
{
|
||||
InitFoldoutScope(ref foldoutState, label, style ?? s_BoldFoldoutStyle);
|
||||
}
|
||||
|
||||
private void InitFoldoutScope(ref bool foldoutState, GUIContent label, GUIStyle style)
|
||||
{
|
||||
// Foldout
|
||||
Rect foldoutRect = GUILayoutUtility.GetRect(1.0f, FoldoutHeight);
|
||||
EditorGUI.HelpBox(foldoutRect, "", MessageType.None);
|
||||
foldoutRect.x += IndentX;
|
||||
foldoutRect.width -= IndentX;
|
||||
foldoutState = EditorGUI.Foldout(foldoutRect, foldoutState, label, true, style);
|
||||
|
||||
// Content
|
||||
GUILayout.Space(VerticalSpacingAdjust);
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(foldoutState ? FoldoutHeight : 21);
|
||||
}
|
||||
|
||||
protected override void CloseScope()
|
||||
{
|
||||
GUILayout.Space(3f);
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
}
|
||||
|
||||
public class ToggleFoldoutScope : GUI.Scope
|
||||
{
|
||||
// Magic numbers 2
|
||||
private const float FoldoutHeight = 24.0f;
|
||||
private const float IndentX = 18.0f;
|
||||
private const float VerticalSpacingAdjust = -26.0f;
|
||||
private const float ToggleWidth = 16.0f;
|
||||
|
||||
public ToggleFoldoutScope(ref bool foldoutState, ref bool toggleState, string label, GUIStyle style = null)
|
||||
{
|
||||
InitToggleFoldoutScope(ref foldoutState, ref toggleState, new GUIContent(label), style ?? s_BoldFoldoutStyle);
|
||||
}
|
||||
|
||||
public ToggleFoldoutScope(ref bool foldoutState, ref bool toggleState, GUIContent label, GUIStyle style = null)
|
||||
{
|
||||
InitToggleFoldoutScope(ref foldoutState, ref toggleState, label, style ?? s_BoldFoldoutStyle);
|
||||
}
|
||||
|
||||
private void InitToggleFoldoutScope(ref bool foldoutState, ref bool toggleState, GUIContent label, GUIStyle style)
|
||||
{
|
||||
// Foldout
|
||||
Rect fullRect = GUILayoutUtility.GetRect(1.0f, FoldoutHeight);
|
||||
EditorGUI.HelpBox(fullRect, "", MessageType.None);
|
||||
|
||||
// Toggle
|
||||
Rect toggleRect = new Rect(fullRect.x + IndentX + 1f, fullRect.y + 1f, ToggleWidth, FoldoutHeight);
|
||||
toggleState = EditorGUI.Toggle(toggleRect, toggleState);
|
||||
|
||||
// Foldout
|
||||
Rect foldoutRect = new Rect(fullRect.x + IndentX, fullRect.y, fullRect.width - IndentX, FoldoutHeight);
|
||||
foldoutState = EditorGUI.Foldout(foldoutRect, foldoutState, " " + label, true, style);
|
||||
|
||||
// Content
|
||||
GUILayout.Space(VerticalSpacingAdjust);
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(foldoutState ? FoldoutHeight : 21);
|
||||
}
|
||||
|
||||
protected override void CloseScope()
|
||||
{
|
||||
GUILayout.Space(3f);
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
}
|
||||
|
||||
public class SetIndentLevelScope : GUI.Scope
|
||||
{
|
||||
private readonly int originalIndentLevel;
|
||||
|
||||
public SetIndentLevelScope(int indentLevel)
|
||||
{
|
||||
originalIndentLevel = EditorGUI.indentLevel;
|
||||
EditorGUI.indentLevel = indentLevel;
|
||||
}
|
||||
|
||||
protected override void CloseScope()
|
||||
{
|
||||
EditorGUI.indentLevel = originalIndentLevel;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
11
Assets/ABI.CCK/Scripts/Editor/GUIExtensions/SharedComponentGUI.cs.meta
Executable file
11
Assets/ABI.CCK/Scripts/Editor/GUIExtensions/SharedComponentGUI.cs.meta
Executable file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 954dde6e1cffbf34c9e843e1ca804a88
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue