First commit for private source control. Older commits available on Github.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AYellowpaper.SerializedCollections.Editor
|
||||
{
|
||||
public struct GUIEnabledScope : IDisposable
|
||||
{
|
||||
public readonly bool PreviouslyEnabled;
|
||||
|
||||
public GUIEnabledScope(bool enabled)
|
||||
{
|
||||
PreviouslyEnabled = GUI.enabled;
|
||||
GUI.enabled = enabled;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
GUI.enabled = PreviouslyEnabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c671c12e9de22d042be004c62b6f4158
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 243052
|
||||
packageName: Serialized Dictionary
|
||||
packageVersion: 1.0.13
|
||||
assetPath: Assets/Plugins/SerializedCollections/Editor/Scripts/Utility/GUIEnabledScope.cs
|
||||
uploadId: 632226
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AYellowpaper.SerializedCollections.Editor
|
||||
{
|
||||
public struct LabelWidth : IDisposable
|
||||
{
|
||||
public float PreviousWidth { get; }
|
||||
|
||||
public LabelWidth(float width)
|
||||
{
|
||||
PreviousWidth = EditorGUIUtility.labelWidth;
|
||||
EditorGUIUtility.labelWidth = width;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
EditorGUIUtility.labelWidth = PreviousWidth;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd75bc249daa39f4e832a3dab9c23c82
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 243052
|
||||
packageName: Serialized Dictionary
|
||||
packageVersion: 1.0.13
|
||||
assetPath: Assets/Plugins/SerializedCollections/Editor/Scripts/Utility/LabelWidth.cs
|
||||
uploadId: 632226
|
||||
@@ -0,0 +1,41 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace AYellowpaper.SerializedCollections.Editor
|
||||
{
|
||||
public static class RectUtility
|
||||
{
|
||||
public static Rect WithX(this Rect rect, float x) => new Rect(x, rect.y, rect.width, rect.height);
|
||||
public static Rect WithY(this Rect rect, float y) => new Rect(rect.x, y, rect.width, rect.height);
|
||||
public static Rect WithWidth(this Rect rect, float width) => new Rect(rect.x, rect.y, width, rect.height);
|
||||
public static Rect WithHeight(this Rect rect, float height) => new Rect(rect.x, rect.y, rect.width, height);
|
||||
public static Rect WithPosition(this Rect rect, Vector2 position) => new Rect(position, rect.size);
|
||||
public static Rect WithPosition(this Rect rect, float x, float y) => new Rect(new Vector2(x, y), rect.size);
|
||||
public static Rect WithSize(this Rect rect, Vector2 size) => new Rect(rect.position, size);
|
||||
public static Rect WithSize(this Rect rect, float width, float height) => new Rect(rect.position, new Vector2(width, height));
|
||||
|
||||
public static Rect WithXAndWidth(this Rect rect, float x, float width) => new Rect(x, rect.y, width, rect.height);
|
||||
public static Rect WithYAndHeight(this Rect rect, float y, float height) => new Rect(rect.x, y, rect.width, height);
|
||||
|
||||
public static Rect AppendRight(this Rect rect, float width) => new Rect(rect.x + rect.width, rect.y, width, rect.height);
|
||||
public static Rect AppendRight(this Rect rect, float width, float space) => new Rect(rect.x + rect.width + space, rect.y, width, rect.height);
|
||||
public static Rect AppendLeft(this Rect rect, float width) => new Rect(rect.x - width, rect.y, width, rect.height);
|
||||
public static Rect AppendLeft(this Rect rect, float width, float space) => new Rect(rect.x - space - width, rect.y, width, rect.height);
|
||||
public static Rect AppendUp(this Rect rect, float height) => new Rect(rect.x, rect.y - height, rect.width, height);
|
||||
public static Rect AppendUp(this Rect rect, float height, float space) => new Rect(rect.x, rect.y - space - height, rect.width, height);
|
||||
public static Rect AppendDown(this Rect rect, float height) => new Rect(rect.x, rect.y + rect.height, rect.width, height);
|
||||
public static Rect AppendDown(this Rect rect, float height, float space) => new Rect(rect.x, rect.y + rect.height + space, rect.width, height);
|
||||
|
||||
public static Rect CutLeft(this Rect rect, float width) => new Rect(rect.x + width, rect.y, rect.width - width, rect.height);
|
||||
public static Rect CutRight(this Rect rect, float width) => new Rect(rect.x, rect.y, rect.width - width, rect.height);
|
||||
public static Rect CutTop(this Rect rect, float height) => new Rect(rect.x, rect.y + height, rect.width, rect.height - height);
|
||||
public static Rect CutBottom(this Rect rect, float height) => new Rect(rect.x, rect.y, rect.width, rect.height - height);
|
||||
|
||||
public static Rect CutHorizontal(this Rect rect, float leftAndRight) => CutHorizontal(rect, leftAndRight, leftAndRight);
|
||||
public static Rect CutHorizontal(this Rect rect, float left, float right) => new Rect(rect.x + left, rect.y, rect.width - left - right, rect.height);
|
||||
public static Rect CutVertical(this Rect rect, float topAndBottom) => CutVertical(rect, topAndBottom, topAndBottom);
|
||||
public static Rect CutVertical(this Rect rect, float top, float bottom) => new Rect(rect.x, rect.y + top, rect.width, rect.height - top - bottom);
|
||||
|
||||
public static Rect Cut(this Rect rect, float topBottom, float leftRight) => Cut(rect, topBottom, leftRight, topBottom, leftRight);
|
||||
public static Rect Cut(this Rect rect, float top, float right, float bottom, float left) => new Rect(rect.x + left, rect.y + top, rect.width - left - right, rect.height - top - bottom);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 68261ebef89d61441a35961731b0a083
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 243052
|
||||
packageName: Serialized Dictionary
|
||||
packageVersion: 1.0.13
|
||||
assetPath: Assets/Plugins/SerializedCollections/Editor/Scripts/Utility/RectUtility.cs
|
||||
uploadId: 632226
|
||||
@@ -0,0 +1,245 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using System.Linq;
|
||||
using AYellowpaper.SerializedCollections.Editor.Data;
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace AYellowpaper.SerializedCollections.Editor
|
||||
{
|
||||
internal static class SCEditorUtility
|
||||
{
|
||||
public const string EditorPrefsPrefix = "SC_";
|
||||
public const bool KeyFlag = true;
|
||||
public const bool ValueFlag = false;
|
||||
|
||||
public static float CalculateHeight(SerializedProperty property, DisplayType displayType)
|
||||
{
|
||||
return CalculateHeight(property, displayType == DisplayType.List ? true : false);
|
||||
}
|
||||
|
||||
public static float CalculateHeight(SerializedProperty property, bool drawAsList)
|
||||
{
|
||||
if (drawAsList)
|
||||
{
|
||||
float height = 0;
|
||||
foreach (SerializedProperty child in GetChildren(property))
|
||||
height += EditorGUI.GetPropertyHeight(child, true);
|
||||
return height;
|
||||
}
|
||||
|
||||
return EditorGUI.GetPropertyHeight(property, true);
|
||||
}
|
||||
|
||||
public static IEnumerable<SerializedProperty> GetChildren(SerializedProperty property, bool recursive = false)
|
||||
{
|
||||
if (!property.hasVisibleChildren)
|
||||
{
|
||||
yield return property;
|
||||
yield break;
|
||||
}
|
||||
|
||||
SerializedProperty end = property.GetEndProperty();
|
||||
property.NextVisible(true);
|
||||
do
|
||||
{
|
||||
yield return property;
|
||||
} while (property.NextVisible(recursive) && !SerializedProperty.EqualContents(property, end));
|
||||
}
|
||||
|
||||
public static PropertyData GetPropertyData(SerializedProperty property)
|
||||
{
|
||||
var data = new PropertyData();
|
||||
var json = EditorPrefs.GetString(EditorPrefsPrefix + property.propertyPath, null);
|
||||
if (json != null)
|
||||
EditorJsonUtility.FromJsonOverwrite(json, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
public static void SavePropertyData(SerializedProperty property, PropertyData propertyData)
|
||||
{
|
||||
var json = EditorJsonUtility.ToJson(propertyData);
|
||||
EditorPrefs.SetString(EditorPrefsPrefix + property.propertyPath, json);
|
||||
}
|
||||
|
||||
public static bool ShouldShowSearch(int pages)
|
||||
{
|
||||
var settings = EditorUserSettings.Get();
|
||||
return settings.AlwaysShowSearch ? true : pages >= settings.PageCountForSearch;
|
||||
}
|
||||
|
||||
public static bool HasDrawerForProperty(SerializedProperty property, Type type)
|
||||
{
|
||||
Type attributeUtilityType = typeof(SerializedProperty).Assembly.GetType("UnityEditor.ScriptAttributeUtility");
|
||||
if (attributeUtilityType == null)
|
||||
return false;
|
||||
var getDrawerMethod = attributeUtilityType.GetMethod("GetDrawerTypeForPropertyAndType", BindingFlags.Static | BindingFlags.NonPublic);
|
||||
if (getDrawerMethod == null)
|
||||
return false;
|
||||
return getDrawerMethod.Invoke(null, new object[] { property, type }) != null;
|
||||
}
|
||||
|
||||
internal static void AddGenericMenuItem(GenericMenu genericMenu, bool isOn, bool isEnabled, GUIContent content, GenericMenu.MenuFunction action)
|
||||
{
|
||||
if (isEnabled)
|
||||
genericMenu.AddItem(content, isOn, action);
|
||||
else
|
||||
genericMenu.AddDisabledItem(content);
|
||||
}
|
||||
|
||||
internal static void AddGenericMenuItem(GenericMenu genericMenu, bool isOn, bool isEnabled, GUIContent content, GenericMenu.MenuFunction2 action, object userData)
|
||||
{
|
||||
if (isEnabled)
|
||||
genericMenu.AddItem(content, isOn, action, userData);
|
||||
else
|
||||
genericMenu.AddDisabledItem(content);
|
||||
}
|
||||
|
||||
internal static bool TryGetTypeFromProperty(SerializedProperty property, out Type type)
|
||||
{
|
||||
try
|
||||
{
|
||||
var classType = typeof(EditorGUI).Assembly.GetType("UnityEditor.ScriptAttributeUtility");
|
||||
var methodInfo = classType.GetMethod("GetFieldInfoFromProperty", BindingFlags.Static | BindingFlags.NonPublic);
|
||||
var parameters = new object[] { property, null };
|
||||
methodInfo.Invoke(null, parameters);
|
||||
type = (Type) parameters[1];
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
type = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
internal static float DoHorizontalScale(Rect rect, float value)
|
||||
{
|
||||
var controlId = GUIUtility.GetControlID(FocusType.Passive);
|
||||
var isMovingMouse = Event.current.type == EventType.MouseDrag;
|
||||
DoButtonControl(rect, controlId, false, false, GUIContent.none, GUIStyle.none);
|
||||
|
||||
if (controlId == GUIUtility.hotControl && isMovingMouse)
|
||||
{
|
||||
value += Event.current.delta.x;
|
||||
GUI.changed = true;
|
||||
}
|
||||
|
||||
EditorGUIUtility.AddCursorRect(rect, MouseCursor.ResizeHorizontal);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
internal static bool DoButtonControl(Rect rect, int id, bool on, bool hover, GUIContent content, GUIStyle style)
|
||||
{
|
||||
Event current = Event.current;
|
||||
switch (current.type)
|
||||
{
|
||||
case EventType.MouseDown:
|
||||
if (HitTest(rect, current.mousePosition))
|
||||
{
|
||||
GUIUtility.hotControl = id;
|
||||
current.Use();
|
||||
}
|
||||
break;
|
||||
case EventType.MouseUp:
|
||||
if (GUIUtility.hotControl == id)
|
||||
{
|
||||
GUIUtility.hotControl = 0;
|
||||
current.Use();
|
||||
if (HitTest(rect, current.mousePosition))
|
||||
{
|
||||
GUI.changed = true;
|
||||
return !on;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case EventType.MouseDrag:
|
||||
if (GUIUtility.hotControl == id)
|
||||
{
|
||||
current.Use();
|
||||
}
|
||||
break;
|
||||
case EventType.KeyDown:
|
||||
bool flag = current.alt || current.shift || current.command || current.control;
|
||||
if ((current.keyCode == KeyCode.Space || current.keyCode == KeyCode.Return || current.keyCode == KeyCode.KeypadEnter) && !flag && GUIUtility.keyboardControl == id)
|
||||
{
|
||||
current.Use();
|
||||
GUI.changed = true;
|
||||
return !on;
|
||||
}
|
||||
break;
|
||||
case EventType.Repaint:
|
||||
style.Draw(rect, content, id, on, hover);
|
||||
break;
|
||||
}
|
||||
return on;
|
||||
}
|
||||
|
||||
internal static bool HitTest(Rect rect, Vector2 point) => point.x >= rect.xMin && point.x < rect.xMax && point.y >= rect.yMin && point.y < rect.yMax;
|
||||
|
||||
|
||||
public static object GetPropertyValue(SerializedProperty prop, object target)
|
||||
{
|
||||
var path = prop.propertyPath.Replace(".Array.data[", "[");
|
||||
var elements = path.Split('.');
|
||||
foreach (var element in elements.Take(elements.Length - 1))
|
||||
{
|
||||
if (element.Contains("["))
|
||||
{
|
||||
var elementName = element.Substring(0, element.IndexOf("["));
|
||||
var index = Convert.ToInt32(element.Substring(element.IndexOf("[")).Replace("[", "").Replace("]", ""));
|
||||
target = GetValue(target, elementName, index);
|
||||
}
|
||||
else
|
||||
{
|
||||
target = GetValue(target, element);
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
public static object GetValue(object source, string name)
|
||||
{
|
||||
if (source == null)
|
||||
return null;
|
||||
var type = source.GetType();
|
||||
var f = type.GetFieldRecursive(name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
|
||||
if (f == null)
|
||||
{
|
||||
var p = type.GetPropertyRecursive(name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase);
|
||||
if (p == null)
|
||||
return null;
|
||||
return p.GetValue(source, null);
|
||||
}
|
||||
return f.GetValue(source);
|
||||
}
|
||||
|
||||
public static object GetValue(object source, string name, int index)
|
||||
{
|
||||
var enumerable = GetValue(source, name) as IEnumerable;
|
||||
var enm = enumerable.GetEnumerator();
|
||||
while (index-- >= 0)
|
||||
enm.MoveNext();
|
||||
return enm.Current;
|
||||
}
|
||||
|
||||
private static FieldInfo GetFieldRecursive(this Type type, string name, BindingFlags bindingFlags)
|
||||
{
|
||||
var fieldInfo = type.GetField(name, bindingFlags);
|
||||
if (fieldInfo == null && type.BaseType != null)
|
||||
return type.BaseType.GetFieldRecursive(name, bindingFlags);
|
||||
return fieldInfo;
|
||||
}
|
||||
|
||||
private static PropertyInfo GetPropertyRecursive(this Type type, string name, BindingFlags bindingFlags)
|
||||
{
|
||||
var propertyInfo = type.GetProperty(name, bindingFlags);
|
||||
if (propertyInfo == null && type.BaseType != null)
|
||||
return type.BaseType.GetPropertyRecursive(name, bindingFlags);
|
||||
return propertyInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 138277cf2e7d2cd4e99c3cd7e2ecaaed
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 243052
|
||||
packageName: Serialized Dictionary
|
||||
packageVersion: 1.0.13
|
||||
assetPath: Assets/Plugins/SerializedCollections/Editor/Scripts/Utility/SCEditorUtility.cs
|
||||
uploadId: 632226
|
||||
@@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AYellowpaper.SerializedCollections.Editor
|
||||
{
|
||||
internal static class SCEnumUtility
|
||||
{
|
||||
private static Dictionary<Type, EnumCache> _cache = new Dictionary<Type, EnumCache>();
|
||||
|
||||
internal static EnumCache GetEnumCache(Type enumType)
|
||||
{
|
||||
if (_cache.TryGetValue(enumType, out var val))
|
||||
return val;
|
||||
|
||||
try
|
||||
{
|
||||
var classType = typeof(EditorGUI).Assembly.GetType("UnityEditor.EnumDataUtility");
|
||||
var methodInfo = classType.GetMethod("GetCachedEnumData", BindingFlags.Static | BindingFlags.NonPublic);
|
||||
var parameters = new object[] { enumType, true };
|
||||
var result = methodInfo.Invoke(null, parameters);
|
||||
var flagValues = (int[])result.GetType().GetField("flagValues").GetValue(result);
|
||||
var names = (string[])result.GetType().GetField("names").GetValue(result);
|
||||
var cache = new EnumCache(enumType, flagValues, names);
|
||||
_cache.Add(enumType, cache);
|
||||
return cache;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal record EnumCache
|
||||
{
|
||||
public readonly Type Type;
|
||||
public readonly bool IsFlag;
|
||||
public readonly int Length;
|
||||
public readonly int[] FlagValues;
|
||||
public readonly string[] Names;
|
||||
|
||||
private readonly Dictionary<int, string[]> _namesByValue = new Dictionary<int, string[]>();
|
||||
|
||||
public EnumCache(Type type, int[] flagValues, string[] displayNames)
|
||||
{
|
||||
Type = type;
|
||||
FlagValues = flagValues;
|
||||
Names = displayNames;
|
||||
Length = flagValues.Length;
|
||||
IsFlag = Type.IsDefined(typeof(FlagsAttribute));
|
||||
}
|
||||
|
||||
internal string[] GetNamesForValue(int value)
|
||||
{
|
||||
if (_namesByValue.TryGetValue(value, out var list))
|
||||
return list;
|
||||
|
||||
string[] array = IsFlag ? GetFlagValues(value).ToArray() : new[] { GetEnumValue(value) };
|
||||
|
||||
_namesByValue.Add(value, array);
|
||||
return array;
|
||||
}
|
||||
|
||||
private string GetEnumValue(int value)
|
||||
{
|
||||
for (int i = 0; i < Length; i++)
|
||||
{
|
||||
if (FlagValues[i] == value)
|
||||
return Names[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private IEnumerable<string> GetFlagValues(int flagValue)
|
||||
{
|
||||
if (flagValue == 0)
|
||||
{
|
||||
yield return FlagValues[0] == 0 ? Names[0] : "Nothing";
|
||||
yield break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < Length; i++)
|
||||
{
|
||||
int fv = FlagValues[i];
|
||||
if ((fv & flagValue) == fv && fv != 0)
|
||||
yield return Names[i];
|
||||
}
|
||||
|
||||
if (FlagValues[Length - 1] != -1 && flagValue == -1)
|
||||
yield return "Everything";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 76def6672c756704bac4efd5a3625113
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 243052
|
||||
packageName: Serialized Dictionary
|
||||
packageVersion: 1.0.13
|
||||
assetPath: Assets/Plugins/SerializedCollections/Editor/Scripts/Utility/SCEnumUtility.cs
|
||||
uploadId: 632226
|
||||
Reference in New Issue
Block a user