diff --git a/Editor/General/Script/Utils/Setting/EHelper.Setting.cs b/Editor/General/Script/Utils/Setting/EHelper.Setting.cs index 21309417..89c0145f 100644 --- a/Editor/General/Script/Utils/Setting/EHelper.Setting.cs +++ b/Editor/General/Script/Utils/Setting/EHelper.Setting.cs @@ -6,8 +6,8 @@ using System; using System.Collections.Generic; -using System.Reflection; using UnityEditor; +using UnityEditor.Build; using UnityEngine; namespace AIO.UEditor @@ -21,25 +21,13 @@ public static class Setting { private static ICollection GetScriptingDefineSymbolsForGroup(BuildTargetGroup buildTargetGroup) { - //获得当前平台已有的的宏定义 - var GetScriptingDefineSymbols = typeof(PlayerSettings).GetMethod("GetScriptingDefineSymbolsInternal", - BindingFlags.Static | BindingFlags.NonPublic); - string str = null; - if (GetScriptingDefineSymbols != null) - { - foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) - { - if (!assembly.GetName().Name.StartsWith("UnityEditor.Build")) continue; - var namedBuildTargetType = assembly.GetType("UnityEditor.Build.NamedBuildTarget"); - var FromBuildTargetGroupMethod = namedBuildTargetType?.GetMethod("FromBuildTargetGroup", - BindingFlags.Static | BindingFlags.Public); - if (FromBuildTargetGroupMethod is null) continue; - var symbols = FromBuildTargetGroupMethod.Invoke(null, new object[] { buildTargetGroup }); - str = GetScriptingDefineSymbols.Invoke(null, new object[] { symbols }) as string; - break; - } - } - else str = PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTargetGroup); + var str = +#if UNITY_2023_1_OR_NEWER + PlayerSettings.GetScriptingDefineSymbols( + NamedBuildTarget.FromBuildTargetGroup(buildTargetGroup)); +#else + PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTargetGroup); +#endif return string.IsNullOrEmpty(str) ? Array.Empty() : str.Split(';'); } @@ -47,35 +35,13 @@ private static ICollection GetScriptingDefineSymbolsForGroup(BuildTarget private static void SetScriptingDefineSymbolsForGroup(BuildTargetGroup buildTargetGroup, IEnumerable verify) { - //获得当前平台已有的的宏定义 - MethodInfo SetScriptingDefineSymbols = null; - foreach (var methodInfo in typeof(PlayerSettings).GetMethods(BindingFlags.Static | BindingFlags.Public)) - { - if (methodInfo.Name != "SetScriptingDefineSymbols") continue; - var parameters = methodInfo.GetParameters(); - if (parameters.Length != 2) continue; - if (parameters[0].ParameterType != typeof(string)) continue; - if (parameters[1].ParameterType != typeof(string)) continue; - SetScriptingDefineSymbols = methodInfo; - } - var str = string.Join(";", verify); - if (SetScriptingDefineSymbols != null) - { - foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) - { - if (!assembly.GetName().Name.StartsWith("UnityEditor.Build")) continue; - var namedBuildTargetType = assembly.GetType("UnityEditor.Build.NamedBuildTarget"); - var FromBuildTargetGroupMethod = namedBuildTargetType?.GetMethod("FromBuildTargetGroup", - BindingFlags.Static | BindingFlags.Public); - if (FromBuildTargetGroupMethod is null) continue; - var Symbols = FromBuildTargetGroupMethod.Invoke(null, new object[] { buildTargetGroup }); - SetScriptingDefineSymbols.Invoke(null, new object[] { Symbols, str }); - - break; - } - } - else PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, str); +#if UNITY_2023_1_OR_NEWER + PlayerSettings.SetScriptingDefineSymbols( + NamedBuildTarget.FromBuildTargetGroup(buildTargetGroup), str); +#else + PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, str); +#endif } /// @@ -84,7 +50,6 @@ private static void SetScriptingDefineSymbolsForGroup(BuildTargetGroup buildTarg public static void AddScriptingDefine(BuildTargetGroup buildTargetGroup, ICollection value) { if (value is null || value.Count == 0) return; - Debug.Log($"Plugins Data Editor : AddScriptingDefine -> {buildTargetGroup}"); var verify = new List(GetScriptingDefineSymbolsForGroup(buildTargetGroup)); foreach (var v in value) { @@ -101,7 +66,6 @@ public static void AddScriptingDefine(BuildTargetGroup buildTargetGroup, ICollec public static void DelScriptingDefine(BuildTargetGroup buildTargetGroup, ICollection value) { if (value is null || value.Count == 0) return; - Debug.Log($"Plugins Data Editor : DelScriptingDefine -> {buildTargetGroup}"); var str = GetScriptingDefineSymbolsForGroup(buildTargetGroup); if (str.Count == 0) return; IList verify = new List(str); diff --git a/Plugins/Editor/AIO.PrCourse.Unity.dll b/Plugins/Editor/AIO.PrCourse.Unity.dll index de8b6ad0..453761d5 100644 Binary files a/Plugins/Editor/AIO.PrCourse.Unity.dll and b/Plugins/Editor/AIO.PrCourse.Unity.dll differ diff --git a/Plugins/Editor/AIO.PrCourse.dll b/Plugins/Editor/AIO.PrCourse.dll index 94d285e0..16d3efdd 100644 Binary files a/Plugins/Editor/AIO.PrCourse.dll and b/Plugins/Editor/AIO.PrCourse.dll differ diff --git a/Tools~/Process/Process.Unity/Script/RainbowFolders/Borodar.RainbowCore.RList.Editor/ReorderableDrawer.cs b/Tools~/Process/Process.Unity/Script/RainbowFolders/Borodar.RainbowCore.RList.Editor/ReorderableDrawer.cs index b4ae7872..fd73f927 100644 --- a/Tools~/Process/Process.Unity/Script/RainbowFolders/Borodar.RainbowCore.RList.Editor/ReorderableDrawer.cs +++ b/Tools~/Process/Process.Unity/Script/RainbowFolders/Borodar.RainbowCore.RList.Editor/ReorderableDrawer.cs @@ -55,13 +55,10 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten public static int GetListId(SerializedProperty property) { - if (property != null) - { - int hashCode = property.serializedObject.targetObject.GetHashCode(); - int hashCode2 = property.propertyPath.GetHashCode(); - return ((hashCode << 5) + hashCode) ^ hashCode2; - } - return 0; + if (property == null) return 0; + var hashCode = property.serializedObject.targetObject.GetHashCode(); + var hashCode2 = property.propertyPath.GetHashCode(); + return ((hashCode << 5) + hashCode) ^ hashCode2; } public static ReorderableList GetList(SerializedProperty property, string arrayPropertyName) diff --git a/Tools~/Process/Process.Unity/Script/RainbowFolders/Borodar.RainbowCore.RList.Editor/ReorderableList.cs b/Tools~/Process/Process.Unity/Script/RainbowFolders/Borodar.RainbowCore.RList.Editor/ReorderableList.cs index e9f3ef42..ac3c9fd8 100644 --- a/Tools~/Process/Process.Unity/Script/RainbowFolders/Borodar.RainbowCore.RList.Editor/ReorderableList.cs +++ b/Tools~/Process/Process.Unity/Script/RainbowFolders/Borodar.RainbowCore.RList.Editor/ReorderableList.cs @@ -5,2356 +5,2494 @@ using System.Reflection; using UnityEditor; using UnityEngine; +using Object = UnityEngine.Object; namespace AIO.RainbowCore.RList.Editor { - internal class ReorderableList - { - public enum ElementDisplayType - { - Auto, - Expandable, - SingleLine - } + internal class ReorderableList + { + public enum ElementDisplayType + { + Auto, + Expandable, + SingleLine + } - public delegate void DrawHeaderDelegate(Rect rect, GUIContent label); + public delegate void DrawHeaderDelegate(Rect rect, GUIContent label); - public delegate void DrawFooterDelegate(Rect rect); + public delegate void DrawFooterDelegate(Rect rect); - public delegate void DrawElementDelegate(Rect rect, SerializedProperty element, GUIContent label, bool selected, bool focused); + public delegate void DrawElementDelegate(Rect rect, SerializedProperty element, GUIContent label, bool selected, + bool focused); - public delegate void ActionDelegate(ReorderableList list); + public delegate void ActionDelegate(ReorderableList list); - public delegate bool ActionBoolDelegate(ReorderableList list); + public delegate bool ActionBoolDelegate(ReorderableList list); - public delegate void AddDropdownDelegate(Rect buttonRect, ReorderableList list); + public delegate void AddDropdownDelegate(Rect buttonRect, ReorderableList list); - public delegate UnityEngine.Object DragDropReferenceDelegate(UnityEngine.Object[] references, ReorderableList list); + public delegate Object DragDropReferenceDelegate(Object[] references, + ReorderableList list); - public delegate void DragDropAppendDelegate(UnityEngine.Object reference, ReorderableList list); + public delegate void DragDropAppendDelegate(Object reference, ReorderableList list); - public delegate float GetElementHeightDelegate(SerializedProperty element); + public delegate float GetElementHeightDelegate(SerializedProperty element); - public delegate float GetElementsHeightDelegate(ReorderableList list); + public delegate float GetElementsHeightDelegate(ReorderableList list); - public delegate string GetElementNameDelegate(SerializedProperty element); + public delegate string GetElementNameDelegate(SerializedProperty element); - public delegate GUIContent GetElementLabelDelegate(SerializedProperty element); + public delegate GUIContent GetElementLabelDelegate(SerializedProperty element); - public delegate void SurrogateCallback(SerializedProperty element, UnityEngine.Object objectReference, ReorderableList list); + public delegate void SurrogateCallback(SerializedProperty element, Object objectReference, + ReorderableList list); - private static class Style - { - internal const string PAGE_INFO_FORMAT = "{0} / {1}"; + private static class Style + { + internal const string PAGE_INFO_FORMAT = "{0} / {1}"; - internal static GUIContent iconToolbarPlus; + internal static GUIContent iconToolbarPlus; - internal static GUIContent iconToolbarPlusMore; + internal static GUIContent iconToolbarPlusMore; - internal static GUIContent iconToolbarMinus; + internal static GUIContent iconToolbarMinus; - internal static GUIContent iconPagePrev; + internal static GUIContent iconPagePrev; - internal static GUIContent iconPageNext; + internal static GUIContent iconPageNext; - internal static GUIContent iconPagePopup; + internal static GUIContent iconPagePopup; - internal static GUIStyle paginationText; + internal static GUIStyle paginationText; - internal static GUIStyle pageSizeTextField; + internal static GUIStyle pageSizeTextField; - internal static GUIStyle draggingHandle; + internal static GUIStyle draggingHandle; - internal static GUIStyle headerBackground; + internal static GUIStyle headerBackground; - internal static GUIStyle footerBackground; + internal static GUIStyle footerBackground; - internal static GUIStyle paginationHeader; + internal static GUIStyle paginationHeader; - internal static GUIStyle boxBackground; + internal static GUIStyle boxBackground; + + internal static GUIStyle preButton; + + internal static GUIStyle elementBackground; + + internal static GUIStyle verticalLabel; + + internal static GUIContent expandButton; + + internal static GUIContent collapseButton; + + internal static GUIContent sortAscending; + + internal static GUIContent sortDescending; + + internal static GUIContent listIcon; + + private static string GetIconName(string name) + { + if (!iconNames.ContainsKey(name)) return "d_console.erroricon"; + int.TryParse(Application.unityVersion.Split('.')[0], out var ver); + return iconNames[name].ContainsKey(ver) ? iconNames[name][ver] : "d_console.erroricon"; + } + + static Style() + { + iconToolbarPlus = EditorGUIUtility.TrIconContent("Toolbar Plus", "| Add to list"); + iconToolbarPlusMore = EditorGUIUtility.TrIconContent("Toolbar Plus More", "| Choose to add to list"); + iconToolbarMinus = EditorGUIUtility.TrIconContent("Toolbar Minus", "| Remove selection from list"); + iconPagePrev = EditorGUIUtility.TrIconContent("Animation.PrevKey", "| Previous page"); + iconPageNext = EditorGUIUtility.TrIconContent("Animation.NextKey", "| Next page"); + iconPagePopup = EditorGUIUtility.TrIconContent("UnityEditor.HierarchyWindow", "| Select page"); + paginationText = new GUIStyle + { + margin = new RectOffset(2, 2, 0, 0), + fontSize = EditorStyles.miniTextField.fontSize, + font = EditorStyles.miniFont, + normal = + { + textColor = EditorStyles.miniTextField.normal.textColor + }, + alignment = TextAnchor.UpperLeft, + clipping = TextClipping.Clip + }; + pageSizeTextField = new GUIStyle("RL Footer") + { + alignment = TextAnchor.MiddleLeft, + clipping = TextClipping.Clip, + fixedHeight = 0f, + padding = new RectOffset(3, 0, 0, 0), + overflow = new RectOffset(0, 0, -2, -3), + contentOffset = new Vector2(0f, -1f), + font = EditorStyles.miniFont, + fontSize = EditorStyles.miniTextField.fontSize, + fontStyle = FontStyle.Normal, + wordWrap = false, + normal = + { + textColor = EditorStyles.miniTextField.normal.textColor + } + }; + draggingHandle = new GUIStyle("RL DragHandle"); + headerBackground = new GUIStyle("RL Header"); + footerBackground = new GUIStyle("RL Footer"); + paginationHeader = new GUIStyle("RL Element") + { + border = new RectOffset(2, 3, 2, 3) + }; + elementBackground = new GUIStyle("RL Element") + { + border = new RectOffset(2, 3, 2, 3) + }; + verticalLabel = new GUIStyle(EditorStyles.label) + { + alignment = TextAnchor.UpperLeft, + contentOffset = new Vector2(10f, 3f) + }; + boxBackground = new GUIStyle("RL Background") + { + border = new RectOffset(6, 3, 3, 6) + }; + preButton = new GUIStyle("RL FooterButton"); + + expandButton = EditorGUIUtility.TrIconContent(GetIconName(nameof(expandButton))); + expandButton.tooltip = "Expand All Elements"; + + collapseButton = EditorGUIUtility.TrIconContent(GetIconName(nameof(collapseButton))); + collapseButton.tooltip = "Collapse All Elements"; + + sortAscending = EditorGUIUtility.TrIconContent("align_vertically_bottom"); + sortAscending.tooltip = "Sort Ascending"; + sortDescending = EditorGUIUtility.TrIconContent("align_vertically_top"); + sortDescending.tooltip = "Sort Descending"; + listIcon = EditorGUIUtility.TrIconContent("align_horizontally_right"); + } + } + + private static readonly Dictionary> iconNames = + new Dictionary> + { + { + "expandButton", new Dictionary + { + { 2023, "d_winbtn_mac_inact" }, + { 2020, "d_winbtn_win_max" }, + { 0, "winbtn_win_max" } + } + }, + { + "collapseButton", new Dictionary + { + { 2023, "d_winbtn_win_min" }, + { 2020, "d_winbtn_win_restore" }, + { 0, "winbtn_win_max" } + } + }, + }; + + private struct DragList + { + private DragElement[] elements; + + internal int StartIndex { get; private set; } + + internal int Length { get; private set; } + + internal DragElement[] Elements + { + get => elements; + set => elements = value; + } + + internal DragElement this[int index] + { + get => elements[index]; + set => elements[index] = value; + } + + internal DragList(int length) + { + Length = length; + StartIndex = 0; + elements = new DragElement[length]; + } + + internal void Resize(int start, int length) + { + StartIndex = start; + Length = length; + if (elements.Length != length) + { + Array.Resize(ref elements, length); + } + } + + internal void SortByIndex() + { + Array.Sort(elements, delegate(DragElement a, DragElement b) + { + if (b.selected) return !a.selected ? 1 : a.startIndex.CompareTo(b.startIndex); + return a.selected ? -1 : a.startIndex.CompareTo(b.startIndex); + }); + } + + internal void RecordState() + { + for (var i = 0; i < Length; i++) + { + elements[i].RecordState(); + } + } + + internal void RestoreState(SerializedProperty list) + { + for (var i = 0; i < Length; i++) + { + elements[i].RestoreState(list.GetArrayElementAtIndex(i + StartIndex)); + } + } + + internal void SortByPosition() + { + Array.Sort(elements, (a, b) => a.desiredRect.center.y.CompareTo(b.desiredRect.center.y)); + } + + internal int GetIndexFromSelection(int index) + { + return Array.FindIndex(elements, t => t.startIndex == index); + } + } + + private struct DragElement + { + internal SerializedProperty property; + + internal int startIndex; + + internal float dragOffset; + + internal bool selected; + + internal Rect rect; + + internal Rect desiredRect; + + private bool isExpanded; + + private Dictionary states; + + internal bool Overlaps(Rect value, int index, int direction) + { + if (direction < 0 && index < startIndex) + { + return desiredRect.yMin < value.center.y; + } + + if (direction > 0 && index > startIndex) + { + return desiredRect.yMax > value.center.y; + } + + return false; + } + + internal void RecordState() + { + states = new Dictionary(); + isExpanded = property.isExpanded; + Iterate(this, property, + delegate(DragElement e, SerializedProperty p, int index) { e.states[index] = p.isExpanded; }); + } + + internal void RestoreState(SerializedProperty value) + { + value.isExpanded = isExpanded; + Iterate(this, value, + delegate(DragElement e, SerializedProperty p, int index) { p.isExpanded = e.states[index]; }); + } + + private static void Iterate(DragElement element, SerializedProperty property, + Action action) + { + var serializedProperty = property.Copy(); + var endProperty = serializedProperty.GetEndProperty(); + var num = 0; + while (serializedProperty.NextVisible(enterChildren: true) && + !SerializedProperty.EqualContents(serializedProperty, endProperty)) + { + if (!serializedProperty.hasVisibleChildren) continue; + action(element, serializedProperty, num); + num++; + } + } + } + + private class SlideGroup + { + private Dictionary animIDs; + + public SlideGroup() + { + animIDs = new Dictionary(); + } + + public Rect GetRect(int id, Rect r, float easing) + { + if (Event.current.type != EventType.Repaint) + { + return r; + } + + if (!animIDs.ContainsKey(id)) + { + animIDs.Add(id, r); + return r; + } + + var rect = animIDs[id]; + if (rect.y == r.y) return r; + + var num = r.y - rect.y; + var num2 = Mathf.Abs(num); + if (num2 > rect.height * 2f) + { + r.y = num > 0f ? r.y - rect.height : r.y + rect.height; + } + else if (num2 > 0.5) + { + r.y = Mathf.Lerp(rect.y, r.y, easing); + } + + animIDs[id] = r; + HandleUtility.Repaint(); + + return r; + } + + public Rect SetRect(int id, Rect rect) + { + if (animIDs.ContainsKey(id)) + { + animIDs[id] = rect; + } + else + { + animIDs.Add(id, rect); + } + + return rect; + } + } + + private struct Pagination + { + internal bool enabled; + + internal int pageSize; + + internal int page; + + internal bool usePagination + { + get + { + if (enabled) + { + return pageSize > 0; + } + + return false; + } + } + + internal int GetVisibleLength(int total) + { + if (GetVisibleRange(total, out var start, out var end)) + { + return end - start; + } + + return total; + } + + internal int GetPageForIndex(int index) + { + return !usePagination ? 0 : Mathf.FloorToInt(index / (float)pageSize); + } + + internal int GetPageCount(int total) + { + return !usePagination ? 1 : Mathf.CeilToInt(total / (float)pageSize); + } + + internal bool GetVisibleRange(int total, out int start, out int end) + { + if (usePagination) + { + var num = pageSize; + start = Mathf.Clamp(page * num, 0, total - 1); + end = Mathf.Min(start + num, total); + return true; + } + + start = 0; + end = total; + return false; + } + } + + private class ListSelection : IEnumerable + { + private List indexes; + + internal int? firstSelected; + + public int First + { + get + { + if (indexes.Count <= 0) + { + return -1; + } + + return indexes[0]; + } + } + + public int Last + { + get + { + if (indexes.Count <= 0) + { + return -1; + } + + return indexes[indexes.Count - 1]; + } + } + + public int Length => indexes.Count; + + public int this[int index] + { + get => indexes[index]; + set + { + var num = indexes[index]; + indexes[index] = value; + if (num == firstSelected) + { + firstSelected = value; + } + } + } + + public ListSelection() + { + indexes = new List(); + } + + public ListSelection(IEnumerable indexes) + { + this.indexes = new List(indexes); + } + + public bool Contains(int index) + { + return indexes.Contains(index); + } + + public void Clear() + { + indexes.Clear(); + firstSelected = null; + } + + public void SelectWhenNoAction(int index, Event evt) + { + if (!EditorGUI.actionKey && !evt.shift) + { + Select(index); + } + } + + public void Select(int index) + { + indexes.Clear(); + indexes.Add(index); + firstSelected = index; + } + + public void Remove(int index) + { + if (indexes.Contains(index)) + { + indexes.Remove(index); + } + } + + public void AppendWithAction(int index, Event evt) + { + if (EditorGUI.actionKey) + { + if (Contains(index)) + { + Remove(index); + return; + } + + Append(index); + firstSelected = index; + } + else if (evt.shift && indexes.Count > 0 && firstSelected.HasValue) + { + indexes.Clear(); + AppendRange(firstSelected.Value, index); + } + else if (!Contains(index)) + { + Select(index); + } + } + + public void Sort() + { + if (indexes.Count > 0) + { + indexes.Sort(); + } + } + + public void Sort(Comparison comparison) + { + if (indexes.Count > 0) + { + indexes.Sort(comparison); + } + } + + public int[] ToArray() + { + return indexes.ToArray(); + } + + public ListSelection Clone() + { + return new ListSelection(ToArray()) + { + firstSelected = firstSelected + }; + } + + internal void Trim(int min, int max) + { + var num = indexes.Count; + while (--num > -1) + { + var num2 = indexes[num]; + if (num2 >= min && num2 < max) continue; + if (num2 == firstSelected && num > 0) + firstSelected = indexes[num - 1]; + indexes.RemoveAt(num); + } + } + + internal bool CanRevert(SerializedProperty list) + { + if (list.serializedObject.targetObjects.Length != 1) return false; + for (var i = 0; i < Length; i++) + { + if (list.GetArrayElementAtIndex(this[i]).isInstantiatedPrefab) + { + return true; + } + } + + return false; + } + + internal void RevertValues(object userData) + { + if (!(userData is SerializedProperty serializedProperty)) return; + for (var i = 0; i < Length; i++) + { + var arrayElementAtIndex = serializedProperty.GetArrayElementAtIndex(this[i]); + if (arrayElementAtIndex.isInstantiatedPrefab) + { + arrayElementAtIndex.prefabOverride = false; + } + } + + serializedProperty.serializedObject.ApplyModifiedProperties(); + serializedProperty.serializedObject.Update(); + HandleUtility.Repaint(); + } + + internal void Duplicate(SerializedProperty list) + { + var num = 0; + for (var i = 0; i < Length; i++) + { + this[i] += num; + list.GetArrayElementAtIndex(this[i]).DuplicateCommand(); + list.serializedObject.ApplyModifiedProperties(); + list.serializedObject.Update(); + num++; + } + + HandleUtility.Repaint(); + } + + internal void Delete(SerializedProperty list) + { + Sort(); + var num = Length; + while (--num > -1) + { + list.GetArrayElementAtIndex(this[num]).DeleteCommand(); + } + + Clear(); + list.serializedObject.ApplyModifiedProperties(); + list.serializedObject.Update(); + HandleUtility.Repaint(); + } + + private void Append(int index) + { + if (index >= 0 && !indexes.Contains(index)) + { + indexes.Add(index); + } + } + + private void AppendRange(int from, int to) + { + int num = (int)Mathf.Sign(to - from); + if (num != 0) + { + for (int i = from; i != to; i += num) + { + Append(i); + } + } + + Append(to); + } + + public IEnumerator GetEnumerator() + { + return ((IEnumerable)indexes).GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return ((IEnumerable)indexes).GetEnumerator(); + } + } + + private static class ListSort + { + private delegate int SortComparision(SerializedProperty p1, SerializedProperty p2); + + internal static void SortOnProperty(SerializedProperty list, int length, bool descending, + string propertyName) + { + BubbleSort(list, length, delegate(SerializedProperty p1, SerializedProperty p2) + { + SerializedProperty serializedProperty = p1.FindPropertyRelative(propertyName); + SerializedProperty serializedProperty2 = p2.FindPropertyRelative(propertyName); + if (serializedProperty != null && serializedProperty2 != null && + serializedProperty.propertyType == serializedProperty2.propertyType) + { + int num = Compare(serializedProperty, serializedProperty2, descending, + serializedProperty.propertyType); + if (!descending) + { + return num; + } + + return -num; + } + + return 0; + }); + } + + internal static void SortOnType(SerializedProperty list, int length, bool descending, + SerializedPropertyType type) + { + BubbleSort(list, length, delegate(SerializedProperty p1, SerializedProperty p2) + { + int num = Compare(p1, p2, descending, type); + return (!descending) ? num : (-num); + }); + } + + private static void BubbleSort(SerializedProperty list, int length, SortComparision comparision) + { + for (int i = 0; i < length; i++) + { + SerializedProperty arrayElementAtIndex = list.GetArrayElementAtIndex(i); + for (int j = i + 1; j < length; j++) + { + SerializedProperty arrayElementAtIndex2 = list.GetArrayElementAtIndex(j); + if (comparision(arrayElementAtIndex, arrayElementAtIndex2) > 0) + { + list.MoveArrayElement(j, i); + } + } + } + } + + private static int Compare(SerializedProperty p1, SerializedProperty p2, bool descending, + SerializedPropertyType type) + { + if (p1 == null || p2 == null) + { + return 0; + } + + switch (type) + { + case SerializedPropertyType.Boolean: + return p1.boolValue.CompareTo(p2.boolValue); + case SerializedPropertyType.Integer: + case SerializedPropertyType.LayerMask: + case SerializedPropertyType.Enum: + case SerializedPropertyType.Character: + return p1.longValue.CompareTo(p2.longValue); + case SerializedPropertyType.Color: + return p1.colorValue.grayscale.CompareTo(p2.colorValue.grayscale); + case SerializedPropertyType.ExposedReference: + return CompareObjects(p1.exposedReferenceValue, p2.exposedReferenceValue, descending); + case SerializedPropertyType.Float: + return p1.doubleValue.CompareTo(p2.doubleValue); + case SerializedPropertyType.ObjectReference: + return CompareObjects(p1.objectReferenceValue, p2.objectReferenceValue, descending); + case SerializedPropertyType.String: + return p1.stringValue.CompareTo(p2.stringValue); + default: + return 0; + } + } + + private static int CompareObjects(Object obj1, Object obj2, bool descending) + { + if ((bool)obj1 && (bool)obj2) + { + return obj1.name.CompareTo(obj2.name); + } + + if ((bool)obj1) + { + if (!descending) + { + return -1; + } + + return 1; + } + + if (!descending) + { + return 1; + } + + return -1; + } + } + + public struct Surrogate + { + public Type type; + + public bool exactType; + + public SurrogateCallback callback; + + internal bool enabled; + + public bool HasType + { + get + { + if (enabled) + { + return type != null; + } + + return false; + } + } + + public Surrogate(Type type) + : this(type, null) + { + } + + public Surrogate(Type type, SurrogateCallback callback) + { + this.type = type; + this.callback = callback; + enabled = true; + exactType = false; + } + + public void Invoke(SerializedProperty element, Object objectReference, ReorderableList list) + { + if (element != null && callback != null) + { + callback(element, objectReference, list); + } + } + } + + private class InvalidListException : InvalidOperationException + { + public InvalidListException() + : base("ReorderableList serializedProperty must be an array") + { + } + } + + private class MissingListException : ArgumentNullException + { + public MissingListException() : base($"ReorderableList serializedProperty is null") + { + } + } - internal static GUIStyle preButton; + private static class Internals + { + private static MethodInfo dragDropValidation; - internal static GUIStyle elementBackground; + private static object[] dragDropValidationParams; - internal static GUIStyle verticalLabel; + private static MethodInfo appendDragDrop; - internal static GUIContent expandButton; + private static object[] appendDragDropParams; - internal static GUIContent collapseButton; + static Internals() + { + dragDropValidation = Type.GetType("UnityEditor.EditorGUI, UnityEditor")? + .GetMethod("ValidateObjectFieldAssignment", BindingFlags.Static | BindingFlags.NonPublic); + appendDragDrop = typeof(SerializedProperty).GetMethod("AppendFoldoutPPtrValue", + BindingFlags.Instance | BindingFlags.NonPublic); + } - internal static GUIContent sortAscending; + internal static Object ValidateObjectDragAndDrop(Object[] references, + SerializedProperty property, Type type, bool exactType) + { + dragDropValidationParams = GetParams(ref dragDropValidationParams, 3); + dragDropValidationParams[0] = references; + dragDropValidationParams[1] = type; + dragDropValidationParams[2] = property; + return dragDropValidation.Invoke(null, dragDropValidationParams) as Object; + } - internal static GUIContent sortDescending; + internal static void AppendDragAndDropValue(Object obj, SerializedProperty list) + { + appendDragDropParams = GetParams(ref appendDragDropParams, 1); + appendDragDropParams[0] = obj; + appendDragDrop.Invoke(list, appendDragDropParams); + } - internal static GUIContent listIcon; + private static object[] GetParams(ref object[] parameters, int count) + { + if (parameters == null) + { + parameters = new object[count]; + } - static Style() - { - iconToolbarPlus = EditorGUIUtility.IconContent("Toolbar Plus", "| Add to list"); - iconToolbarPlusMore = EditorGUIUtility.IconContent("Toolbar Plus More", "| Choose to add to list"); - iconToolbarMinus = EditorGUIUtility.IconContent("Toolbar Minus", "| Remove selection from list"); - iconPagePrev = EditorGUIUtility.IconContent("Animation.PrevKey", "| Previous page"); - iconPageNext = EditorGUIUtility.IconContent("Animation.NextKey", "| Next page"); - iconPagePopup = EditorGUIUtility.IconContent("UnityEditor.HierarchyWindow", "| Select page"); - paginationText = new GUIStyle(); - paginationText.margin = new RectOffset(2, 2, 0, 0); - paginationText.fontSize = EditorStyles.miniTextField.fontSize; - paginationText.font = EditorStyles.miniFont; - paginationText.normal.textColor = EditorStyles.miniTextField.normal.textColor; - paginationText.alignment = TextAnchor.UpperLeft; - paginationText.clipping = TextClipping.Clip; - pageSizeTextField = new GUIStyle("RL Footer"); - pageSizeTextField.alignment = TextAnchor.MiddleLeft; - pageSizeTextField.clipping = TextClipping.Clip; - pageSizeTextField.fixedHeight = 0f; - pageSizeTextField.padding = new RectOffset(3, 0, 0, 0); - pageSizeTextField.overflow = new RectOffset(0, 0, -2, -3); - pageSizeTextField.contentOffset = new Vector2(0f, -1f); - pageSizeTextField.font = EditorStyles.miniFont; - pageSizeTextField.fontSize = EditorStyles.miniTextField.fontSize; - pageSizeTextField.fontStyle = FontStyle.Normal; - pageSizeTextField.wordWrap = false; - pageSizeTextField.normal.textColor = EditorStyles.miniTextField.normal.textColor; - draggingHandle = new GUIStyle("RL DragHandle"); - headerBackground = new GUIStyle("RL Header"); - footerBackground = new GUIStyle("RL Footer"); - paginationHeader = new GUIStyle("RL Element"); - paginationHeader.border = new RectOffset(2, 3, 2, 3); - elementBackground = new GUIStyle("RL Element"); - elementBackground.border = new RectOffset(2, 3, 2, 3); - verticalLabel = new GUIStyle(EditorStyles.label); - verticalLabel.alignment = TextAnchor.UpperLeft; - verticalLabel.contentOffset = new Vector2(10f, 3f); - boxBackground = new GUIStyle("RL Background"); - boxBackground.border = new RectOffset(6, 3, 3, 6); - preButton = new GUIStyle("RL FooterButton"); - expandButton = EditorGUIUtility.IconContent("winbtn_win_max"); - expandButton.tooltip = "Expand All Elements"; - collapseButton = EditorGUIUtility.IconContent("winbtn_win_min"); - collapseButton.tooltip = "Collapse All Elements"; - sortAscending = EditorGUIUtility.IconContent("align_vertically_bottom"); - sortAscending.tooltip = "Sort Ascending"; - sortDescending = EditorGUIUtility.IconContent("align_vertically_top"); - sortDescending.tooltip = "Sort Descending"; - listIcon = EditorGUIUtility.IconContent("align_horizontally_right"); - } - } - - private struct DragList - { - private int startIndex; - - private DragElement[] elements; - - private int length; - - internal int StartIndex => startIndex; - - internal int Length => length; - - internal DragElement[] Elements - { - get - { - return elements; - } - set - { - elements = value; - } - } - - internal DragElement this[int index] - { - get - { - return elements[index]; - } - set - { - elements[index] = value; - } - } - - internal DragList(int length) - { - this.length = length; - startIndex = 0; - elements = new DragElement[length]; - } - - internal void Resize(int start, int length) - { - startIndex = start; - this.length = length; - if (elements.Length != length) - { - Array.Resize(ref elements, length); - } - } - - internal void SortByIndex() - { - Array.Sort(elements, delegate(DragElement a, DragElement b) - { - if (b.selected) - { - if (!a.selected) - { - return 1; - } - return a.startIndex.CompareTo(b.startIndex); - } - return a.selected ? ((!b.selected) ? (-1) : b.startIndex.CompareTo(a.startIndex)) : a.startIndex.CompareTo(b.startIndex); - }); - } - - internal void RecordState() - { - for (int i = 0; i < length; i++) - { - elements[i].RecordState(); - } - } - - internal void RestoreState(SerializedProperty list) - { - for (int i = 0; i < length; i++) - { - elements[i].RestoreState(list.GetArrayElementAtIndex(i + startIndex)); - } - } - - internal void SortByPosition() - { - Array.Sort(elements, (DragElement a, DragElement b) => a.desiredRect.center.y.CompareTo(b.desiredRect.center.y)); - } - - internal int GetIndexFromSelection(int index) - { - return Array.FindIndex(elements, (DragElement t) => t.startIndex == index); - } - } - - private struct DragElement - { - internal SerializedProperty property; - - internal int startIndex; - - internal float dragOffset; - - internal bool selected; - - internal Rect rect; - - internal Rect desiredRect; - - private bool isExpanded; - - private Dictionary states; - - internal bool Overlaps(Rect value, int index, int direction) - { - if (direction < 0 && index < startIndex) - { - return desiredRect.yMin < value.center.y; - } - if (direction > 0 && index > startIndex) - { - return desiredRect.yMax > value.center.y; - } - return false; - } - - internal void RecordState() - { - states = new Dictionary(); - isExpanded = property.isExpanded; - Iterate(this, property, delegate(DragElement e, SerializedProperty p, int index) - { - e.states[index] = p.isExpanded; - }); - } - - internal void RestoreState(SerializedProperty property) - { - property.isExpanded = isExpanded; - Iterate(this, property, delegate(DragElement e, SerializedProperty p, int index) - { - p.isExpanded = e.states[index]; - }); - } - - private static void Iterate(DragElement element, SerializedProperty property, Action action) - { - SerializedProperty serializedProperty = property.Copy(); - SerializedProperty endProperty = serializedProperty.GetEndProperty(); - int num = 0; - while (serializedProperty.NextVisible(enterChildren: true) && !SerializedProperty.EqualContents(serializedProperty, endProperty)) - { - if (serializedProperty.hasVisibleChildren) - { - action(element, serializedProperty, num); - num++; - } - } - } - } - - private class SlideGroup - { - private Dictionary animIDs; - - public SlideGroup() - { - animIDs = new Dictionary(); - } - - public Rect GetRect(int id, Rect r, float easing) - { - if (Event.current.type != EventType.Repaint) - { - return r; - } - if (!animIDs.ContainsKey(id)) - { - animIDs.Add(id, r); - return r; - } - Rect rect = animIDs[id]; - if (rect.y != r.y) - { - float num = r.y - rect.y; - float num2 = Mathf.Abs(num); - if (num2 > rect.height * 2f) - { - r.y = ((num > 0f) ? (r.y - rect.height) : (r.y + rect.height)); - } - else if ((double)num2 > 0.5) - { - r.y = Mathf.Lerp(rect.y, r.y, easing); - } - animIDs[id] = r; - HandleUtility.Repaint(); - } - return r; - } - - public Rect SetRect(int id, Rect rect) - { - if (animIDs.ContainsKey(id)) - { - animIDs[id] = rect; - } - else - { - animIDs.Add(id, rect); - } - return rect; - } - } - - private struct Pagination - { - internal bool enabled; - - internal int pageSize; - - internal int page; - - internal bool usePagination - { - get - { - if (enabled) - { - return pageSize > 0; - } - return false; - } - } - - internal int GetVisibleLength(int total) - { - if (GetVisibleRange(total, out var start, out var end)) - { - return end - start; - } - return total; - } - - internal int GetPageForIndex(int index) - { - if (!usePagination) - { - return 0; - } - return Mathf.FloorToInt((float)index / (float)pageSize); - } - - internal int GetPageCount(int total) - { - if (!usePagination) - { - return 1; - } - return Mathf.CeilToInt((float)total / (float)pageSize); - } - - internal bool GetVisibleRange(int total, out int start, out int end) - { - if (usePagination) - { - int num = pageSize; - start = Mathf.Clamp(page * num, 0, total - 1); - end = Mathf.Min(start + num, total); - return true; - } - start = 0; - end = total; - return false; - } - } - - private class ListSelection : IEnumerable, IEnumerable - { - private List indexes; - - internal int? firstSelected; - - public int First - { - get - { - if (indexes.Count <= 0) - { - return -1; - } - return indexes[0]; - } - } - - public int Last - { - get - { - if (indexes.Count <= 0) - { - return -1; - } - return indexes[indexes.Count - 1]; - } - } - - public int Length => indexes.Count; - - public int this[int index] - { - get - { - return indexes[index]; - } - set - { - int num = indexes[index]; - indexes[index] = value; - if (num == firstSelected) - { - firstSelected = value; - } - } - } - - public ListSelection() - { - indexes = new List(); - } - - public ListSelection(int[] indexes) - { - this.indexes = new List(indexes); - } - - public bool Contains(int index) - { - return indexes.Contains(index); - } - - public void Clear() - { - indexes.Clear(); - firstSelected = null; - } - - public void SelectWhenNoAction(int index, Event evt) - { - if (!EditorGUI.actionKey && !evt.shift) - { - Select(index); - } - } - - public void Select(int index) - { - indexes.Clear(); - indexes.Add(index); - firstSelected = index; - } - - public void Remove(int index) - { - if (indexes.Contains(index)) - { - indexes.Remove(index); - } - } - - public void AppendWithAction(int index, Event evt) - { - if (EditorGUI.actionKey) - { - if (Contains(index)) - { - Remove(index); - return; - } - Append(index); - firstSelected = index; - } - else if (evt.shift && indexes.Count > 0 && firstSelected.HasValue) - { - indexes.Clear(); - AppendRange(firstSelected.Value, index); - } - else if (!Contains(index)) - { - Select(index); - } - } - - public void Sort() - { - if (indexes.Count > 0) - { - indexes.Sort(); - } - } - - public void Sort(Comparison comparison) - { - if (indexes.Count > 0) - { - indexes.Sort(comparison); - } - } - - public int[] ToArray() - { - return indexes.ToArray(); - } - - public ListSelection Clone() - { - return new ListSelection(ToArray()) - { - firstSelected = firstSelected - }; - } - - internal void Trim(int min, int max) - { - int num = indexes.Count; - while (--num > -1) - { - int num2 = indexes[num]; - if (num2 < min || num2 >= max) - { - if (num2 == firstSelected && num > 0) - { - firstSelected = indexes[num - 1]; - } - indexes.RemoveAt(num); - } - } - } - - internal bool CanRevert(SerializedProperty list) - { - if (list.serializedObject.targetObjects.Length == 1) - { - for (int i = 0; i < Length; i++) - { - if (list.GetArrayElementAtIndex(this[i]).isInstantiatedPrefab) - { - return true; - } - } - } - return false; - } - - internal void RevertValues(object userData) - { - SerializedProperty serializedProperty = userData as SerializedProperty; - for (int i = 0; i < Length; i++) - { - SerializedProperty arrayElementAtIndex = serializedProperty.GetArrayElementAtIndex(this[i]); - if (arrayElementAtIndex.isInstantiatedPrefab) - { - arrayElementAtIndex.prefabOverride = false; - } - } - serializedProperty.serializedObject.ApplyModifiedProperties(); - serializedProperty.serializedObject.Update(); - HandleUtility.Repaint(); - } - - internal void Duplicate(SerializedProperty list) - { - int num = 0; - for (int i = 0; i < Length; i++) - { - this[i] += num; - list.GetArrayElementAtIndex(this[i]).DuplicateCommand(); - list.serializedObject.ApplyModifiedProperties(); - list.serializedObject.Update(); - num++; - } - HandleUtility.Repaint(); - } - - internal void Delete(SerializedProperty list) - { - Sort(); - int num = Length; - while (--num > -1) - { - list.GetArrayElementAtIndex(this[num]).DeleteCommand(); - } - Clear(); - list.serializedObject.ApplyModifiedProperties(); - list.serializedObject.Update(); - HandleUtility.Repaint(); - } - - private void Append(int index) - { - if (index >= 0 && !indexes.Contains(index)) - { - indexes.Add(index); - } - } - - private void AppendRange(int from, int to) - { - int num = (int)Mathf.Sign(to - from); - if (num != 0) - { - for (int i = from; i != to; i += num) - { - Append(i); - } - } - Append(to); - } - - public IEnumerator GetEnumerator() - { - return ((IEnumerable)indexes).GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return ((IEnumerable)indexes).GetEnumerator(); - } - } - - private static class ListSort - { - private delegate int SortComparision(SerializedProperty p1, SerializedProperty p2); - - internal static void SortOnProperty(SerializedProperty list, int length, bool descending, string propertyName) - { - BubbleSort(list, length, delegate(SerializedProperty p1, SerializedProperty p2) - { - SerializedProperty serializedProperty = p1.FindPropertyRelative(propertyName); - SerializedProperty serializedProperty2 = p2.FindPropertyRelative(propertyName); - if (serializedProperty != null && serializedProperty2 != null && serializedProperty.propertyType == serializedProperty2.propertyType) - { - int num = Compare(serializedProperty, serializedProperty2, descending, serializedProperty.propertyType); - if (!descending) - { - return num; - } - return -num; - } - return 0; - }); - } - - internal static void SortOnType(SerializedProperty list, int length, bool descending, SerializedPropertyType type) - { - BubbleSort(list, length, delegate(SerializedProperty p1, SerializedProperty p2) - { - int num = Compare(p1, p2, descending, type); - return (!descending) ? num : (-num); - }); - } - - private static void BubbleSort(SerializedProperty list, int length, SortComparision comparision) - { - for (int i = 0; i < length; i++) - { - SerializedProperty arrayElementAtIndex = list.GetArrayElementAtIndex(i); - for (int j = i + 1; j < length; j++) - { - SerializedProperty arrayElementAtIndex2 = list.GetArrayElementAtIndex(j); - if (comparision(arrayElementAtIndex, arrayElementAtIndex2) > 0) - { - list.MoveArrayElement(j, i); - } - } - } - } - - private static int Compare(SerializedProperty p1, SerializedProperty p2, bool descending, SerializedPropertyType type) - { - if (p1 == null || p2 == null) - { - return 0; - } - switch (type) - { - case SerializedPropertyType.Boolean: - return p1.boolValue.CompareTo(p2.boolValue); - case SerializedPropertyType.Integer: - case SerializedPropertyType.LayerMask: - case SerializedPropertyType.Enum: - case SerializedPropertyType.Character: - return p1.longValue.CompareTo(p2.longValue); - case SerializedPropertyType.Color: - return p1.colorValue.grayscale.CompareTo(p2.colorValue.grayscale); - case SerializedPropertyType.ExposedReference: - return CompareObjects(p1.exposedReferenceValue, p2.exposedReferenceValue, descending); - case SerializedPropertyType.Float: - return p1.doubleValue.CompareTo(p2.doubleValue); - case SerializedPropertyType.ObjectReference: - return CompareObjects(p1.objectReferenceValue, p2.objectReferenceValue, descending); - case SerializedPropertyType.String: - return p1.stringValue.CompareTo(p2.stringValue); - default: - return 0; - } - } - - private static int CompareObjects(UnityEngine.Object obj1, UnityEngine.Object obj2, bool descending) - { - if ((bool)obj1 && (bool)obj2) - { - return obj1.name.CompareTo(obj2.name); - } - if ((bool)obj1) - { - if (!descending) - { - return -1; - } - return 1; - } - if (!descending) - { - return 1; - } - return -1; - } - } - - public struct Surrogate - { - public Type type; - - public bool exactType; - - public SurrogateCallback callback; - - internal bool enabled; - - public bool HasType - { - get - { - if (enabled) - { - return type != null; - } - return false; - } - } - - public Surrogate(Type type) - : this(type, null) - { - } - - public Surrogate(Type type, SurrogateCallback callback) - { - this.type = type; - this.callback = callback; - enabled = true; - exactType = false; - } - - public void Invoke(SerializedProperty element, UnityEngine.Object objectReference, ReorderableList list) - { - if (element != null && callback != null) - { - callback(element, objectReference, list); - } - } - } - - private class InvalidListException : InvalidOperationException - { - public InvalidListException() - : base("ReorderableList serializedProperty must be an array") - { - } - } - - private class MissingListExeption : ArgumentNullException - { - public MissingListExeption() - : base("ReorderableList serializedProperty is null") - { - } - } - - private static class Internals - { - private static MethodInfo dragDropValidation; + return parameters; + } + } - private static object[] dragDropValidationParams; + private const float ELEMENT_EDGE_TOP = 1f; - private static MethodInfo appendDragDrop; + private const float ELEMENT_EDGE_BOT = 3f; - private static object[] appendDragDropParams; + private const float ELEMENT_HEIGHT_OFFSET = 4f; - static Internals() - { - dragDropValidation = Type.GetType("UnityEditor.EditorGUI, UnityEditor").GetMethod("ValidateObjectFieldAssignment", BindingFlags.Static | BindingFlags.NonPublic); - appendDragDrop = typeof(SerializedProperty).GetMethod("AppendFoldoutPPtrValue", BindingFlags.Instance | BindingFlags.NonPublic); - } + private static int selectionHash = "ReorderableListSelection".GetHashCode(); - internal static UnityEngine.Object ValidateObjectDragAndDrop(UnityEngine.Object[] references, SerializedProperty property, Type type, bool exactType) - { - dragDropValidationParams = GetParams(ref dragDropValidationParams, 3); - dragDropValidationParams[0] = references; - dragDropValidationParams[1] = type; - dragDropValidationParams[2] = property; - return dragDropValidation.Invoke(null, dragDropValidationParams) as UnityEngine.Object; - } + private static int dragAndDropHash = "ReorderableListDragAndDrop".GetHashCode(); - internal static void AppendDragAndDropValue(UnityEngine.Object obj, SerializedProperty list) - { - appendDragDropParams = GetParams(ref appendDragDropParams, 1); - appendDragDropParams[0] = obj; - appendDragDrop.Invoke(list, appendDragDropParams); - } + private const string EMPTY_LABEL = "List is Empty"; - private static object[] GetParams(ref object[] parameters, int count) - { - if (parameters == null) - { - parameters = new object[count]; - } - return parameters; - } - } + private const string ARRAY_ERROR = "{0} is not an Array!"; - private const float ELEMENT_EDGE_TOP = 1f; + public bool canAdd; - private const float ELEMENT_EDGE_BOT = 3f; + public bool canRemove; - private const float ELEMENT_HEIGHT_OFFSET = 4f; + public bool draggable; - private static int selectionHash = "ReorderableListSelection".GetHashCode(); + public bool sortable; - private static int dragAndDropHash = "ReorderableListDragAndDrop".GetHashCode(); + public bool expandable; - private const string EMPTY_LABEL = "List is Empty"; + public bool multipleSelection; - private const string ARRAY_ERROR = "{0} is not an Array!"; + public GUIContent label; - public bool canAdd; + public float headerHeight; - public bool canRemove; + public float paginationHeight; - public bool draggable; + public float footerHeight; - public bool sortable; + public float slideEasing; - public bool expandable; + public float verticalSpacing; - public bool multipleSelection; + public bool showDefaultBackground; - public GUIContent label; + public ElementDisplayType elementDisplayType; - public float headerHeight; + public string elementNameProperty; - public float paginationHeight; + public string elementNameOverride; - public float footerHeight; + public bool elementLabels; - public float slideEasing; + public Texture elementIcon; - public float verticalSpacing; + public Surrogate surrogate; - public bool showDefaultBackground; + internal readonly int id; - public ElementDisplayType elementDisplayType; + private SerializedProperty list; - public string elementNameProperty; + private int controlID = -1; - public string elementNameOverride; + private Rect[] elementRects; - public bool elementLabels; + private GUIContent elementLabel; - public Texture elementIcon; + private GUIContent pageInfoContent; - public Surrogate surrogate; + private GUIContent pageSizeContent; - internal readonly int id; + private ListSelection selection; - private SerializedProperty list; + private SlideGroup slideGroup; - private int controlID = -1; + private int pressIndex; - private Rect[] elementRects; + private bool dragging; - private GUIContent elementLabel; + private float pressPosition; - private GUIContent pageInfoContent; + private float dragPosition; - private GUIContent pageSizeContent; + private int dragDirection; - private ListSelection selection; + private DragList dragList; - private SlideGroup slideGroup; + private ListSelection beforeDragSelection; - private int pressIndex; + private Pagination pagination; - private bool dragging; + private int dragDropControlID = -1; - private float pressPosition; + public bool paginate + { + get { return pagination.enabled; } + set { pagination.enabled = value; } + } - private float dragPosition; + public int pageSize + { + get { return pagination.pageSize; } + set { pagination.pageSize = value; } + } - private int dragDirection; + private bool doPagination + { + get + { + if (pagination.enabled) + { + return !list.serializedObject.isEditingMultipleObjects; + } - private DragList dragList; + return false; + } + } - private ListSelection beforeDragSelection; + private float elementSpacing => Mathf.Max(0f, verticalSpacing - 2f); - private Pagination pagination; + public SerializedProperty List + { + get { return list; } + internal set { list = value; } + } - private int dragDropControlID = -1; + public bool HasList + { + get + { + if (list != null) + { + return list.isArray; + } - public bool paginate - { - get - { - return pagination.enabled; - } - set - { - pagination.enabled = value; - } - } + return false; + } + } - public int pageSize - { - get - { - return pagination.pageSize; - } - set - { - pagination.pageSize = value; - } - } + public int Length + { + get + { + if (!HasList) + { + return 0; + } - private bool doPagination - { - get - { - if (pagination.enabled) - { - return !list.serializedObject.isEditingMultipleObjects; - } - return false; - } - } + if (!list.hasMultipleDifferentValues) + { + return list.arraySize; + } - private float elementSpacing => Mathf.Max(0f, verticalSpacing - 2f); + int num = list.arraySize; + Object[] targetObjects = list.serializedObject.targetObjects; + for (int i = 0; i < targetObjects.Length; i++) + { + num = Mathf.Min(new SerializedObject(targetObjects[i]).FindProperty(list.propertyPath).arraySize, + num); + } - public SerializedProperty List - { - get - { - return list; - } - internal set - { - list = value; - } - } + return num; + } + } - public bool HasList - { - get - { - if (list != null) - { - return list.isArray; - } - return false; - } - } + public int VisibleLength => pagination.GetVisibleLength(Length); - public int Length - { - get - { - if (!HasList) - { - return 0; - } - if (!list.hasMultipleDifferentValues) - { - return list.arraySize; - } - int num = list.arraySize; - UnityEngine.Object[] targetObjects = list.serializedObject.targetObjects; - for (int i = 0; i < targetObjects.Length; i++) - { - num = Mathf.Min(new SerializedObject(targetObjects[i]).FindProperty(list.propertyPath).arraySize, num); - } - return num; - } - } - - public int VisibleLength => pagination.GetVisibleLength(Length); - - public int[] Selected - { - get - { - return selection.ToArray(); - } - set - { - selection = new ListSelection(value); - } - } - - public int Index - { - get - { - return selection.First; - } - set - { - selection.Select(value); - } - } - - public bool IsDragging => dragging; - - public event DrawHeaderDelegate drawHeaderCallback; - - public event DrawFooterDelegate drawFooterCallback; - - public event DrawElementDelegate drawElementCallback; - - public event DrawElementDelegate drawElementBackgroundCallback; - - public event GetElementHeightDelegate getElementHeightCallback; - - public event GetElementsHeightDelegate getElementsHeightCallback; - - public event GetElementNameDelegate getElementNameCallback; - - public event GetElementLabelDelegate getElementLabelCallback; - - public event DragDropReferenceDelegate onValidateDragAndDropCallback; - - public event DragDropAppendDelegate onAppendDragDropCallback; - - public event ActionDelegate onReorderCallback; - - public event ActionDelegate onSelectCallback; - - public event ActionDelegate onAddCallback; - - public event AddDropdownDelegate onAddDropdownCallback; - - public event ActionDelegate onRemoveCallback; - - public event ActionDelegate onMouseUpCallback; - - public event ActionBoolDelegate onCanRemoveCallback; - - public event ActionDelegate onChangedCallback; - - public ReorderableList(SerializedProperty list) - : this(list, canAdd: true, canRemove: true, draggable: true) - { - } - - public ReorderableList(SerializedProperty list, bool canAdd, bool canRemove, bool draggable) - : this(list, canAdd, canRemove, draggable, ElementDisplayType.Auto, null, null, null) - { - } - - public ReorderableList(SerializedProperty list, bool canAdd, bool canRemove, bool draggable, ElementDisplayType elementDisplayType, string elementNameProperty, Texture elementIcon) - : this(list, canAdd, canRemove, draggable, elementDisplayType, elementNameProperty, null, elementIcon) - { - } - - public ReorderableList(SerializedProperty list, bool canAdd, bool canRemove, bool draggable, ElementDisplayType elementDisplayType, string elementNameProperty, string elementNameOverride, Texture elementIcon) - { - if (list == null) - { - throw new MissingListExeption(); - } - if (!list.isArray) - { - SerializedProperty serializedProperty = list.FindPropertyRelative("array"); - if (serializedProperty == null || !serializedProperty.isArray) - { - throw new InvalidListException(); - } - this.list = serializedProperty; - } - else - { - this.list = list; - } - this.canAdd = canAdd; - this.canRemove = canRemove; - this.draggable = draggable; - this.elementDisplayType = elementDisplayType; - this.elementNameProperty = elementNameProperty; - this.elementNameOverride = elementNameOverride; - this.elementIcon = elementIcon; - id = GetHashCode(); - list.isExpanded = true; - label = new GUIContent(list.displayName); - pageInfoContent = new GUIContent(); - pageSizeContent = new GUIContent(); - verticalSpacing = EditorGUIUtility.standardVerticalSpacing; - headerHeight = 18f; - paginationHeight = 18f; - footerHeight = 13f; - slideEasing = 0.15f; - expandable = true; - elementLabels = true; - showDefaultBackground = true; - multipleSelection = true; - pagination = default(Pagination); - elementLabel = new GUIContent(); - dragList = new DragList(0); - selection = new ListSelection(); - slideGroup = new SlideGroup(); - elementRects = new Rect[0]; - } - - public float GetHeight() - { - if (HasList) - { - float num = (doPagination ? (headerHeight + paginationHeight) : headerHeight); - if (!list.isExpanded) - { - return headerHeight; - } - return num + GetElementsHeight() + footerHeight; - } - return EditorGUIUtility.singleLineHeight; - } - - public void DoLayoutList() - { - var controlRect = EditorGUILayout.GetControlRect(false, GetHeight(), EditorStyles.largeLabel); - DoList(EditorGUI.IndentedRect(controlRect), label); - } - - public void DoList(Rect rect, GUIContent label) - { - int indentLevel = EditorGUI.indentLevel; - EditorGUI.indentLevel = 0; - Rect rect2 = rect; - rect2.height = headerHeight; - if (!HasList) - { - DrawEmpty(rect2, $"{label.text} is not an Array!", GUIStyle.none, EditorStyles.helpBox); - } - else - { - controlID = GUIUtility.GetControlID(selectionHash, FocusType.Keyboard, rect); - dragDropControlID = GUIUtility.GetControlID(dragAndDropHash, FocusType.Passive, rect); - DrawHeader(rect2, label); - if (list.isExpanded) - { - if (doPagination) - { - Rect rect3 = rect2; - rect3.y += rect2.height; - rect3.height = paginationHeight; - DrawPaginationHeader(rect3); - rect2.yMax = rect3.yMax - 1f; - } - Rect rect4 = rect; - rect4.yMin = rect2.yMax; - rect4.yMax = rect.yMax - footerHeight; - Event current = Event.current; - if (selection.Length > 1 && current.type == EventType.ContextClick && CanSelect(current.mousePosition)) - { - HandleMultipleContextClick(current); - } - if (Length > 0) - { - if (!dragging) - { - UpdateElementRects(rect4, current); - } - if (elementRects.Length != 0) - { - pagination.GetVisibleRange(elementRects.Length, out var start, out var end); - Rect rect5 = rect4; - rect5.yMin = elementRects[start].yMin; - rect5.yMax = elementRects[end - 1].yMax; - HandlePreSelection(rect5, current); - DrawElements(rect4, current); - HandlePostSelection(rect5, current); - } - } - else - { - DrawEmpty(rect4, "List is Empty", Style.boxBackground, Style.verticalLabel); - } - Rect rect6 = rect; - rect6.yMin = rect4.yMax; - rect6.xMin = rect.xMax - 58f; - DrawFooter(rect6); - } - } - EditorGUI.indentLevel = indentLevel; - } - - public SerializedProperty AddItem(T item) where T : UnityEngine.Object - { - SerializedProperty serializedProperty = AddItem(); - if (serializedProperty != null) - { - serializedProperty.objectReferenceValue = item; - } - return serializedProperty; - } - - public SerializedProperty AddItem() - { - if (HasList) - { - list.arraySize++; - selection.Select(list.arraySize - 1); - SetPageByIndex(list.arraySize - 1); - DispatchChange(); - return list.GetArrayElementAtIndex(selection.Last); - } - throw new InvalidListException(); - } - - public void Remove(int[] selection) - { - Array.Sort(selection); - int num = selection.Length; - while (--num > -1) - { - RemoveItem(selection[num]); - } - } - - public void RemoveItem(int index) - { - if (index >= 0 && index < Length) - { - SerializedProperty arrayElementAtIndex = list.GetArrayElementAtIndex(index); - if (arrayElementAtIndex.propertyType == SerializedPropertyType.ObjectReference && (bool)arrayElementAtIndex.objectReferenceValue) - { - arrayElementAtIndex.objectReferenceValue = null; - } - list.DeleteArrayElementAtIndex(index); - selection.Remove(index); - if (Length > 0) - { - selection.Select(Mathf.Max(0, index - 1)); - } - DispatchChange(); - } - } - - public SerializedProperty GetItem(int index) - { - if (index >= 0 && index < Length) - { - return list.GetArrayElementAtIndex(index); - } - return null; - } - - public int IndexOf(SerializedProperty element) - { - if (element != null) - { - int num = Length; - while (--num > -1) - { - if (SerializedProperty.EqualContents(element, list.GetArrayElementAtIndex(num))) - { - return num; - } - } - } - return -1; - } - - public void GrabKeyboardFocus() - { - GUIUtility.keyboardControl = id; - } - - public bool HasKeyboardControl() - { - return GUIUtility.keyboardControl == id; - } - - public void ReleaseKeyboardFocus() - { - if (GUIUtility.keyboardControl == id) - { - GUIUtility.keyboardControl = 0; - } - } - - public void SetPage(int page) - { - if (doPagination) - { - pagination.page = page; - } - } - - public void SetPageByIndex(int index) - { - if (doPagination) - { - pagination.page = pagination.GetPageForIndex(index); - } - } - - public int GetPage(int index) - { - if (!doPagination) - { - return 0; - } - return pagination.page; - } - - public int GetPageByIndex(int index) - { - if (!doPagination) - { - return 0; - } - return pagination.GetPageForIndex(index); - } - - private float GetElementsHeight() - { - if (this.getElementsHeightCallback != null) - { - return this.getElementsHeightCallback(this); - } - int length = Length; - if (length == 0) - { - return 28f; - } - float num = 0f; - float num2 = elementSpacing; - pagination.GetVisibleRange(length, out var start, out var end); - for (int i = start; i < end; i++) - { - num += GetElementHeight(list.GetArrayElementAtIndex(i)) + num2; - } - return num + 7f - num2; - } - - private float GetElementHeight(SerializedProperty element) - { - if (this.getElementHeightCallback != null) - { - return this.getElementHeightCallback(element) + 4f; - } - float propertyHeight = EditorGUI.GetPropertyHeight(element, GetElementLabel(element, elementLabels), IsElementExpandable(element)); - return (propertyHeight > 0f) ? (propertyHeight + 4f) : propertyHeight; - } - - private Rect GetElementDrawRect(int index, Rect desiredRect) - { - if (slideEasing <= 0f) - { - return desiredRect; - } - if (!dragging) - { - return slideGroup.SetRect(index, desiredRect); - } - return slideGroup.GetRect(dragList[index].startIndex, desiredRect, slideEasing); - } - - private Rect GetElementRenderRect(SerializedProperty element, Rect elementRect) - { - float num = (draggable ? 20 : 5); - Rect result = elementRect; - result.xMin += (IsElementExpandable(element) ? (num + 10f) : num); - result.xMax -= 6f; - result.yMin += 1f; - result.yMax -= 3f; - return result; - } - - private void DrawHeader(Rect rect, GUIContent label) - { - if (showDefaultBackground && Event.current.type == EventType.Repaint) - { - Style.headerBackground.Draw(rect, isHover: false, isActive: false, on: false, hasKeyboardFocus: false); - } - HandleDragAndDrop(rect, Event.current); - bool flag = elementDisplayType != ElementDisplayType.SingleLine; - Rect rect2 = rect; - rect2.xMin += 6f; - rect2.xMax -= (flag ? 95f : 55f); - rect2.height -= 2f; - rect2.y++; - label = EditorGUI.BeginProperty(rect2, label, list); - if (this.drawHeaderCallback != null) - { - this.drawHeaderCallback(rect2, label); - } - else if (expandable) - { - rect2.xMin += 10f; - EditorGUI.BeginChangeCheck(); - bool isExpanded = EditorGUI.Foldout(rect2, list.isExpanded, label, toggleOnLabelClick: true); - if (EditorGUI.EndChangeCheck()) - { - list.isExpanded = isExpanded; - } - } - else - { - GUI.Label(rect2, label, EditorStyles.label); - } - EditorGUI.EndProperty(); - if (flag) - { - Rect position = rect; - position.xMin = rect.xMax - 25f; - position.xMax = rect.xMax - 5f; - if (GUI.Button(position, Style.expandButton, Style.preButton)) - { - ExpandElements(expand: true); - } - Rect position2 = rect; - position2.xMin = position.xMin - 20f; - position2.xMax = position.xMin; - if (GUI.Button(position2, Style.collapseButton, Style.preButton)) - { - ExpandElements(expand: false); - } - rect.xMax = position2.xMin + 5f; - } - if (sortable) - { - Rect rect3 = rect; - rect3.xMin = rect.xMax - 25f; - rect3.xMax = rect.xMax; - Rect rect4 = rect; - rect4.xMin = rect3.xMin - 20f; - rect4.xMax = rect3.xMin; - if (EditorGUI.DropdownButton(rect3, Style.sortAscending, FocusType.Passive, Style.preButton)) - { - SortElements(rect3, descending: false); - } - if (EditorGUI.DropdownButton(rect4, Style.sortDescending, FocusType.Passive, Style.preButton)) - { - SortElements(rect4, descending: true); - } - } - } - - private void ExpandElements(bool expand) - { - if (!list.isExpanded && expand) - { - list.isExpanded = true; - } - int length = Length; - for (int i = 0; i < length; i++) - { - list.GetArrayElementAtIndex(i).isExpanded = expand; - } - } - - private void SortElements(Rect rect, bool descending) - { - int total = Length; - if (total <= 1) - { - return; - } - SerializedProperty arrayElementAtIndex = list.GetArrayElementAtIndex(0); - if (arrayElementAtIndex.propertyType == SerializedPropertyType.Generic) - { - GenericMenu genericMenu = new GenericMenu(); - SerializedProperty serializedProperty = arrayElementAtIndex.Copy(); - SerializedProperty endProperty = serializedProperty.GetEndProperty(); - bool enterChildren = true; - while (serializedProperty.NextVisible(enterChildren) && !SerializedProperty.EqualContents(serializedProperty, endProperty)) - { - genericMenu.AddItem(new GUIContent(serializedProperty.name), on: false, delegate(object userData) - { - ListSort.SortOnProperty(list, total, descending, (string)userData); - ApplyReorder(); - HandleUtility.Repaint(); - }, serializedProperty.name); - enterChildren = false; - } - genericMenu.DropDown(rect); - } - else - { - ListSort.SortOnType(list, total, descending, arrayElementAtIndex.propertyType); - ApplyReorder(); - } - } - - private void DrawEmpty(Rect rect, string label, GUIStyle backgroundStyle, GUIStyle labelStyle) - { - if (showDefaultBackground && Event.current.type == EventType.Repaint) - { - backgroundStyle.Draw(rect, isHover: false, isActive: false, on: false, hasKeyboardFocus: false); - } - EditorGUI.LabelField(rect, label, labelStyle); - } - - private void UpdateElementRects(Rect rect, Event evt) - { - int length = Length; - if (length != elementRects.Length) - { - Array.Resize(ref elementRects, length); - } - if (evt.type == EventType.Repaint) - { - Rect rect2 = rect; - float num3 = (rect2.yMin = (rect2.yMax = rect.yMin + 2f)); - float num4 = elementSpacing; - pagination.GetVisibleRange(length, out var start, out var end); - for (int i = start; i < end; i++) - { - SerializedProperty arrayElementAtIndex = list.GetArrayElementAtIndex(i); - rect2.y = rect2.yMax; - rect2.height = GetElementHeight(arrayElementAtIndex); - elementRects[i] = rect2; - rect2.yMax += num4; - } - } - } - - private void DrawElements(Rect rect, Event evt) - { - if (showDefaultBackground && evt.type == EventType.Repaint) - { - Style.boxBackground.Draw(rect, isHover: false, isActive: false, on: false, hasKeyboardFocus: false); - } - if (!dragging) - { - pagination.GetVisibleRange(Length, out var start, out var end); - for (int i = start; i < end; i++) - { - bool flag = selection.Contains(i); - DrawElement(list.GetArrayElementAtIndex(i), GetElementDrawRect(i, elementRects[i]), flag, flag && GUIUtility.keyboardControl == controlID); - } - } - else - { - if (evt.type != EventType.Repaint) - { - return; - } - int length = dragList.Length; - int length2 = selection.Length; - int j; - for (j = 0; j < length2; j++) - { - DragElement value = dragList[j]; - value.desiredRect.y = dragPosition - value.dragOffset; - dragList[j] = value; - } - j = length; - while (--j > -1) - { - DragElement value2 = dragList[j]; - if (value2.selected) - { - DrawElement(value2.property, value2.desiredRect, selected: true, focused: true); - continue; - } - Rect rect2 = value2.rect; - int num = value2.startIndex; - int num2 = ((dragDirection > 0) ? (length2 - 1) : 0); - int num3 = ((dragDirection > 0) ? (-1) : length2); - for (int num4 = num2; num4 != num3; num4 -= dragDirection) - { - DragElement dragElement = dragList[num4]; - if (dragElement.Overlaps(rect2, num, dragDirection)) - { - rect2.y -= dragElement.rect.height * (float)dragDirection; - num += dragDirection; - } - } - DrawElement(value2.property, GetElementDrawRect(j, rect2), selected: false, focused: false); - value2.desiredRect = rect2; - dragList[j] = value2; - } - } - } - - private void DrawElement(SerializedProperty element, Rect rect, bool selected, bool focused) - { - if (!(rect.height < 1f)) - { - Event current = Event.current; - if (this.drawElementBackgroundCallback != null) - { - this.drawElementBackgroundCallback(rect, element, null, selected, focused); - } - else if (current.type == EventType.Repaint) - { - Style.elementBackground.Draw(rect, isHover: false, selected, selected, focused); - EditorGUI.DrawRect(new Rect(rect.x + 1f, rect.y + rect.height - 2f, rect.width - 3f, 1f), new Color(0f, 0f, 0f, 0.2f)); - } - if (current.type == EventType.Repaint && draggable) - { - Style.draggingHandle.Draw(new Rect(rect.x + 5f, rect.y + 14f, 10f, rect.height - (rect.height - 6f)), isHover: false, isActive: false, on: false, hasKeyboardFocus: false); - } - GUIContent contents = GetElementLabel(element, elementLabels); - Rect elementRenderRect = GetElementRenderRect(element, rect); - if (this.drawElementCallback != null) - { - this.drawElementCallback(elementRenderRect, element, contents, selected, focused); - } - else - { - EditorGUI.PropertyField(elementRenderRect, element, contents, includeChildren: true); - } - int num = GUIUtility.GetControlID(contents, FocusType.Passive, rect); - if (current.GetTypeForControl(num) == EventType.ContextClick && rect.Contains(current.mousePosition)) - { - HandleSingleContextClick(current, element); - } - } - } - - private GUIContent GetElementLabel(SerializedProperty element, bool allowElementLabel) - { - if (!allowElementLabel) - { - return GUIContent.none; - } - if (this.getElementLabelCallback != null) - { - return this.getElementLabelCallback(element); - } - string text = ((this.getElementNameCallback == null) ? GetElementName(element, elementNameProperty, elementNameOverride) : this.getElementNameCallback(element)); - elementLabel.text = ((!string.IsNullOrEmpty(text)) ? text : element.displayName); - elementLabel.tooltip = element.tooltip; - elementLabel.image = elementIcon; - return elementLabel; - } - - private static string GetElementName(SerializedProperty element, string nameProperty, string nameOverride) - { - if (!string.IsNullOrEmpty(nameOverride)) - { - string propertyPath = element.propertyPath; - if (propertyPath.EndsWith("]")) - { - int num = propertyPath.LastIndexOf('[') + 1; - return $"{nameOverride} {propertyPath.Substring(num, propertyPath.Length - num - 1)}"; - } - return nameOverride; - } - if (string.IsNullOrEmpty(nameProperty)) - { - return null; - } - if (element.propertyType == SerializedPropertyType.ObjectReference && nameProperty == "name") - { - if (!element.objectReferenceValue) - { - return null; - } - return element.objectReferenceValue.name; - } - SerializedProperty serializedProperty = element.FindPropertyRelative(nameProperty); - if (serializedProperty != null) - { - switch (serializedProperty.propertyType) - { - case SerializedPropertyType.ObjectReference: - if (!serializedProperty.objectReferenceValue) - { - return null; - } - return serializedProperty.objectReferenceValue.name; - case SerializedPropertyType.Enum: - return serializedProperty.enumDisplayNames[serializedProperty.enumValueIndex]; - case SerializedPropertyType.Integer: - case SerializedPropertyType.Character: - return serializedProperty.intValue.ToString(); - case SerializedPropertyType.LayerMask: - return GetLayerMaskName(serializedProperty.intValue); - case SerializedPropertyType.String: - return serializedProperty.stringValue; - case SerializedPropertyType.Float: - return serializedProperty.floatValue.ToString(); - default: - return serializedProperty.displayName; - } - } - return null; - } - - private static string GetLayerMaskName(int mask) - { - if (mask == 0) - { - return "Nothing"; - } - if (mask < 0) - { - return "Everything"; - } - string text = string.Empty; - int num = 0; - for (int i = 0; i < 32; i++) - { - if (((1 << i) & mask) != 0) - { - if (num == 4) - { - return "Mixed ..."; - } - text = string.Concat(text, (num > 0) ? ", " : string.Empty, LayerMask.LayerToName(i)); - num++; - } - } - return text; - } - - private void DrawFooter(Rect rect) - { - if (this.drawFooterCallback != null) - { - this.drawFooterCallback(rect); - return; - } - if (Event.current.type == EventType.Repaint) - { - Style.footerBackground.Draw(rect, isHover: false, isActive: false, on: false, hasKeyboardFocus: false); - } - Rect rect2 = new Rect(rect.xMin + 4f, rect.y - 3f, 25f, 13f); - Rect position = new Rect(rect.xMax - 29f, rect.y - 3f, 25f, 13f); - EditorGUI.BeginDisabledGroup(!canAdd); - if (GUI.Button(rect2, (this.onAddDropdownCallback != null) ? Style.iconToolbarPlusMore : Style.iconToolbarPlus, Style.preButton)) - { - if (this.onAddDropdownCallback != null) - { - this.onAddDropdownCallback(rect2, this); - } - else if (this.onAddCallback != null) - { - this.onAddCallback(this); - } - else - { - AddItem(); - } - } - EditorGUI.EndDisabledGroup(); - EditorGUI.BeginDisabledGroup(!CanSelect(selection) || !canRemove || (this.onCanRemoveCallback != null && !this.onCanRemoveCallback(this))); - if (GUI.Button(position, Style.iconToolbarMinus, Style.preButton)) - { - if (this.onRemoveCallback != null) - { - this.onRemoveCallback(this); - } - else - { - Remove(selection.ToArray()); - list.serializedObject.ApplyModifiedProperties(); - list.serializedObject.Update(); - } - } - EditorGUI.EndDisabledGroup(); - } - - private void DrawPaginationHeader(Rect rect) - { - int length = Length; - int pageCount = pagination.GetPageCount(length); - int num = Mathf.Clamp(pagination.page, 0, pageCount - 1); - if (num != pagination.page) - { - pagination.page = num; - HandleUtility.Repaint(); - } - Rect position = new Rect(rect.xMin + 4f, rect.y - 1f, 17f, 14f); - Rect position2 = new Rect(position.xMax, rect.y - 1f, 17f, 14f); - Rect position3 = new Rect(position2.xMax, rect.y - 1f, 17f, 14f); - if (Event.current.type == EventType.Repaint) - { - Style.paginationHeader.Draw(rect, isHover: false, isActive: true, on: true, hasKeyboardFocus: false); - } - pageInfoContent.text = $"{pagination.page + 1} / {pageCount}"; - Rect position4 = rect; - position4.width = Style.paginationText.CalcSize(pageInfoContent).x; - position4.x = rect.xMax - position4.width - 7f; - position4.y += 2f; - GUI.Label(position4, pageInfoContent, Style.paginationText); - if (GUI.Button(position, Style.iconPagePrev, Style.preButton)) - { - pagination.page = Mathf.Max(0, pagination.page - 1); - } - if (EditorGUI.DropdownButton(position2, Style.iconPagePopup, FocusType.Passive, Style.preButton)) - { - GenericMenu genericMenu = new GenericMenu(); - for (int i = 0; i < pageCount; i++) - { - int num2 = i; - genericMenu.AddItem(new GUIContent($"Page {i + 1}"), i == pagination.page, OnPageDropDownSelect, num2); - } - genericMenu.DropDown(position2); - } - if (GUI.Button(position3, Style.iconPageNext, Style.preButton)) - { - pagination.page = Mathf.Min(pageCount - 1, pagination.page + 1); - } - pageSizeContent.text = length.ToString(); - GUIStyle pageSizeTextField = Style.pageSizeTextField; - Texture image = Style.listIcon.image; - float num3 = position3.xMax + 5f; - float num4 = position4.xMin - 5f - num3; - float num5 = image.width + 2; - float num6 = pageSizeTextField.CalcSize(pageSizeContent).x + 50f + num5; - Rect position5 = rect; - position5.x = num3 + (num4 - num6) / 2f; - position5.width = num6 - num5; - EditorGUI.BeginChangeCheck(); - EditorGUIUtility.labelWidth = num5; - EditorGUIUtility.SetIconSize(new Vector2(image.width, image.height)); - int value = EditorGUI.DelayedIntField(position5, Style.listIcon, pagination.pageSize, pageSizeTextField); - EditorGUIUtility.labelWidth = 0f; - EditorGUIUtility.SetIconSize(Vector2.zero); - if (EditorGUI.EndChangeCheck()) - { - pagination.pageSize = Mathf.Clamp(value, 0, length); - pagination.page = Mathf.Min(pagination.GetPageCount(length) - 1, pagination.page); - } - } - - private void OnPageDropDownSelect(object userData) - { - pagination.page = (int)userData; - } - - private void DispatchChange() - { - if (this.onChangedCallback != null) - { - this.onChangedCallback(this); - } - } - - private void HandleSingleContextClick(Event evt, SerializedProperty element) - { - selection.Select(IndexOf(element)); - GenericMenu genericMenu = new GenericMenu(); - if (element.isInstantiatedPrefab) - { - genericMenu.AddItem(new GUIContent(string.Concat("Revert ", GetElementLabel(element, allowElementLabel: true).text, " to Prefab")), on: false, selection.RevertValues, list); - genericMenu.AddSeparator(string.Empty); - } - HandleSharedContextClick(evt, genericMenu, "Duplicate Array Element", "Delete Array Element", "Move Array Element"); - } - - private void HandleMultipleContextClick(Event evt) - { - GenericMenu genericMenu = new GenericMenu(); - if (selection.CanRevert(list)) - { - genericMenu.AddItem(new GUIContent("Revert Values to Prefab"), on: false, selection.RevertValues, list); - genericMenu.AddSeparator(string.Empty); - } - HandleSharedContextClick(evt, genericMenu, "Duplicate Array Elements", "Delete Array Elements", "Move Array Elements"); - } - - private void HandleSharedContextClick(Event evt, GenericMenu menu, string duplicateLabel, string deleteLabel, string moveLabel) - { - menu.AddItem(new GUIContent(duplicateLabel), on: false, HandleDuplicate, list); - menu.AddItem(new GUIContent(deleteLabel), on: false, HandleDelete, list); - if (doPagination) - { - int pageCount = pagination.GetPageCount(Length); - if (pageCount > 1) - { - for (int i = 0; i < pageCount; i++) - { - string text = $"{moveLabel}/Page {i + 1}"; - menu.AddItem(new GUIContent(text), i == pagination.page, HandleMoveElement, i); - } - } - } - menu.ShowAsContext(); - evt.Use(); - } - - private void HandleMoveElement(object userData) - { - int num = (int)userData; - int page = pagination.page; - int num2 = pagination.pageSize; - int num3 = num * num2 - page * num2; - int num4 = ((num3 > 0) ? 1 : (-1)); - int length = Length; - int num5 = 0; - for (int i = 0; i < selection.Length; i++) - { - int num6 = selection[i] + num3; - num5 = ((num4 < 0) ? Mathf.Min(num5, num6) : Mathf.Max(num5, num6 - length)); - } - num3 -= num5; - UpdateDragList(0f, 0, length); - List list = new List(dragList.Elements.Where((DragElement t) => !selection.Contains(t.startIndex))); - selection.Sort(); - for (int j = 0; j < selection.Length; j++) - { - int num7 = selection[j]; - int indexFromSelection = dragList.GetIndexFromSelection(num7); - int index = Mathf.Clamp(num7 + num3, 0, list.Count); - list.Insert(index, dragList[indexFromSelection]); - } - dragList.Elements = list.ToArray(); - ReorderDraggedElements(num4, 0, null); - pagination.page = num; - HandleUtility.Repaint(); - } - - private void HandleDelete(object userData) - { - selection.Delete(userData as SerializedProperty); - DispatchChange(); - } - - private void HandleDuplicate(object userData) - { - selection.Duplicate(userData as SerializedProperty); - DispatchChange(); - } - - private void HandleDragAndDrop(Rect rect, Event evt) - { - switch (evt.GetTypeForControl(dragDropControlID)) - { - case EventType.DragUpdated: - case EventType.DragPerform: - { - if (!GUI.enabled || !rect.Contains(evt.mousePosition)) - { - break; - } - UnityEngine.Object[] objectReferences = DragAndDrop.objectReferences; - UnityEngine.Object[] array = new UnityEngine.Object[1]; - bool flag = false; - UnityEngine.Object[] array2 = objectReferences; - for (int i = 0; i < array2.Length; i++) - { - UnityEngine.Object @object = (array[0] = array2[i]); - UnityEngine.Object object2 = ValidateObjectDragAndDrop(array); - if (object2 != null) - { - DragAndDrop.visualMode = DragAndDropVisualMode.Copy; - if (evt.type == EventType.DragPerform) - { - AppendDragAndDropValue(object2); - flag = true; - DragAndDrop.activeControlID = 0; - } - else - { - DragAndDrop.activeControlID = dragDropControlID; - } - } - } - if (flag) - { - GUI.changed = true; - DragAndDrop.AcceptDrag(); - } - break; - } - case EventType.DragExited: - if (GUI.enabled) - { - HandleUtility.Repaint(); - } - break; - } - } - - private UnityEngine.Object ValidateObjectDragAndDrop(UnityEngine.Object[] references) - { - if (this.onValidateDragAndDropCallback != null) - { - return this.onValidateDragAndDropCallback(references, this); - } - if (surrogate.HasType) - { - return Internals.ValidateObjectDragAndDrop(references, null, surrogate.type, surrogate.exactType); - } - return Internals.ValidateObjectDragAndDrop(references, list, null, exactType: false); - } - - private void AppendDragAndDropValue(UnityEngine.Object obj) - { - if (this.onAppendDragDropCallback != null) - { - this.onAppendDragDropCallback(obj, this); - } - else if (surrogate.HasType) - { - surrogate.Invoke(AddItem(), obj, this); - } - else - { - Internals.AppendDragAndDropValue(obj, list); - } - DispatchChange(); - } - - private void HandlePreSelection(Rect rect, Event evt) - { - if (evt.type == EventType.MouseDrag && draggable && GUIUtility.hotControl == controlID) - { - if (selection.Length > 0 && UpdateDragPosition(evt.mousePosition, rect, dragList)) - { - GUIUtility.keyboardControl = controlID; - dragging = true; - } - evt.Use(); - } - } - - private void HandlePostSelection(Rect rect, Event evt) - { - switch (evt.GetTypeForControl(controlID)) - { - case EventType.MouseDown: - if (rect.Contains(evt.mousePosition) && IsSelectionButton(evt)) - { - int selectionIndex = GetSelectionIndex(evt.mousePosition); - if (CanSelect(selectionIndex)) - { - DoSelection(selectionIndex, GUIUtility.keyboardControl == 0 || GUIUtility.keyboardControl == controlID || evt.button == 2, evt); - } - else - { - selection.Clear(); - } - HandleUtility.Repaint(); - } - break; - case EventType.MouseUp: - if (!draggable) - { - selection.SelectWhenNoAction(pressIndex, evt); - if (this.onMouseUpCallback != null && IsPositionWithinElement(evt.mousePosition, selection.Last)) - { - this.onMouseUpCallback(this); - } - } - else if (GUIUtility.hotControl == controlID) - { - evt.Use(); - if (dragging) - { - dragging = false; - ReorderDraggedElements(dragDirection, dragList.StartIndex, delegate - { - dragList.SortByPosition(); - }); - } - else - { - selection.SelectWhenNoAction(pressIndex, evt); - if (this.onMouseUpCallback != null) - { - this.onMouseUpCallback(this); - } - } - GUIUtility.hotControl = 0; - } - HandleUtility.Repaint(); - break; - case EventType.KeyDown: - if (GUIUtility.keyboardControl != controlID) - { - break; - } - if (evt.keyCode == KeyCode.DownArrow && !dragging) - { - selection.Select(Mathf.Min(selection.Last + 1, Length - 1)); - evt.Use(); - } - else if (evt.keyCode == KeyCode.UpArrow && !dragging) - { - selection.Select(Mathf.Max(selection.Last - 1, 0)); - evt.Use(); - } - else if (evt.keyCode == KeyCode.Escape && GUIUtility.hotControl == controlID) - { - GUIUtility.hotControl = 0; - if (dragging) - { - dragging = false; - selection = beforeDragSelection; - } - evt.Use(); - } - break; - case EventType.MouseMove: - case EventType.MouseDrag: - break; - } - } - - private bool IsSelectionButton(Event evt) - { - if (evt.button != 0) - { - return evt.button == 2; - } - return true; - } - - private void DoSelection(int index, bool setKeyboardControl, Event evt) - { - if (multipleSelection) - { - selection.AppendWithAction(pressIndex = index, evt); - } - else - { - selection.Select(pressIndex = index); - } - if (this.onSelectCallback != null) - { - this.onSelectCallback(this); - } - if (draggable) - { - dragging = false; - dragPosition = (pressPosition = evt.mousePosition.y); - pagination.GetVisibleRange(Length, out var start, out var end); - UpdateDragList(dragPosition, start, end); - selection.Trim(start, end); - beforeDragSelection = selection.Clone(); - GUIUtility.hotControl = controlID; - } - if (setKeyboardControl) - { - GUIUtility.keyboardControl = controlID; - } - evt.Use(); - } - - private void UpdateDragList(float dragPosition, int start, int end) - { - dragList.Resize(start, end - start); - for (int i = start; i < end; i++) - { - SerializedProperty arrayElementAtIndex = list.GetArrayElementAtIndex(i); - Rect rect = elementRects[i]; - DragElement dragElement = default(DragElement); - dragElement.property = arrayElementAtIndex; - dragElement.dragOffset = dragPosition - rect.y; - dragElement.rect = rect; - dragElement.desiredRect = rect; - dragElement.selected = selection.Contains(i); - dragElement.startIndex = i; - DragElement value = dragElement; - dragList[i - start] = value; - } - dragList.SortByIndex(); - } - - private bool UpdateDragPosition(Vector2 position, Rect bounds, DragList dragList) - { - int index = 0; - int index2 = selection.Length - 1; - float dragOffset = dragList[index].dragOffset; - float num = dragList[index2].rect.height - dragList[index2].dragOffset; - dragPosition = Mathf.Clamp(position.y, bounds.yMin + dragOffset, bounds.yMax - num); - if (Mathf.Abs(dragPosition - pressPosition) > 1f) - { - dragDirection = (int)Mathf.Sign(dragPosition - pressPosition); - return true; - } - return false; - } - - private void ReorderDraggedElements(int direction, int offset, Action sortList) - { - dragList.RecordState(); - sortList?.Invoke(); - selection.Sort(delegate(int a, int b) - { - int indexFromSelection2 = dragList.GetIndexFromSelection(a); - int indexFromSelection3 = dragList.GetIndexFromSelection(b); - return (direction <= 0) ? indexFromSelection3.CompareTo(indexFromSelection2) : indexFromSelection2.CompareTo(indexFromSelection3); - }); - int num = selection.Length; - while (--num > -1) - { - int indexFromSelection = dragList.GetIndexFromSelection(selection[num]); - int num2 = indexFromSelection + offset; - selection[num] = num2; - list.MoveArrayElement(dragList[indexFromSelection].startIndex, num2); - } - dragList.RestoreState(list); - ApplyReorder(); - } - - private void ApplyReorder() - { - list.serializedObject.ApplyModifiedProperties(); - list.serializedObject.Update(); - if (this.onReorderCallback != null) - { - this.onReorderCallback(this); - } - DispatchChange(); - } - - private int GetSelectionIndex(Vector2 position) - { - pagination.GetVisibleRange(elementRects.Length, out var start, out var end); - for (int i = start; i < end; i++) - { - Rect rect = elementRects[i]; - if (rect.Contains(position) || (i == 0 && position.y <= rect.yMin) || (i == end - 1 && position.y >= rect.yMax)) - { - return i; - } - } - return -1; - } - - private bool CanSelect(ListSelection selection) - { - if (selection.Length <= 0) - { - return false; - } - return selection.All((int s) => CanSelect(s)); - } - - private bool CanSelect(int index) - { - if (index >= 0) - { - return index < Length; - } - return false; - } - - private bool CanSelect(Vector2 position) - { - if (selection.Length <= 0) - { - return false; - } - return selection.Any((int s) => IsPositionWithinElement(position, s)); - } - - private bool IsPositionWithinElement(Vector2 position, int index) - { - if (!CanSelect(index)) - { - return false; - } - return elementRects[index].Contains(position); - } - - private bool IsElementExpandable(SerializedProperty element) - { - switch (elementDisplayType) - { - case ElementDisplayType.Auto: - if (element.hasVisibleChildren) - { - return IsTypeExpandable(element.propertyType); - } - return false; - case ElementDisplayType.Expandable: - return true; - case ElementDisplayType.SingleLine: - return false; - default: - return false; - } - } - - private bool IsTypeExpandable(SerializedPropertyType type) - { - switch (type) - { - case SerializedPropertyType.Generic: - case SerializedPropertyType.Vector4: - case SerializedPropertyType.ArraySize: - case SerializedPropertyType.Quaternion: - return true; - default: - return false; - } - } - } -} + public int[] Selected + { + get { return selection.ToArray(); } + set { selection = new ListSelection(value); } + } + + public int Index + { + get { return selection.First; } + set { selection.Select(value); } + } + + public bool IsDragging => dragging; + + public event DrawHeaderDelegate drawHeaderCallback; + + public event DrawFooterDelegate drawFooterCallback; + + public event DrawElementDelegate drawElementCallback; + + public event DrawElementDelegate drawElementBackgroundCallback; + + public event GetElementHeightDelegate getElementHeightCallback; + + public event GetElementsHeightDelegate getElementsHeightCallback; + + public event GetElementNameDelegate getElementNameCallback; + + public event GetElementLabelDelegate getElementLabelCallback; + + public event DragDropReferenceDelegate onValidateDragAndDropCallback; + + public event DragDropAppendDelegate onAppendDragDropCallback; + + public event ActionDelegate onReorderCallback; + + public event ActionDelegate onSelectCallback; + + public event ActionDelegate onAddCallback; + + public event AddDropdownDelegate onAddDropdownCallback; + + public event ActionDelegate onRemoveCallback; + + public event ActionDelegate onMouseUpCallback; + + public event ActionBoolDelegate onCanRemoveCallback; + + public event ActionDelegate onChangedCallback; + + public ReorderableList(SerializedProperty list) + : this(list, canAdd: true, canRemove: true, draggable: true) + { + } + + public ReorderableList(SerializedProperty list, bool canAdd, bool canRemove, bool draggable) + : this(list, canAdd, canRemove, draggable, ElementDisplayType.Auto, null, null, null) + { + } + + public ReorderableList(SerializedProperty list, bool canAdd, bool canRemove, bool draggable, + ElementDisplayType elementDisplayType, string elementNameProperty, Texture elementIcon) + : this(list, canAdd, canRemove, draggable, elementDisplayType, elementNameProperty, null, elementIcon) + { + } + + public ReorderableList(SerializedProperty list, bool canAdd, bool canRemove, bool draggable, + ElementDisplayType elementDisplayType, string elementNameProperty, string elementNameOverride, + Texture elementIcon) + { + if (list == null) + { + throw new MissingListException(); + } + + if (!list.isArray) + { + SerializedProperty serializedProperty = list.FindPropertyRelative("array"); + if (serializedProperty == null || !serializedProperty.isArray) + { + throw new InvalidListException(); + } + + this.list = serializedProperty; + } + else + { + this.list = list; + } + + this.canAdd = canAdd; + this.canRemove = canRemove; + this.draggable = draggable; + this.elementDisplayType = elementDisplayType; + this.elementNameProperty = elementNameProperty; + this.elementNameOverride = elementNameOverride; + this.elementIcon = elementIcon; + id = GetHashCode(); + list.isExpanded = true; + label = new GUIContent(list.displayName); + pageInfoContent = new GUIContent(); + pageSizeContent = new GUIContent(); + verticalSpacing = EditorGUIUtility.standardVerticalSpacing; + headerHeight = 18f; + paginationHeight = 18f; + footerHeight = 13f; + slideEasing = 0.15f; + expandable = true; + elementLabels = true; + showDefaultBackground = true; + multipleSelection = true; + pagination = default(Pagination); + elementLabel = new GUIContent(); + dragList = new DragList(0); + selection = new ListSelection(); + slideGroup = new SlideGroup(); + elementRects = new Rect[0]; + } + + public float GetHeight() + { + if (!HasList) return EditorGUIUtility.singleLineHeight; + var num = doPagination ? headerHeight + paginationHeight : headerHeight; + if (!list.isExpanded) return headerHeight; + return num + GetElementsHeight() + footerHeight + 15; + } + + public void DoLayoutList() + { + var controlRect = EditorGUILayout.GetControlRect(false, GetHeight(), EditorStyles.largeLabel); + DoList(EditorGUI.IndentedRect(controlRect), label); + } + + public void DoList(Rect rect, GUIContent titleLabel) + { + var indentLevel = EditorGUI.indentLevel; + EditorGUI.indentLevel = 0; + var rect2 = rect; + rect2.height = headerHeight; + if (!HasList) + { + DrawEmpty(rect2, $"{titleLabel.text} is not an Array!", GUIStyle.none, EditorStyles.helpBox); + } + else + { + controlID = GUIUtility.GetControlID(selectionHash, FocusType.Keyboard, rect); + dragDropControlID = GUIUtility.GetControlID(dragAndDropHash, FocusType.Passive, rect); + DrawHeader(rect2, titleLabel); + if (list.isExpanded) + { + if (doPagination) + { + var rect3 = rect2; + rect3.y += rect2.height + 16f; + rect3.height = paginationHeight; + rect3.width -= 1; + rect3.xMin += 1; + DrawPaginationHeader(rect3); + rect2.yMax = rect3.yMax - 1f; + } + + var rect4 = rect; + rect4.yMin = rect2.yMax; + rect4.yMax = rect.yMax - footerHeight; + var current = Event.current; + if (selection.Length > 1 && current.type == EventType.ContextClick && + CanSelect(current.mousePosition)) + { + HandleMultipleContextClick(current); + } + + if (Length > 0) + { + if (!dragging) + { + UpdateElementRects(rect4, current); + } + + if (elementRects.Length != 0) + { + pagination.GetVisibleRange(elementRects.Length, out var start, out var end); + var rect5 = rect4; + rect5.yMin = elementRects[start].yMin; + rect5.yMax = elementRects[end - 1].yMax; + HandlePreSelection(rect5, current); + DrawElements(rect4, current); + HandlePostSelection(rect5, current); + } + } + else + { + DrawEmpty(rect4, "List is Empty", Style.boxBackground, Style.verticalLabel); + } + } + + var rect6 = rect; + rect6.yMin = rect.yMax - footerHeight; + rect6.xMin = rect.xMax - 58f; + DrawFooter(rect6); + } + + EditorGUI.indentLevel = indentLevel; + } + + public SerializedProperty AddItem(T item) where T : Object + { + SerializedProperty serializedProperty = AddItem(); + if (serializedProperty != null) + { + serializedProperty.objectReferenceValue = item; + } + + return serializedProperty; + } + + public SerializedProperty AddItem() + { + if (HasList) + { + list.arraySize++; + selection.Select(list.arraySize - 1); + SetPageByIndex(list.arraySize - 1); + DispatchChange(); + return list.GetArrayElementAtIndex(selection.Last); + } + + throw new InvalidListException(); + } + + public void Remove(int[] selection) + { + Array.Sort(selection); + int num = selection.Length; + while (--num > -1) + { + RemoveItem(selection[num]); + } + } + + public void RemoveItem(int index) + { + if (index >= 0 && index < Length) + { + SerializedProperty arrayElementAtIndex = list.GetArrayElementAtIndex(index); + if (arrayElementAtIndex.propertyType == SerializedPropertyType.ObjectReference && + (bool)arrayElementAtIndex.objectReferenceValue) + { + arrayElementAtIndex.objectReferenceValue = null; + } + + list.DeleteArrayElementAtIndex(index); + selection.Remove(index); + if (Length > 0) + { + selection.Select(Mathf.Max(0, index - 1)); + } + + DispatchChange(); + } + } + + public SerializedProperty GetItem(int index) + { + if (index >= 0 && index < Length) + { + return list.GetArrayElementAtIndex(index); + } + + return null; + } + + public int IndexOf(SerializedProperty element) + { + if (element != null) + { + int num = Length; + while (--num > -1) + { + if (SerializedProperty.EqualContents(element, list.GetArrayElementAtIndex(num))) + { + return num; + } + } + } + + return -1; + } + + public void GrabKeyboardFocus() + { + GUIUtility.keyboardControl = id; + } + + public bool HasKeyboardControl() + { + return GUIUtility.keyboardControl == id; + } + + public void ReleaseKeyboardFocus() + { + if (GUIUtility.keyboardControl == id) + { + GUIUtility.keyboardControl = 0; + } + } + + public void SetPage(int page) + { + if (doPagination) + { + pagination.page = page; + } + } + + public void SetPageByIndex(int index) + { + if (doPagination) + { + pagination.page = pagination.GetPageForIndex(index); + } + } + + public int GetPage(int index) + { + if (!doPagination) + { + return 0; + } + + return pagination.page; + } + + public int GetPageByIndex(int index) + { + if (!doPagination) + { + return 0; + } + + return pagination.GetPageForIndex(index); + } + + private float GetElementsHeight() + { + if (this.getElementsHeightCallback != null) + { + return this.getElementsHeightCallback(this); + } + + int length = Length; + if (length == 0) + { + return 28f; + } + + float num = 0f; + float num2 = elementSpacing; + pagination.GetVisibleRange(length, out var start, out var end); + for (int i = start; i < end; i++) + { + num += GetElementHeight(list.GetArrayElementAtIndex(i)) + num2; + } + + return num + 7f - num2; + } + + private float GetElementHeight(SerializedProperty element) + { + if (this.getElementHeightCallback != null) + { + return this.getElementHeightCallback(element) + 4f; + } + + float propertyHeight = EditorGUI.GetPropertyHeight(element, GetElementLabel(element, elementLabels), + IsElementExpandable(element)); + return (propertyHeight > 0f) ? (propertyHeight + 4f) : propertyHeight; + } + + private Rect GetElementDrawRect(int index, Rect desiredRect) + { + if (slideEasing <= 0f) + { + return desiredRect; + } + + if (!dragging) + { + return slideGroup.SetRect(index, desiredRect); + } + + return slideGroup.GetRect(dragList[index].startIndex, desiredRect, slideEasing); + } + + private Rect GetElementRenderRect(SerializedProperty element, Rect elementRect) + { + float num = (draggable ? 20 : 5); + Rect result = elementRect; + result.xMin += (IsElementExpandable(element) ? (num + 10f) : num); + result.xMax -= 6f; + result.yMin += 1f; + result.yMax -= 3f; + return result; + } + + private void DrawHeader(Rect rect, GUIContent titleLabel) + { + if (showDefaultBackground && Event.current.type == EventType.Repaint) + { + Style.headerBackground.Draw(rect, isHover: false, isActive: false, on: false, hasKeyboardFocus: false); + } + + HandleDragAndDrop(rect, Event.current); + var flag = elementDisplayType != ElementDisplayType.SingleLine; + var rect2 = rect; + rect2.xMin += 6f; + rect2.xMax -= flag ? 95f : 55f; + rect2.height = 15f; + rect2.y++; + titleLabel = EditorGUI.BeginProperty(rect2, titleLabel, list); + if (this.drawHeaderCallback != null) + { + drawHeaderCallback(rect2, titleLabel); + } + else if (expandable) + { + rect2.xMin += 10f; + EditorGUI.BeginChangeCheck(); + var isExpanded = EditorGUI.Foldout(rect2, list.isExpanded, titleLabel, toggleOnLabelClick: true); + if (EditorGUI.EndChangeCheck()) + { + list.isExpanded = isExpanded; + } + } + else + { + GUI.Label(rect2, titleLabel, EditorStyles.label); + } + + EditorGUI.EndProperty(); + if (flag) + { + var position = rect; + position.xMin = rect.xMax - 25f; + position.xMax = rect.xMax - 5f; + if (GUI.Button(position, Style.expandButton, Style.preButton)) + { + ExpandElements(expand: true); + } + + var position2 = rect; + position2.xMin = position.xMin - 20f; + position2.xMax = position.xMin; + if (GUI.Button(position2, Style.collapseButton, Style.preButton)) + { + ExpandElements(expand: false); + } + + rect.xMax = position2.xMin + 5f; + } + + if (!sortable) return; + var rect3 = rect; + rect3.xMin = rect.xMax - 25f; + rect3.xMax = rect.xMax; + var rect4 = rect; + rect4.xMin = rect3.xMin - 20f; + rect4.xMax = rect3.xMin; + if (EditorGUI.DropdownButton(rect3, Style.sortAscending, FocusType.Passive, Style.preButton)) + { + SortElements(rect3, descending: false); + } + + if (EditorGUI.DropdownButton(rect4, Style.sortDescending, FocusType.Passive, Style.preButton)) + { + SortElements(rect4, descending: true); + } + } + + private void ExpandElements(bool expand) + { + if (!list.isExpanded && expand) + { + list.isExpanded = true; + } + + int length = Length; + for (int i = 0; i < length; i++) + { + list.GetArrayElementAtIndex(i).isExpanded = expand; + } + } + + private void SortElements(Rect rect, bool descending) + { + int total = Length; + if (total <= 1) + { + return; + } + + SerializedProperty arrayElementAtIndex = list.GetArrayElementAtIndex(0); + if (arrayElementAtIndex.propertyType == SerializedPropertyType.Generic) + { + GenericMenu genericMenu = new GenericMenu(); + SerializedProperty serializedProperty = arrayElementAtIndex.Copy(); + SerializedProperty endProperty = serializedProperty.GetEndProperty(); + bool enterChildren = true; + while (serializedProperty.NextVisible(enterChildren) && + !SerializedProperty.EqualContents(serializedProperty, endProperty)) + { + genericMenu.AddItem(new GUIContent(serializedProperty.name), on: false, delegate(object userData) + { + ListSort.SortOnProperty(list, total, descending, (string)userData); + ApplyReorder(); + HandleUtility.Repaint(); + }, serializedProperty.name); + enterChildren = false; + } + + genericMenu.DropDown(rect); + } + else + { + ListSort.SortOnType(list, total, descending, arrayElementAtIndex.propertyType); + ApplyReorder(); + } + } + + private void DrawEmpty(Rect rect, string label, GUIStyle backgroundStyle, GUIStyle labelStyle) + { + if (showDefaultBackground && Event.current.type == EventType.Repaint) + { + backgroundStyle.Draw(rect, isHover: false, isActive: false, on: false, hasKeyboardFocus: false); + } + + EditorGUI.LabelField(rect, label, labelStyle); + } + + private void UpdateElementRects(Rect rect, Event evt) + { + int length = Length; + if (length != elementRects.Length) + { + Array.Resize(ref elementRects, length); + } + + if (evt.type == EventType.Repaint) + { + Rect rect2 = rect; + float num3 = (rect2.yMin = (rect2.yMax = rect.yMin + 2f)); + float num4 = elementSpacing; + pagination.GetVisibleRange(length, out var start, out var end); + for (int i = start; i < end; i++) + { + SerializedProperty arrayElementAtIndex = list.GetArrayElementAtIndex(i); + rect2.y = rect2.yMax; + rect2.height = GetElementHeight(arrayElementAtIndex); + elementRects[i] = rect2; + rect2.yMax += num4; + } + } + } + + private void DrawElements(Rect rect, Event evt) + { + if (showDefaultBackground && evt.type == EventType.Repaint) + { + Style.boxBackground.Draw(rect, isHover: false, isActive: false, on: false, hasKeyboardFocus: false); + } + + if (!dragging) + { + pagination.GetVisibleRange(Length, out var start, out var end); + for (int i = start; i < end; i++) + { + bool flag = selection.Contains(i); + DrawElement(list.GetArrayElementAtIndex(i), GetElementDrawRect(i, elementRects[i]), flag, + flag && GUIUtility.keyboardControl == controlID); + } + } + else + { + if (evt.type != EventType.Repaint) + { + return; + } + + int length = dragList.Length; + int length2 = selection.Length; + int j; + for (j = 0; j < length2; j++) + { + DragElement value = dragList[j]; + value.desiredRect.y = dragPosition - value.dragOffset; + dragList[j] = value; + } + + j = length; + while (--j > -1) + { + DragElement value2 = dragList[j]; + if (value2.selected) + { + DrawElement(value2.property, value2.desiredRect, selected: true, focused: true); + continue; + } + + Rect rect2 = value2.rect; + int num = value2.startIndex; + int num2 = ((dragDirection > 0) ? (length2 - 1) : 0); + int num3 = ((dragDirection > 0) ? (-1) : length2); + for (int num4 = num2; num4 != num3; num4 -= dragDirection) + { + DragElement dragElement = dragList[num4]; + if (dragElement.Overlaps(rect2, num, dragDirection)) + { + rect2.y -= dragElement.rect.height * (float)dragDirection; + num += dragDirection; + } + } + + DrawElement(value2.property, GetElementDrawRect(j, rect2), selected: false, focused: false); + value2.desiredRect = rect2; + dragList[j] = value2; + } + } + } + + private void DrawElement(SerializedProperty element, Rect rect, bool selected, bool focused) + { + if (!(rect.height < 1f)) + { + Event current = Event.current; + if (this.drawElementBackgroundCallback != null) + { + this.drawElementBackgroundCallback(rect, element, null, selected, focused); + } + else if (current.type == EventType.Repaint) + { + Style.elementBackground.Draw(rect, isHover: false, selected, selected, focused); + EditorGUI.DrawRect(new Rect(rect.x + 1f, rect.y + rect.height - 2f, rect.width - 3f, 1f), + new Color(0f, 0f, 0f, 0.2f)); + } + + if (current.type == EventType.Repaint && draggable) + { + Style.draggingHandle.Draw( + new Rect(rect.x + 5f, rect.y + 14f, 10f, rect.height - (rect.height - 6f)), isHover: false, + isActive: false, on: false, hasKeyboardFocus: false); + } + + GUIContent contents = GetElementLabel(element, elementLabels); + Rect elementRenderRect = GetElementRenderRect(element, rect); + if (this.drawElementCallback != null) + { + this.drawElementCallback(elementRenderRect, element, contents, selected, focused); + } + else + { + EditorGUI.PropertyField(elementRenderRect, element, contents, includeChildren: true); + } + + int num = GUIUtility.GetControlID(contents, FocusType.Passive, rect); + if (current.GetTypeForControl(num) == EventType.ContextClick && rect.Contains(current.mousePosition)) + { + HandleSingleContextClick(current, element); + } + } + } + + private GUIContent GetElementLabel(SerializedProperty element, bool allowElementLabel) + { + if (!allowElementLabel) + { + return GUIContent.none; + } + + if (this.getElementLabelCallback != null) + { + return this.getElementLabelCallback(element); + } + + string text = ((this.getElementNameCallback == null) + ? GetElementName(element, elementNameProperty, elementNameOverride) + : this.getElementNameCallback(element)); + elementLabel.text = ((!string.IsNullOrEmpty(text)) ? text : element.displayName); + elementLabel.tooltip = element.tooltip; + elementLabel.image = elementIcon; + return elementLabel; + } + + private static string GetElementName(SerializedProperty element, string nameProperty, string nameOverride) + { + if (!string.IsNullOrEmpty(nameOverride)) + { + string propertyPath = element.propertyPath; + if (propertyPath.EndsWith("]")) + { + int num = propertyPath.LastIndexOf('[') + 1; + return $"{nameOverride} {propertyPath.Substring(num, propertyPath.Length - num - 1)}"; + } + + return nameOverride; + } + + if (string.IsNullOrEmpty(nameProperty)) + { + return null; + } + + if (element.propertyType == SerializedPropertyType.ObjectReference && nameProperty == "name") + { + if (!element.objectReferenceValue) + { + return null; + } + + return element.objectReferenceValue.name; + } + + SerializedProperty serializedProperty = element.FindPropertyRelative(nameProperty); + if (serializedProperty != null) + { + switch (serializedProperty.propertyType) + { + case SerializedPropertyType.ObjectReference: + if (!serializedProperty.objectReferenceValue) + { + return null; + } + + return serializedProperty.objectReferenceValue.name; + case SerializedPropertyType.Enum: + return serializedProperty.enumDisplayNames[serializedProperty.enumValueIndex]; + case SerializedPropertyType.Integer: + case SerializedPropertyType.Character: + return serializedProperty.intValue.ToString(); + case SerializedPropertyType.LayerMask: + return GetLayerMaskName(serializedProperty.intValue); + case SerializedPropertyType.String: + return serializedProperty.stringValue; + case SerializedPropertyType.Float: + return serializedProperty.floatValue.ToString(); + default: + return serializedProperty.displayName; + } + } + + return null; + } + + private static string GetLayerMaskName(int mask) + { + if (mask == 0) + { + return "Nothing"; + } + + if (mask < 0) + { + return "Everything"; + } + + string text = string.Empty; + int num = 0; + for (int i = 0; i < 32; i++) + { + if (((1 << i) & mask) != 0) + { + if (num == 4) + { + return "Mixed ..."; + } + + text = string.Concat(text, (num > 0) ? ", " : string.Empty, LayerMask.LayerToName(i)); + num++; + } + } + + return text; + } + + private void DrawFooter(Rect rect) + { + if (this.drawFooterCallback != null) + { + this.drawFooterCallback(rect); + return; + } + + if (Event.current.type == EventType.Repaint) + { + Style.footerBackground.Draw(rect, isHover: false, isActive: false, on: false, hasKeyboardFocus: false); + } + + var rect2 = new Rect(rect.xMin + 4f, rect.y - 3f, 25f, 13f); + var position = new Rect(rect.xMax - 29f, rect.y - 3f, 25f, 13f); + EditorGUI.BeginDisabledGroup(!canAdd); + if (GUI.Button(rect2, + onAddDropdownCallback != null ? Style.iconToolbarPlusMore : Style.iconToolbarPlus, + Style.preButton)) + { + if (this.onAddDropdownCallback != null) + { + this.onAddDropdownCallback(rect2, this); + } + else if (this.onAddCallback != null) + { + this.onAddCallback(this); + } + else + { + AddItem(); + } + } + + EditorGUI.EndDisabledGroup(); + EditorGUI.BeginDisabledGroup(!CanSelect(selection) || !canRemove || + (this.onCanRemoveCallback != null && !this.onCanRemoveCallback(this))); + if (GUI.Button(position, Style.iconToolbarMinus, Style.preButton)) + { + if (this.onRemoveCallback != null) + { + this.onRemoveCallback(this); + } + else + { + Remove(selection.ToArray()); + list.serializedObject.ApplyModifiedProperties(); + list.serializedObject.Update(); + } + } + + EditorGUI.EndDisabledGroup(); + } + + private void DrawPaginationHeader(Rect rect) + { + var length = Length; + var pageCount = pagination.GetPageCount(length); + var num = Mathf.Clamp(pagination.page, 0, pageCount - 1); + if (num != pagination.page) + { + pagination.page = num; + HandleUtility.Repaint(); + } + + var position = new Rect(rect.xMin + 4f, rect.y - 1f, 17f, 14f); + var position2 = new Rect(position.xMax, rect.y - 1f, 17f, 14f); + var position3 = new Rect(position2.xMax, rect.y - 1f, 17f, 14f); + if (Event.current.type == EventType.Repaint) + { + Style.paginationHeader.Draw(rect, isHover: false, isActive: true, on: true, hasKeyboardFocus: false); + } + + pageInfoContent.text = $"{pagination.page + 1} / {pageCount}"; + var position4 = rect; + position4.width = Style.paginationText.CalcSize(pageInfoContent).x; + position4.x = rect.xMax - position4.width - 7f; + position4.y += 2f; + GUI.Label(position4, pageInfoContent, Style.paginationText); + if (GUI.Button(position, Style.iconPagePrev, Style.preButton)) + { + pagination.page = Mathf.Max(0, pagination.page - 1); + } + + if (EditorGUI.DropdownButton(position2, Style.iconPagePopup, FocusType.Passive, Style.preButton)) + { + GenericMenu genericMenu = new GenericMenu(); + for (int i = 0; i < pageCount; i++) + { + int num2 = i; + genericMenu.AddItem(new GUIContent($"Page {i + 1}"), i == pagination.page, OnPageDropDownSelect, + num2); + } + + genericMenu.DropDown(position2); + } + + if (GUI.Button(position3, Style.iconPageNext, Style.preButton)) + { + pagination.page = Mathf.Min(pageCount - 1, pagination.page + 1); + } + + pageSizeContent.text = length.ToString(); + GUIStyle pageSizeTextField = Style.pageSizeTextField; + Texture image = Style.listIcon.image; + float num3 = position3.xMax + 5f; + float num4 = position4.xMin - 5f - num3; + float num5 = image.width + 2; + float num6 = pageSizeTextField.CalcSize(pageSizeContent).x + 50f + num5; + Rect position5 = rect; + position5.x = num3 + (num4 - num6) / 2f; + position5.width = num6 - num5; + EditorGUI.BeginChangeCheck(); + EditorGUIUtility.labelWidth = num5; + EditorGUIUtility.SetIconSize(new Vector2(image.width, image.height)); + int value = EditorGUI.DelayedIntField(position5, Style.listIcon, pagination.pageSize, pageSizeTextField); + EditorGUIUtility.labelWidth = 0f; + EditorGUIUtility.SetIconSize(Vector2.zero); + if (EditorGUI.EndChangeCheck()) + { + pagination.pageSize = Mathf.Clamp(value, 0, length); + pagination.page = Mathf.Min(pagination.GetPageCount(length) - 1, pagination.page); + } + } + + private void OnPageDropDownSelect(object userData) + { + pagination.page = (int)userData; + } + + private void DispatchChange() + { + if (this.onChangedCallback != null) + { + this.onChangedCallback(this); + } + } + + private void HandleSingleContextClick(Event evt, SerializedProperty element) + { + selection.Select(IndexOf(element)); + GenericMenu genericMenu = new GenericMenu(); + if (element.isInstantiatedPrefab) + { + genericMenu.AddItem( + new GUIContent(string.Concat("Revert ", GetElementLabel(element, allowElementLabel: true).text, + " to Prefab")), on: false, selection.RevertValues, list); + genericMenu.AddSeparator(string.Empty); + } + + HandleSharedContextClick(evt, genericMenu, "Duplicate Array Element", "Delete Array Element", + "Move Array Element"); + } + + private void HandleMultipleContextClick(Event evt) + { + GenericMenu genericMenu = new GenericMenu(); + if (selection.CanRevert(list)) + { + genericMenu.AddItem(new GUIContent("Revert Values to Prefab"), on: false, selection.RevertValues, list); + genericMenu.AddSeparator(string.Empty); + } + + HandleSharedContextClick(evt, genericMenu, "Duplicate Array Elements", "Delete Array Elements", + "Move Array Elements"); + } + + private void HandleSharedContextClick(Event evt, GenericMenu menu, string duplicateLabel, string deleteLabel, + string moveLabel) + { + menu.AddItem(new GUIContent(duplicateLabel), on: false, HandleDuplicate, list); + menu.AddItem(new GUIContent(deleteLabel), on: false, HandleDelete, list); + if (doPagination) + { + int pageCount = pagination.GetPageCount(Length); + if (pageCount > 1) + { + for (int i = 0; i < pageCount; i++) + { + string text = $"{moveLabel}/Page {i + 1}"; + menu.AddItem(new GUIContent(text), i == pagination.page, HandleMoveElement, i); + } + } + } + + menu.ShowAsContext(); + evt.Use(); + } + + private void HandleMoveElement(object userData) + { + int num = (int)userData; + int page = pagination.page; + int num2 = pagination.pageSize; + int num3 = num * num2 - page * num2; + int num4 = ((num3 > 0) ? 1 : (-1)); + int length = Length; + int num5 = 0; + for (int i = 0; i < selection.Length; i++) + { + int num6 = selection[i] + num3; + num5 = ((num4 < 0) ? Mathf.Min(num5, num6) : Mathf.Max(num5, num6 - length)); + } + + num3 -= num5; + UpdateDragList(0f, 0, length); + List list = + new List(dragList.Elements.Where((DragElement t) => !selection.Contains(t.startIndex))); + selection.Sort(); + for (int j = 0; j < selection.Length; j++) + { + int num7 = selection[j]; + int indexFromSelection = dragList.GetIndexFromSelection(num7); + int index = Mathf.Clamp(num7 + num3, 0, list.Count); + list.Insert(index, dragList[indexFromSelection]); + } + + dragList.Elements = list.ToArray(); + ReorderDraggedElements(num4, 0, null); + pagination.page = num; + HandleUtility.Repaint(); + } + + private void HandleDelete(object userData) + { + selection.Delete(userData as SerializedProperty); + DispatchChange(); + } + + private void HandleDuplicate(object userData) + { + selection.Duplicate(userData as SerializedProperty); + DispatchChange(); + } + + private void HandleDragAndDrop(Rect rect, Event evt) + { + switch (evt.GetTypeForControl(dragDropControlID)) + { + case EventType.DragUpdated: + case EventType.DragPerform: + { + if (!GUI.enabled || !rect.Contains(evt.mousePosition)) + { + break; + } + + Object[] objectReferences = DragAndDrop.objectReferences; + Object[] array = new Object[1]; + bool flag = false; + Object[] array2 = objectReferences; + for (int i = 0; i < array2.Length; i++) + { + Object @object = (array[0] = array2[i]); + Object object2 = ValidateObjectDragAndDrop(array); + if (object2 != null) + { + DragAndDrop.visualMode = DragAndDropVisualMode.Copy; + if (evt.type == EventType.DragPerform) + { + AppendDragAndDropValue(object2); + flag = true; + DragAndDrop.activeControlID = 0; + } + else + { + DragAndDrop.activeControlID = dragDropControlID; + } + } + } + + if (flag) + { + GUI.changed = true; + DragAndDrop.AcceptDrag(); + } + + break; + } + case EventType.DragExited: + if (GUI.enabled) + { + HandleUtility.Repaint(); + } + + break; + } + } + + private Object ValidateObjectDragAndDrop(Object[] references) + { + if (this.onValidateDragAndDropCallback != null) + { + return this.onValidateDragAndDropCallback(references, this); + } + + if (surrogate.HasType) + { + return Internals.ValidateObjectDragAndDrop(references, null, surrogate.type, surrogate.exactType); + } + + return Internals.ValidateObjectDragAndDrop(references, list, null, exactType: false); + } + + private void AppendDragAndDropValue(Object obj) + { + if (this.onAppendDragDropCallback != null) + { + this.onAppendDragDropCallback(obj, this); + } + else if (surrogate.HasType) + { + surrogate.Invoke(AddItem(), obj, this); + } + else + { + Internals.AppendDragAndDropValue(obj, list); + } + + DispatchChange(); + } + + private void HandlePreSelection(Rect rect, Event evt) + { + if (evt.type == EventType.MouseDrag && draggable && GUIUtility.hotControl == controlID) + { + if (selection.Length > 0 && UpdateDragPosition(evt.mousePosition, rect, dragList)) + { + GUIUtility.keyboardControl = controlID; + dragging = true; + } + + evt.Use(); + } + } + + private void HandlePostSelection(Rect rect, Event evt) + { + switch (evt.GetTypeForControl(controlID)) + { + case EventType.MouseDown: + if (rect.Contains(evt.mousePosition) && IsSelectionButton(evt)) + { + int selectionIndex = GetSelectionIndex(evt.mousePosition); + if (CanSelect(selectionIndex)) + { + DoSelection(selectionIndex, + GUIUtility.keyboardControl == 0 || GUIUtility.keyboardControl == controlID || + evt.button == 2, evt); + } + else + { + selection.Clear(); + } + + HandleUtility.Repaint(); + } + + break; + case EventType.MouseUp: + if (!draggable) + { + selection.SelectWhenNoAction(pressIndex, evt); + if (this.onMouseUpCallback != null && + IsPositionWithinElement(evt.mousePosition, selection.Last)) + { + this.onMouseUpCallback(this); + } + } + else if (GUIUtility.hotControl == controlID) + { + evt.Use(); + if (dragging) + { + dragging = false; + ReorderDraggedElements(dragDirection, dragList.StartIndex, + delegate { dragList.SortByPosition(); }); + } + else + { + selection.SelectWhenNoAction(pressIndex, evt); + if (this.onMouseUpCallback != null) + { + this.onMouseUpCallback(this); + } + } + + GUIUtility.hotControl = 0; + } + + HandleUtility.Repaint(); + break; + case EventType.KeyDown: + if (GUIUtility.keyboardControl != controlID) + { + break; + } + + if (evt.keyCode == KeyCode.DownArrow && !dragging) + { + selection.Select(Mathf.Min(selection.Last + 1, Length - 1)); + evt.Use(); + } + else if (evt.keyCode == KeyCode.UpArrow && !dragging) + { + selection.Select(Mathf.Max(selection.Last - 1, 0)); + evt.Use(); + } + else if (evt.keyCode == KeyCode.Escape && GUIUtility.hotControl == controlID) + { + GUIUtility.hotControl = 0; + if (dragging) + { + dragging = false; + selection = beforeDragSelection; + } + + evt.Use(); + } + + break; + case EventType.MouseMove: + case EventType.MouseDrag: + break; + } + } + + private bool IsSelectionButton(Event evt) + { + if (evt.button != 0) + { + return evt.button == 2; + } + + return true; + } + + private void DoSelection(int index, bool setKeyboardControl, Event evt) + { + if (multipleSelection) + { + selection.AppendWithAction(pressIndex = index, evt); + } + else + { + selection.Select(pressIndex = index); + } + + if (this.onSelectCallback != null) + { + this.onSelectCallback(this); + } + + if (draggable) + { + dragging = false; + dragPosition = (pressPosition = evt.mousePosition.y); + pagination.GetVisibleRange(Length, out var start, out var end); + UpdateDragList(dragPosition, start, end); + selection.Trim(start, end); + beforeDragSelection = selection.Clone(); + GUIUtility.hotControl = controlID; + } + + if (setKeyboardControl) + { + GUIUtility.keyboardControl = controlID; + } + + evt.Use(); + } + + private void UpdateDragList(float dragPosition, int start, int end) + { + dragList.Resize(start, end - start); + for (int i = start; i < end; i++) + { + SerializedProperty arrayElementAtIndex = list.GetArrayElementAtIndex(i); + Rect rect = elementRects[i]; + DragElement dragElement = default(DragElement); + dragElement.property = arrayElementAtIndex; + dragElement.dragOffset = dragPosition - rect.y; + dragElement.rect = rect; + dragElement.desiredRect = rect; + dragElement.selected = selection.Contains(i); + dragElement.startIndex = i; + DragElement value = dragElement; + dragList[i - start] = value; + } + + dragList.SortByIndex(); + } + + private bool UpdateDragPosition(Vector2 position, Rect bounds, DragList dragList) + { + int index = 0; + int index2 = selection.Length - 1; + float dragOffset = dragList[index].dragOffset; + float num = dragList[index2].rect.height - dragList[index2].dragOffset; + dragPosition = Mathf.Clamp(position.y, bounds.yMin + dragOffset, bounds.yMax - num); + if (Mathf.Abs(dragPosition - pressPosition) > 1f) + { + dragDirection = (int)Mathf.Sign(dragPosition - pressPosition); + return true; + } + + return false; + } + + private void ReorderDraggedElements(int direction, int offset, Action sortList) + { + dragList.RecordState(); + sortList?.Invoke(); + selection.Sort(delegate(int a, int b) + { + int indexFromSelection2 = dragList.GetIndexFromSelection(a); + int indexFromSelection3 = dragList.GetIndexFromSelection(b); + return (direction <= 0) + ? indexFromSelection3.CompareTo(indexFromSelection2) + : indexFromSelection2.CompareTo(indexFromSelection3); + }); + int num = selection.Length; + while (--num > -1) + { + int indexFromSelection = dragList.GetIndexFromSelection(selection[num]); + int num2 = indexFromSelection + offset; + selection[num] = num2; + list.MoveArrayElement(dragList[indexFromSelection].startIndex, num2); + } + + dragList.RestoreState(list); + ApplyReorder(); + } + + private void ApplyReorder() + { + list.serializedObject.ApplyModifiedProperties(); + list.serializedObject.Update(); + if (this.onReorderCallback != null) + { + this.onReorderCallback(this); + } + + DispatchChange(); + } + + private int GetSelectionIndex(Vector2 position) + { + pagination.GetVisibleRange(elementRects.Length, out var start, out var end); + for (int i = start; i < end; i++) + { + Rect rect = elementRects[i]; + if (rect.Contains(position) || (i == 0 && position.y <= rect.yMin) || + (i == end - 1 && position.y >= rect.yMax)) + { + return i; + } + } + + return -1; + } + + private bool CanSelect(ListSelection selection) + { + if (selection.Length <= 0) + { + return false; + } + + return selection.All((int s) => CanSelect(s)); + } + + private bool CanSelect(int index) + { + if (index >= 0) + { + return index < Length; + } + + return false; + } + + private bool CanSelect(Vector2 position) + { + if (selection.Length <= 0) + { + return false; + } + + return selection.Any((int s) => IsPositionWithinElement(position, s)); + } + + private bool IsPositionWithinElement(Vector2 position, int index) + { + if (!CanSelect(index)) + { + return false; + } + + return elementRects[index].Contains(position); + } + + private bool IsElementExpandable(SerializedProperty element) + { + switch (elementDisplayType) + { + case ElementDisplayType.Auto: + if (element.hasVisibleChildren) + { + return IsTypeExpandable(element.propertyType); + } + + return false; + case ElementDisplayType.Expandable: + return true; + case ElementDisplayType.SingleLine: + return false; + default: + return false; + } + } + + private bool IsTypeExpandable(SerializedPropertyType type) + { + switch (type) + { + case SerializedPropertyType.Generic: + case SerializedPropertyType.Vector4: + case SerializedPropertyType.ArraySize: + case SerializedPropertyType.Quaternion: + return true; + default: + return false; + } + } + } +} \ No newline at end of file diff --git a/Tools~/Process/Process.Unity/Script/RainbowFolders/Borodar.RainbowCore/CoreEditorUtility.cs b/Tools~/Process/Process.Unity/Script/RainbowFolders/Borodar.RainbowCore/CoreEditorUtility.cs index c9f78668..5f6c7a4c 100644 --- a/Tools~/Process/Process.Unity/Script/RainbowFolders/Borodar.RainbowCore/CoreEditorUtility.cs +++ b/Tools~/Process/Process.Unity/Script/RainbowFolders/Borodar.RainbowCore/CoreEditorUtility.cs @@ -7,95 +7,153 @@ namespace AIO.RainbowCore { - internal static class CoreEditorUtility - { - public static readonly Color POPUP_BORDER_CLR_FREE = new Color(0.51f, 0.51f, 0.51f); - - public static readonly Color POPUP_BORDER_CLR_PRO = new Color(0.13f, 0.13f, 0.13f); - - public static readonly Color POPUP_BACKGROUND_CLR_FREE = new Color(0.83f, 0.83f, 0.83f); - - public static readonly Color POPUP_BACKGROUND_CLR_PRO = new Color(0.18f, 0.18f, 0.18f); - - public static readonly Color SEPARATOR_CLR_1_FREE = new Color(0.65f, 0.65f, 0.65f, 1f); - - public static readonly Color SEPARATOR_CLR_2_FREE = new Color(0.9f, 0.9f, 0.9f, 1f); - - public static readonly Color SEPARATOR_CLR_1_PRO = new Color(0.13f, 0.13f, 0.13f, 1f); - - public static readonly Color SEPARATOR_CLR_2_PRO = new Color(0.22f, 0.22f, 0.22f, 1f); - - public static void CreateAsset(string baseName, string forcedPath = "") where T : ScriptableObject - { - if (baseName.Contains("/")) - { - throw new ArgumentException("Base name should not contain slashes"); - } - T val = ScriptableObject.CreateInstance(); - string text; - if (!string.IsNullOrEmpty(forcedPath)) - { - text = forcedPath; - Directory.CreateDirectory(forcedPath); - } - else - { - text = AssetDatabase.GetAssetPath(Selection.activeObject); - if (string.IsNullOrEmpty(text)) - { - text = "Assets"; - } - else if (Path.GetExtension(text) != string.Empty) - { - text = text.Replace(Path.GetFileName(text), string.Empty); - } - } - string path = AssetDatabase.GenerateUniqueAssetPath(string.Concat(text, "/", baseName, ".asset")); - AssetDatabase.CreateAsset(val, path); - AssetDatabase.SaveAssets(); - EditorUtility.FocusProjectWindow(); - Selection.activeObject = val; - } - - public static IEnumerable GetAllWindowsByType(string type) - { - return from obj in Resources.FindObjectsOfTypeAll(typeof(EditorWindow)) - where obj.GetType().ToString() == type - select (EditorWindow)obj; - } - - public static bool SearchField(ref string query, ref Enum filter, Enum defaultFilter, params GUILayoutOption[] options) - { - string value = query; - Enum objB = filter; - bool result = false; - GUILayout.BeginHorizontal(); - Rect rect = GUILayoutUtility.GetRect(GUIContent.none, "ToolbarSeachTextFieldPopup", options); - rect.width -= 18f; - Rect position = rect; - position.width = 20f; - filter = EditorGUI.EnumPopup(position, filter, "label"); - if (!object.Equals(filter, objB)) - { - result = true; - } - query = EditorGUI.TextField(rect, "", query, "ToolbarSeachTextFieldPopup"); - if (query != null && !query.Equals(value)) - { - result = true; - } - Rect position2 = rect; - position2.x += rect.width; - position2.width = 18f; - if (GUI.Button(position2, "", "ToolbarSeachCancelButton")) - { - query = string.Empty; - filter = defaultFilter; - result = true; - GUIUtility.keyboardControl = 0; - } - GUILayout.EndHorizontal(); - return result; - } - } -} + internal static class CoreEditorUtility + { + public static readonly Color POPUP_BORDER_CLR_FREE = new Color(0.51f, 0.51f, 0.51f); + + public static readonly Color POPUP_BORDER_CLR_PRO = new Color(0.13f, 0.13f, 0.13f); + + public static readonly Color POPUP_BACKGROUND_CLR_FREE = new Color(0.83f, 0.83f, 0.83f); + + public static readonly Color POPUP_BACKGROUND_CLR_PRO = new Color(0.18f, 0.18f, 0.18f); + + public static readonly Color SEPARATOR_CLR_1_FREE = new Color(0.65f, 0.65f, 0.65f, 1f); + + public static readonly Color SEPARATOR_CLR_2_FREE = new Color(0.9f, 0.9f, 0.9f, 1f); + + public static readonly Color SEPARATOR_CLR_1_PRO = new Color(0.13f, 0.13f, 0.13f, 1f); + + public static readonly Color SEPARATOR_CLR_2_PRO = new Color(0.22f, 0.22f, 0.22f, 1f); + + public static void CreateAsset(string baseName, string forcedPath = "") where T : ScriptableObject + { + if (baseName.Contains("/")) + { + throw new ArgumentException("Base name should not contain slashes"); + } + + T val = ScriptableObject.CreateInstance(); + string text; + if (!string.IsNullOrEmpty(forcedPath)) + { + text = forcedPath; + Directory.CreateDirectory(forcedPath); + } + else + { + text = AssetDatabase.GetAssetPath(Selection.activeObject); + if (string.IsNullOrEmpty(text)) + { + text = "Assets"; + } + else if (Path.GetExtension(text) != string.Empty) + { + text = text.Replace(Path.GetFileName(text), string.Empty); + } + } + + string path = AssetDatabase.GenerateUniqueAssetPath(string.Concat(text, "/", baseName, ".asset")); + AssetDatabase.CreateAsset(val, path); + AssetDatabase.SaveAssets(); + EditorUtility.FocusProjectWindow(); + Selection.activeObject = val; + } + + public static IEnumerable GetAllWindowsByType(string type) + { + return from obj in Resources.FindObjectsOfTypeAll(typeof(EditorWindow)) + where obj.GetType().ToString() == type + select (EditorWindow)obj; + } + + private static GUIStyle ToolbarSearchTextFieldPopup + { + get + { + if (!(_ToolbarSearchTextFieldPopup is null)) return _ToolbarSearchTextFieldPopup; + if (int.TryParse(Application.unityVersion.Split('.')[0], out var ver)) + { + switch (ver) + { + case 2023: + _ToolbarSearchTextFieldPopup = new GUIStyle("ToolbarSearchTextFieldPopup"); + break; + default: + _ToolbarSearchTextFieldPopup = new GUIStyle("ToolbarSeachTextFieldPopup"); + break; + } + } + else _ToolbarSearchTextFieldPopup = GUIStyle.none; + + return _ToolbarSearchTextFieldPopup; + } + } + + private static GUIStyle _ToolbarSearchTextFieldPopup; + + private static GUIStyle ToolbarSearchCancelButton + { + get + { + if (!(_ToolbarSearchCancelButton is null)) return _ToolbarSearchCancelButton; + if (int.TryParse(Application.unityVersion.Split('.')[0], out var ver)) + { + switch (ver) + { + case 2023: + _ToolbarSearchCancelButton = new GUIStyle("ToolbarSearchCancelButton"); + break; + default: + _ToolbarSearchCancelButton = new GUIStyle("ToolbarSeachCancelButton"); + break; + } + } + else _ToolbarSearchCancelButton = GUIStyle.none; + + return _ToolbarSearchCancelButton; + } + } + + private static GUIStyle _ToolbarSearchCancelButton; + + + public static bool SearchField(ref string query, ref Enum filter, Enum defaultFilter, + params GUILayoutOption[] options) + { + var value = query; + var objB = filter; + var result = false; + GUILayout.BeginHorizontal(); + //"ToolbarSearchTextFieldPopup" + var rect = GUILayoutUtility.GetRect(GUIContent.none, ToolbarSearchTextFieldPopup, options); + rect.width -= 18f; + var position = rect; + position.width = 20f; + filter = EditorGUI.EnumPopup(position, filter, "label"); + if (!object.Equals(filter, objB)) + { + result = true; + } + + query = EditorGUI.TextField(rect, "", query, ToolbarSearchTextFieldPopup); + if (query != null && !query.Equals(value)) + { + result = true; + } + + var position2 = rect; + position2.x += rect.width; + position2.width = 18f; + if (GUI.Button(position2, "", ToolbarSearchCancelButton)) + { + query = string.Empty; + filter = defaultFilter; + result = true; + GUIUtility.keyboardControl = 0; + } + + GUILayout.EndHorizontal(); + return result; + } + } +} \ No newline at end of file diff --git a/Tools~/Process/Process.Unity/Script/RainbowFolders/Borodar.RainbowFolders.Settings/ProjectRuleDrawer.cs b/Tools~/Process/Process.Unity/Script/RainbowFolders/Borodar.RainbowFolders.Settings/ProjectRuleDrawer.cs index e03d44ed..54c3bf0f 100644 --- a/Tools~/Process/Process.Unity/Script/RainbowFolders/Borodar.RainbowFolders.Settings/ProjectRuleDrawer.cs +++ b/Tools~/Process/Process.Unity/Script/RainbowFolders/Borodar.RainbowFolders.Settings/ProjectRuleDrawer.cs @@ -1,7 +1,6 @@ using System; using AIO.RainbowCore; using UnityEditor; - using UnityEngine; namespace AIO.RainbowFolders.Settings @@ -77,19 +76,14 @@ public SerializedItemWrapper(SerializedProperty property) public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { - if (!property.FindPropertyRelative("IsHidden").boolValue) - { - Rect originalPosition = position; - SerializedItemWrapper item = new SerializedItemWrapper(property); - EditorGUI.BeginChangeCheck(); - DrawLabels(ref position, item); - DrawValues(ref position, originalPosition, item); - DrawPreview(ref position, originalPosition, item); - if (EditorGUI.EndChangeCheck()) - { - property.serializedObject.ApplyModifiedProperties(); - } - } + if (property.FindPropertyRelative("IsHidden").boolValue) return; + var originalPosition = position; + var item = new SerializedItemWrapper(property); + EditorGUI.BeginChangeCheck(); + DrawLabels(ref position, item); + DrawValues(ref position, originalPosition, item); + DrawPreview(ref position, originalPosition, item); + if (EditorGUI.EndChangeCheck()) property.serializedObject.ApplyModifiedProperties(); } public override float GetPropertyHeight(SerializedProperty property, GUIContent label) @@ -98,6 +92,7 @@ public override float GetPropertyHeight(SerializedProperty property, GUIContent { return 0f; } + SerializedProperty serializedProperty = property.FindPropertyRelative("IconType"); SerializedProperty serializedProperty2 = property.FindPropertyRelative("BackgroundType"); bool num = serializedProperty.intValue == 1; @@ -107,10 +102,12 @@ public override float GetPropertyHeight(SerializedProperty property, GUIContent { num2 += 32f; } + if (flag) { num2 += 16f; } + return num2; } @@ -119,8 +116,10 @@ private static void DrawLabels(ref Rect position, SerializedItemWrapper item) position.y += 8f; position.width = 92f; position.height = 16f; - ProjectRule.KeyType keyType = (ProjectRule.KeyType)Enum.GetValues(typeof(ProjectRule.KeyType)).GetValue(item.FolderKeyType.enumValueIndex); - item.FolderKeyType.enumValueIndex = (int)(ProjectRule.KeyType)(object)EditorGUI.EnumPopup(position, keyType); + ProjectRule.KeyType keyType = (ProjectRule.KeyType)Enum.GetValues(typeof(ProjectRule.KeyType)) + .GetValue(item.FolderKeyType.enumValueIndex); + item.FolderKeyType.enumValueIndex = + (int)(ProjectRule.KeyType)(object)EditorGUI.EnumPopup(position, keyType); position.y += 20f; EditorGUI.LabelField(position, "Priority"); position.y += 20f; @@ -132,6 +131,7 @@ private static void DrawLabels(ref Rect position, SerializedItemWrapper item) position.y += 17f; EditorGUI.LabelField(position, "x64"); } + position.y += 17f; EditorGUI.LabelField(position, "Recursive"); position.y += 20f; @@ -141,6 +141,7 @@ private static void DrawLabels(ref Rect position, SerializedItemWrapper item) position.y += 17f; EditorGUI.LabelField(position, "x16"); } + position.y += 17f; EditorGUI.LabelField(position, "Recursive"); } @@ -163,6 +164,7 @@ private static void DrawValues(ref Rect position, Rect originalPosition, Seriali position.y += 17f; EditorGUI.PropertyField(position, item.LargeIcon, GUIContent.none); } + position.y += 16f + (EditorGUIUtility.isProSkin ? 0f : 1f); EditorGUI.PropertyField(position, item.IconRecursive, GUIContent.none); position.y += 20f; @@ -172,6 +174,7 @@ private static void DrawValues(ref Rect position, Rect originalPosition, Seriali position.y += 17f; EditorGUI.PropertyField(position, item.Background, GUIContent.none); } + position.y += 16f + (EditorGUIUtility.isProSkin ? 0f : 1f); EditorGUI.PropertyField(position, item.BackgroundRecursive, GUIContent.none); } @@ -197,17 +200,20 @@ private static void DrawPreview(ref Rect position, Rect originalPosition, Serial } } } - if (texture2D == null) + + if (texture2D is null) { texture2D = ProjectEditorUtility.GetDefaultFolderIcon(); } - if (texture2D2 == null) + + if (texture2D2 is null) { texture2D2 = ProjectEditorUtility.GetDefaultFolderIcon(); } + position.x += position.width + 8f; position.y = originalPosition.y + 32f + 1f + 8f; - float num3 = (position.width = (position.height = 64f)); + var num3 = position.width = position.height = 64f; GUI.DrawTexture(position, texture2D2); position.y += 44f; num3 = (position.width = (position.height = 16f)); @@ -216,12 +222,15 @@ private static void DrawPreview(ref Rect position, Rect originalPosition, Serial position.width = 64f; if (item.HasBackground) { - Texture2D texture2D3 = (item.HasCustomBackground ? ((Texture2D)item.Background.objectReferenceValue) : CoreBackgroundsStorage.GetBackground(item.BackgroundType.intValue)); + Texture2D texture2D3 = (item.HasCustomBackground + ? ((Texture2D)item.Background.objectReferenceValue) + : CoreBackgroundsStorage.GetBackground(item.BackgroundType.intValue)); if (texture2D3 != null) { GUI.DrawTexture(position, texture2D3); } } + position.x += 13f; EditorGUI.LabelField(position, "Folder"); } @@ -238,6 +247,7 @@ private static void DrawIconPopupMenu(Rect rect, SerializedProperty property, bo { obj = "Custom"; } + string text = (string)obj; if (GUI.Button(rect, new GUIContent(text), "MiniPopup")) { @@ -245,7 +255,8 @@ private static void DrawIconPopupMenu(Rect rect, SerializedProperty property, bo } } - private static void DrawBackgroundPopupMenu(Rect rect, SerializedProperty property, bool hasCustomBackground, int backgroundType) + private static void DrawBackgroundPopupMenu(Rect rect, SerializedProperty property, bool hasCustomBackground, + int backgroundType) { object obj; if (!hasCustomBackground) @@ -257,6 +268,7 @@ private static void DrawBackgroundPopupMenu(Rect rect, SerializedProperty proper { obj = "Custom"; } + string text = (string)obj; if (GUI.Button(rect, new GUIContent(text), "MiniPopup")) { @@ -264,4 +276,4 @@ private static void DrawBackgroundPopupMenu(Rect rect, SerializedProperty proper } } } -} +} \ No newline at end of file diff --git a/Tools~/Process/Process.Unity/Script/RainbowFolders/Borodar.RainbowFolders.Settings/ProjectRuleset.cs b/Tools~/Process/Process.Unity/Script/RainbowFolders/Borodar.RainbowFolders.Settings/ProjectRuleset.cs index feda92ed..77799ce0 100644 --- a/Tools~/Process/Process.Unity/Script/RainbowFolders/Borodar.RainbowFolders.Settings/ProjectRuleset.cs +++ b/Tools~/Process/Process.Unity/Script/RainbowFolders/Borodar.RainbowFolders.Settings/ProjectRuleset.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.IO; using System.Linq; using AIO.RainbowCore; using UnityEditor; @@ -39,38 +40,30 @@ public static ProjectRuleset Instance { get { - if (_instance is null) + if (!(_instance is null)) return _instance; + try { - try + if (paths is null) { - if (paths is null) - { - paths = new List(); - foreach (var guid in AssetDatabase.FindAssets($"t:{nameof(ProjectRuleset)}", - new string[] { "Packages", "Assets" })) - { - paths.Add(AssetDatabase.GUIDToAssetPath(guid)); - } - } - - foreach (var expr in paths) + paths = new List(); + foreach (var guid in AssetDatabase.FindAssets($"t:{nameof(ProjectRuleset)}", + new string[] { "Packages", "Assets" })) { - _instance = AssetDatabase.LoadAssetAtPath(expr); - if (_instance is null) continue; - _instance.UpdateOrdinals(); - OnRulesetChange = - (Action)Delegate.Combine(OnRulesetChange, new Action(_instance.UpdateOrdinals)); - _instance.UpdateDictionaries(); - OnRulesetChange = - (Action)Delegate.Combine(OnRulesetChange, new Action(_instance.UpdateDictionaries)); - return _instance; + paths.Add(AssetDatabase.GUIDToAssetPath(guid)); } } - catch (Exception e) + + foreach (var expr in paths) { - // ignored + _instance = AssetDatabase.LoadAssetAtPath(expr); + if (_instance is null) continue; + break; } } + catch (Exception) + { + // ignored + } if (_instance is null) { @@ -79,7 +72,7 @@ public static ProjectRuleset Instance _instance = Resources.Load( $"Editor/RainbowFoldersRuleset/{nameof(ProjectRuleset)}"); } - catch (Exception e) + catch (Exception) { // ignored } @@ -87,18 +80,30 @@ public static ProjectRuleset Instance if (_instance is null) { - _instance = CreateInstance(); try { + _instance = CreateInstance(); + var path = Path.Combine(Application.dataPath, "Editor", "Gen", "Settings"); + if (!Directory.Exists(path)) Directory.CreateDirectory(path); AssetDatabase.CreateAsset(_instance, $"Assets/Editor/Gen/Settings/{nameof(ProjectRuleset)}.asset"); } - catch (Exception e) + catch (Exception) { // ignored } } + if (_instance is null) + throw new NullReferenceException( + $"Can't find {nameof(ProjectRuleset)} in project. Please try to reimport Rainbow Folders package."); + + _instance.UpdateOrdinals(); + OnRulesetChange = + (Action)Delegate.Combine(OnRulesetChange, new Action(_instance.UpdateOrdinals)); + _instance.UpdateDictionaries(); + OnRulesetChange = + (Action)Delegate.Combine(OnRulesetChange, new Action(_instance.UpdateDictionaries)); return _instance; } } @@ -261,7 +266,7 @@ public void ChangeRuleBackgroundByPath(string path, CoreBackground background) private void UpdateOrdinals() { - for (int i = 0; i < Rules.Count; i++) + for (var i = 0; i < Rules.Count; i++) { Rules[i].Ordinal = i; } diff --git a/Tools~/Process/Process.Unity/Script/RainbowFolders/Borodar.RainbowFolders.Settings/ProjectRulesetEditor.cs b/Tools~/Process/Process.Unity/Script/RainbowFolders/Borodar.RainbowFolders.Settings/ProjectRulesetEditor.cs index 80340307..de48f894 100644 --- a/Tools~/Process/Process.Unity/Script/RainbowFolders/Borodar.RainbowFolders.Settings/ProjectRulesetEditor.cs +++ b/Tools~/Process/Process.Unity/Script/RainbowFolders/Borodar.RainbowFolders.Settings/ProjectRulesetEditor.cs @@ -59,15 +59,21 @@ protected void OnEnable() pageSize = 10 }; _reorderableList.onChangedCallback += delegate { OnRulesetChange(); }; - Undo.undoRedoPerformed = (Undo.UndoRedoCallback)Delegate.Remove(Undo.undoRedoPerformed, new Undo.UndoRedoCallback(OnRulesetChange)); - Undo.undoRedoPerformed = (Undo.UndoRedoCallback)Delegate.Combine(Undo.undoRedoPerformed, new Undo.UndoRedoCallback(OnRulesetChange)); + Undo.undoRedoPerformed = + (Undo.UndoRedoCallback)Delegate.Remove(Undo.undoRedoPerformed, + new Undo.UndoRedoCallback(OnRulesetChange)); + Undo.undoRedoPerformed = + (Undo.UndoRedoCallback)Delegate.Combine(Undo.undoRedoPerformed, + new Undo.UndoRedoCallback(OnRulesetChange)); } protected void OnDisable() { EDITORS.Remove(this); ClearHiddenFlags(); - Undo.undoRedoPerformed = (Undo.UndoRedoCallback)Delegate.Remove(Undo.undoRedoPerformed, new Undo.UndoRedoCallback(OnRulesetChange)); + Undo.undoRedoPerformed = + (Undo.UndoRedoCallback)Delegate.Remove(Undo.undoRedoPerformed, + new Undo.UndoRedoCallback(OnRulesetChange)); } public override void OnInspectorGUI() @@ -87,7 +93,7 @@ public override void OnInspectorGUI() DrawSearchByKeyPanel(ForceUpdate); break; default: - throw new ArgumentOutOfRangeException("SearchTab", SearchTab, null); + throw new ArgumentOutOfRangeException($"SearchTab", SearchTab, null); } if (!string.IsNullOrEmpty(_warningMessage)) @@ -110,53 +116,49 @@ private static void OnRulesetChange() private void DrawSearchByFolderPanel(bool forceUpdate) { - DefaultAsset asset = Asset; + var asset = Asset; Asset = (DefaultAsset)EditorGUILayout.ObjectField(Asset, typeof(DefaultAsset), false); - if (forceUpdate || !(Asset == asset)) + if (!forceUpdate && Asset == asset) return; + if (Asset is null) { - if (Asset == null) - { - ClearHiddenFlags(); - } - else - { - ApplyHiddenFlagsByAsset(); - } + ClearHiddenFlags(); + } + else + { + ApplyHiddenFlagsByAsset(); } } private void DrawSearchByKeyPanel(bool forceUpdate) { EditorGUILayout.BeginHorizontal(); - bool flag = CoreEditorUtility.SearchField(ref _query, ref _filter, Filter.All); + var flag = CoreEditorUtility.SearchField(ref _query, ref _filter, Filter.All); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); - if (!object.Equals(_filter, Filter.All)) + if (!Equals(_filter, Filter.All)) { - Rect rect = GUILayoutUtility.GetRect(GUIContent.none, "MiniLabel"); + var rect = GUILayoutUtility.GetRect(GUIContent.none, "MiniLabel"); rect.y += 1f; rect.width = 55f; GUI.Label(rect, $"➔ {_filter}", "MiniLabel"); } GUILayout.FlexibleSpace(); - bool matchCase = _matchCase; + var matchCase = _matchCase; _matchCase = EditorGUILayout.ToggleLeft("Match case", _matchCase, "MiniLabel", GUILayout.Width(83f)); - bool flag2 = _matchCase != matchCase; - bool useRegex = _useRegex; + var flag2 = _matchCase != matchCase; + var useRegex = _useRegex; _useRegex = EditorGUILayout.ToggleLeft("Regex", _useRegex, "MiniLabel", GUILayout.Width(58f)); - bool flag3 = _useRegex != useRegex; + var flag3 = _useRegex != useRegex; EditorGUILayout.EndHorizontal(); - if (forceUpdate || flag || flag2 || flag3) - { - _warningMessage = string.Empty; - ApplyFilters(); - } + if (!forceUpdate && !flag && !flag2 && !flag3) return; + _warningMessage = string.Empty; + ApplyFilters(); } private void ApplyFilters() { - bool flag = object.Equals(Filter.All, _filter); + var flag = Equals(Filter.All, _filter); if (string.IsNullOrEmpty(_query) && flag) { ClearHiddenFlags(); @@ -169,34 +171,34 @@ private void ApplyFilters() private void ClearHiddenFlags() { - if (_foldersProperty != null) + if (_foldersProperty is null) return; + for (var i = 0; i < _foldersProperty.arraySize; i++) { - for (int i = 0; i < _foldersProperty.arraySize; i++) - { - _foldersProperty.GetArrayElementAtIndex(i).FindPropertyRelative("IsHidden").boolValue = false; - } - - _foldersProperty.serializedObject.ApplyModifiedProperties(); - _reorderableList.canAdd = true; - _reorderableList.headerHeight = 4f; - _reorderableList.paginate = true; + _foldersProperty.GetArrayElementAtIndex(i).FindPropertyRelative("IsHidden").boolValue = false; } + + _foldersProperty.serializedObject.ApplyModifiedProperties(); + _reorderableList.canAdd = true; + _reorderableList.headerHeight = 4f; + _reorderableList.paginate = true; } private void ApplyHiddenFlagsByAsset() { - string assetPath = AssetDatabase.GetAssetPath(Asset); - string fileName = Path.GetFileName(assetPath); - foreach (ProjectRule rule in ((ProjectRuleset)base.target).Rules) + var assetPath = AssetDatabase.GetAssetPath(Asset); + var fileName = Path.GetFileName(assetPath); + foreach (var rule in ((ProjectRuleset)target).Rules) { bool flag; switch (rule.Type) { case ProjectRule.KeyType.Name: - flag = rule.Key.Equals(fileName) || (rule.IsRecursive() && assetPath.Contains(string.Concat("/", rule.Key, "/"))); + flag = rule.Key.Equals(fileName) || + (rule.IsRecursive() && assetPath.Contains(string.Concat("/", rule.Key, "/"))); break; case ProjectRule.KeyType.Path: - flag = rule.Key.Equals(assetPath) || (rule.IsRecursive() && assetPath.StartsWith(string.Concat(rule.Key, "/"))); + flag = rule.Key.Equals(assetPath) || + (rule.IsRecursive() && assetPath.StartsWith(string.Concat(rule.Key, "/"))); break; default: throw new ArgumentOutOfRangeException(); @@ -212,29 +214,32 @@ private void ApplyHiddenFlagsByAsset() private void ApplyHiddenFlagsByKey() { - Regex regex = (_useRegex ? MakeRegexFromQuery() : null); - for (int i = 0; i < _foldersProperty.arraySize; i++) + var regex = _useRegex ? MakeRegexFromQuery() : null; + for (var i = 0; i < _foldersProperty.arraySize; i++) { - SerializedProperty arrayElementAtIndex = _foldersProperty.GetArrayElementAtIndex(i); - SerializedProperty serializedProperty = arrayElementAtIndex.FindPropertyRelative("IsHidden"); - Enum filter = _filter; - if (filter is Filter) + var arrayElementAtIndex = _foldersProperty.GetArrayElementAtIndex(i); + var serializedProperty = arrayElementAtIndex.FindPropertyRelative("IsHidden"); + if (_filter is Filter filter) { - switch ((Filter)(object)filter) + switch (filter) { case Filter.All: serializedProperty.boolValue = !KeyContainsQuery(arrayElementAtIndex, regex); continue; case Filter.Name: - serializedProperty.boolValue = !KeyHasSameType(arrayElementAtIndex, ProjectRule.KeyType.Name) || !KeyContainsQuery(arrayElementAtIndex, regex); + serializedProperty.boolValue = + !KeyHasSameType(arrayElementAtIndex, ProjectRule.KeyType.Name) || + !KeyContainsQuery(arrayElementAtIndex, regex); continue; case Filter.Path: - serializedProperty.boolValue = !KeyHasSameType(arrayElementAtIndex, ProjectRule.KeyType.Path) || !KeyContainsQuery(arrayElementAtIndex, regex); + serializedProperty.boolValue = + !KeyHasSameType(arrayElementAtIndex, ProjectRule.KeyType.Path) || + !KeyContainsQuery(arrayElementAtIndex, regex); continue; } } - throw new ArgumentOutOfRangeException("_filter", _filter, null); + throw new ArgumentOutOfRangeException($"_filter", _filter, null); } _foldersProperty.serializedObject.ApplyModifiedProperties(); @@ -245,7 +250,7 @@ private void ApplyHiddenFlagsByKey() private Regex MakeRegexFromQuery() { - RegexOptions options = ((!_matchCase) ? RegexOptions.IgnoreCase : RegexOptions.None); + var options = !_matchCase ? RegexOptions.IgnoreCase : RegexOptions.None; try { return new Regex(_query, options); @@ -264,13 +269,13 @@ private static bool KeyHasSameType(SerializedProperty item, ProjectRule.KeyType private bool KeyContainsQuery(SerializedProperty item, Regex regex) { - string stringValue = item.FindPropertyRelative("Key").stringValue; + var stringValue = item.FindPropertyRelative("Key").stringValue; if (_useRegex) { return regex.Match(stringValue).Success; } - StringComparison comparisonType = (_matchCase ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase); + var comparisonType = _matchCase ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase; return stringValue.IndexOf(_query, comparisonType) >= 0; } @@ -278,11 +283,9 @@ private void DrawReorderableList() { EditorGUI.BeginChangeCheck(); _reorderableList.DoLayoutList(); - if (EditorGUI.EndChangeCheck()) - { - ProjectRuleset.OnRulesetChange(); - serializedObject.ApplyModifiedProperties(); - } + if (!EditorGUI.EndChangeCheck()) return; + ProjectRuleset.OnRulesetChange(); + serializedObject.ApplyModifiedProperties(); } } } \ No newline at end of file