Browse Source

Reorderable lists for commands and variables now use EditorGUI determined LineHeight

master
desktop-maesty/steve 7 years ago
parent
commit
c2e317ea5a
  1. 8
      Assets/Fungus/Scripts/Editor/CommandEditor.cs
  2. 42
      Assets/Fungus/Scripts/Editor/CommandListAdaptor.cs
  3. 6
      Assets/Fungus/Scripts/Editor/VariableListAdaptor.cs

8
Assets/Fungus/Scripts/Editor/CommandEditor.cs

@ -171,6 +171,14 @@ namespace Fungus.EditorUtils
drawHeaderCallback = (Rect rect) => drawHeaderCallback = (Rect rect) =>
{ {
EditorGUI.LabelField(rect, locSerProp.displayName); EditorGUI.LabelField(rect, locSerProp.displayName);
},
drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
{
EditorGUI.PropertyField(rect, locSerProp.GetArrayElementAtIndex(index));
},
elementHeightCallback = (int index) =>
{
return EditorGUI.GetPropertyHeight(locSerProp.GetArrayElementAtIndex(index), null, true);// + EditorGUIUtility.singleLineHeight;
} }
}; };

42
Assets/Fungus/Scripts/Editor/CommandListAdaptor.cs

@ -8,7 +8,8 @@ using UnityEditorInternal;
namespace Fungus.EditorUtils namespace Fungus.EditorUtils
{ {
public class CommandListAdaptor { public class CommandListAdaptor
{
public void DrawCommandList() public void DrawCommandList()
{ {
@ -32,29 +33,37 @@ namespace Fungus.EditorUtils
public float fixedItemHeight; public float fixedItemHeight;
public SerializedProperty this[int index] { public SerializedProperty this[int index]
{
get { return _arrayProperty.GetArrayElementAtIndex(index); } get { return _arrayProperty.GetArrayElementAtIndex(index); }
} }
public SerializedProperty arrayProperty { public SerializedProperty arrayProperty
{
get { return _arrayProperty; } get { return _arrayProperty; }
} }
public CommandListAdaptor(Block _block, SerializedProperty arrayProperty, float fixedItemHeight = 0) { public CommandListAdaptor(Block _block, SerializedProperty arrayProperty)
{
if (arrayProperty == null) if (arrayProperty == null)
throw new ArgumentNullException("Array property was null."); throw new ArgumentNullException("Array property was null.");
if (!arrayProperty.isArray) if (!arrayProperty.isArray)
throw new InvalidOperationException("Specified serialized propery is not an array."); throw new InvalidOperationException("Specified serialized propery is not an array.");
this._arrayProperty = arrayProperty; this._arrayProperty = arrayProperty;
this.fixedItemHeight = fixedItemHeight;
this.block = _block; this.block = _block;
list = new ReorderableList(arrayProperty.serializedObject, arrayProperty, true, true, false, false); list = new ReorderableList(arrayProperty.serializedObject, arrayProperty, true, true, false, false);
list.drawHeaderCallback = DrawHeader; list.drawHeaderCallback = DrawHeader;
list.drawElementCallback = DrawItem; list.drawElementCallback = DrawItem;
//list.elementHeightCallback = GetElementHeight;
} }
//private float GetElementHeight(int index)
//{
// return EditorGUI.GetPropertyHeight(this[index], null, true);// + EditorGUIUtility.singleLineHeight;
//}
private void DrawHeader(Rect rect) private void DrawHeader(Rect rect)
{ {
EditorGUI.LabelField(rect, new GUIContent("Commands")); EditorGUI.LabelField(rect, new GUIContent("Commands"));
@ -173,7 +182,8 @@ namespace Fungus.EditorUtils
// Command key and shift key is not pressed // Command key and shift key is not pressed
if (!EditorGUI.actionKey && !Event.current.shift) if (!EditorGUI.actionKey && !Event.current.shift)
{ {
BlockEditor.actionList.Add ( delegate { BlockEditor.actionList.Add(delegate
{
flowchart.SelectedCommands.Remove(command); flowchart.SelectedCommands.Remove(command);
flowchart.ClearSelectedCommands(); flowchart.ClearSelectedCommands();
}); });
@ -182,7 +192,8 @@ namespace Fungus.EditorUtils
// Command key pressed // Command key pressed
if (EditorGUI.actionKey) if (EditorGUI.actionKey)
{ {
BlockEditor.actionList.Add ( delegate { BlockEditor.actionList.Add(delegate
{
flowchart.SelectedCommands.Remove(command); flowchart.SelectedCommands.Remove(command);
}); });
Event.current.Use(); Event.current.Use();
@ -195,13 +206,15 @@ namespace Fungus.EditorUtils
// Left click and no command key // Left click and no command key
if (!shift && !EditorGUI.actionKey && Event.current.button == 0) if (!shift && !EditorGUI.actionKey && Event.current.button == 0)
{ {
BlockEditor.actionList.Add ( delegate { BlockEditor.actionList.Add(delegate
{
flowchart.ClearSelectedCommands(); flowchart.ClearSelectedCommands();
}); });
Event.current.Use(); Event.current.Use();
} }
BlockEditor.actionList.Add ( delegate { BlockEditor.actionList.Add(delegate
{
flowchart.AddSelectedCommand(command); flowchart.AddSelectedCommand(command);
}); });
@ -264,7 +277,8 @@ namespace Fungus.EditorUtils
for (int i = Math.Min(firstSelectedIndex, lastSelectedIndex); i < Math.Max(firstSelectedIndex, lastSelectedIndex); ++i) for (int i = Math.Min(firstSelectedIndex, lastSelectedIndex); i < Math.Max(firstSelectedIndex, lastSelectedIndex); ++i)
{ {
var selectedCommand = flowchart.SelectedBlock.CommandList[i]; var selectedCommand = flowchart.SelectedBlock.CommandList[i];
BlockEditor.actionList.Add ( delegate { BlockEditor.actionList.Add(delegate
{
flowchart.AddSelectedCommand(selectedCommand); flowchart.AddSelectedCommand(selectedCommand);
}); });
} }
@ -367,13 +381,5 @@ namespace Fungus.EditorUtils
GUI.backgroundColor = Color.white; GUI.backgroundColor = Color.white;
} }
public virtual float GetItemHeight(int index) {
return fixedItemHeight != 0f
? fixedItemHeight
: EditorGUI.GetPropertyHeight(this[index], GUIContent.none, false)
;
}
} }
} }

6
Assets/Fungus/Scripts/Editor/VariableListAdaptor.cs

@ -60,6 +60,12 @@ namespace Fungus.EditorUtils
list.onRemoveCallback = RemoveItem; list.onRemoveCallback = RemoveItem;
list.onAddCallback = AddButton; list.onAddCallback = AddButton;
list.onRemoveCallback = RemoveItem; list.onRemoveCallback = RemoveItem;
list.elementHeightCallback = GetElementHeight;
}
private float GetElementHeight(int index)
{
return /*EditorGUI.GetPropertyHeight(this[index], null, true) +*/ EditorGUIUtility.singleLineHeight;
} }
private void RemoveItem(ReorderableList list) private void RemoveItem(ReorderableList list)

Loading…
Cancel
Save