Skip to content

Commit

Permalink
Finally fixed editor drawing issues when using the ReorderableDrawer.…
Browse files Browse the repository at this point in the history
… Unity added a method "CanCacheInspectorGUI"! So no more strange animation overlap bugs

Fixed element naming when using "nameOverride" not showing the element index
Fixed some visual alignment issues
  • Loading branch information
foulston committed Oct 26, 2018
1 parent 85f3d63 commit 76a4f7b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
3 changes: 2 additions & 1 deletion List/Attributes/ReorderableAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ public ReorderableAttribute(bool add, bool remove, bool draggable, string elemen
this.add = add;
this.remove = remove;
this.draggable = draggable;
this.sortable = true;
this.elementNameProperty = elementNameProperty;
this.elementNameOverride = elementNameOverride;
this.elementIconPath = elementIconPath;

sortable = true;
}
}
}
9 changes: 7 additions & 2 deletions List/Editor/ReorderableDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@ public class ReorderableDrawer : PropertyDrawer {

private static Dictionary<int, ReorderableList> lists = new Dictionary<int, ReorderableList>();

public override bool CanCacheInspectorGUI(SerializedProperty property) {

return false;
}

public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {

ReorderableList list = GetList(property, attribute as ReorderableAttribute, ARRAY_PROPERTY_NAME);

return list != null ? list.GetHeight() : EditorGUIUtility.singleLineHeight;
}
}

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {

Expand Down Expand Up @@ -83,7 +88,7 @@ public static ReorderableList GetList(SerializedProperty property, ReorderableAt
list = new ReorderableList(array, attrib.add, attrib.remove, attrib.draggable, displayType, attrib.elementNameProperty, attrib.elementNameOverride, icon);
list.paginate = attrib.paginate;
list.pageSize = attrib.pageSize;
list.sortable = attrib.sortable;
list.sortable = attrib.sortable;
}
else {

Expand Down
16 changes: 9 additions & 7 deletions List/Editor/ReorderableList.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using System.Reflection;
using UnityEditor;
using UnityEngine;

Expand All @@ -16,6 +16,9 @@ public class ReorderableList {
private static int selectionHash = "ReorderableListSelection".GetHashCode();
private static int dragAndDropHash = "ReorderableListDragAndDrop".GetHashCode();

private const string EMPTY_LABEL = "List is Empty";
private const string ARRAY_ERROR = "{0} is not an Array!";

public enum ElementDisplayType {
Auto,
Expandable,
Expand Down Expand Up @@ -289,7 +292,7 @@ public void DoList(Rect rect, GUIContent label) {

if (!HasList) {

DrawEmpty(headerRect, label.text + " is not an Array!", GUIStyle.none, EditorStyles.helpBox);
DrawEmpty(headerRect, string.Format(ARRAY_ERROR, label.text), GUIStyle.none, EditorStyles.helpBox);
}
else {

Expand Down Expand Up @@ -350,7 +353,7 @@ public void DoList(Rect rect, GUIContent label) {
}
else {

DrawEmpty(elementBackgroundRect, "List is Empty", Style.boxBackground, Style.verticalLabel);
DrawEmpty(elementBackgroundRect, EMPTY_LABEL, Style.boxBackground, Style.verticalLabel);
}

Rect footerRect = rect;
Expand Down Expand Up @@ -979,9 +982,8 @@ private static string GetElementName(SerializedProperty element, string nameProp
if (path.EndsWith(arrayEndDelimeter)) {

int startIndex = path.LastIndexOf(arrayStartDelimeter) + 1;
const string space = " ";

return string.Format("{0} {1}", nameOverride, space, path.Substring(startIndex, path.Length - startIndex - 1));
return string.Format("{0} {1}", nameOverride, path.Substring(startIndex, path.Length - startIndex - 1));
}

return nameOverride;
Expand Down Expand Up @@ -1888,8 +1890,8 @@ static Style() {
elementBackground = new GUIStyle("RL Element");
elementBackground.border = new RectOffset(2, 3, 2, 3);
verticalLabel = new GUIStyle(EditorStyles.label);
verticalLabel.alignment = TextAnchor.MiddleLeft;
verticalLabel.contentOffset = new Vector2(10, -3);
verticalLabel.alignment = TextAnchor.UpperLeft;
verticalLabel.contentOffset = new Vector2(10, 3);
boxBackground = new GUIStyle("RL Background");
boxBackground.border = new RectOffset(6, 3, 3, 6);
preButton = new GUIStyle("RL FooterButton");
Expand Down
4 changes: 2 additions & 2 deletions List/ReorderableArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public T this[int index] {
get { return array[index]; }
set { array[index] = value; }
}

public int Length {

get { return array.Count; }
}

Expand Down

0 comments on commit 76a4f7b

Please sign in to comment.