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. 46
      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) =>
{
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;
}
};

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

@ -8,7 +8,8 @@ using UnityEditorInternal;
namespace Fungus.EditorUtils
{
public class CommandListAdaptor {
public class CommandListAdaptor
{
public void DrawCommandList()
{
@ -32,29 +33,37 @@ namespace Fungus.EditorUtils
public float fixedItemHeight;
public SerializedProperty this[int index] {
public SerializedProperty this[int index]
{
get { return _arrayProperty.GetArrayElementAtIndex(index); }
}
public SerializedProperty arrayProperty {
public SerializedProperty arrayProperty
{
get { return _arrayProperty; }
}
public CommandListAdaptor(Block _block, SerializedProperty arrayProperty, float fixedItemHeight = 0) {
public CommandListAdaptor(Block _block, SerializedProperty arrayProperty)
{
if (arrayProperty == null)
throw new ArgumentNullException("Array property was null.");
if (!arrayProperty.isArray)
throw new InvalidOperationException("Specified serialized propery is not an array.");
this._arrayProperty = arrayProperty;
this.fixedItemHeight = fixedItemHeight;
this.block = _block;
list = new ReorderableList(arrayProperty.serializedObject, arrayProperty, true, true, false, false);
list.drawHeaderCallback = DrawHeader;
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)
{
EditorGUI.LabelField(rect, new GUIContent("Commands"));
@ -173,7 +182,8 @@ namespace Fungus.EditorUtils
// Command key and shift key is not pressed
if (!EditorGUI.actionKey && !Event.current.shift)
{
BlockEditor.actionList.Add ( delegate {
BlockEditor.actionList.Add(delegate
{
flowchart.SelectedCommands.Remove(command);
flowchart.ClearSelectedCommands();
});
@ -182,7 +192,8 @@ namespace Fungus.EditorUtils
// Command key pressed
if (EditorGUI.actionKey)
{
BlockEditor.actionList.Add ( delegate {
BlockEditor.actionList.Add(delegate
{
flowchart.SelectedCommands.Remove(command);
});
Event.current.Use();
@ -195,13 +206,15 @@ namespace Fungus.EditorUtils
// Left click and no command key
if (!shift && !EditorGUI.actionKey && Event.current.button == 0)
{
BlockEditor.actionList.Add ( delegate {
BlockEditor.actionList.Add(delegate
{
flowchart.ClearSelectedCommands();
});
Event.current.Use();
}
BlockEditor.actionList.Add ( delegate {
BlockEditor.actionList.Add(delegate
{
flowchart.AddSelectedCommand(command);
});
@ -210,7 +223,7 @@ namespace Fungus.EditorUtils
int lastSelectedIndex = -1;
if (flowchart.SelectedCommands.Count > 0)
{
if ( flowchart.SelectedBlock != null)
if (flowchart.SelectedBlock != null)
{
for (int i = 0; i < flowchart.SelectedBlock.CommandList.Count; i++)
{
@ -224,7 +237,7 @@ namespace Fungus.EditorUtils
}
}
}
for (int i = flowchart.SelectedBlock.CommandList.Count - 1; i >=0; i--)
for (int i = flowchart.SelectedBlock.CommandList.Count - 1; i >= 0; i--)
{
Command commandInBlock = flowchart.SelectedBlock.CommandList[i];
foreach (Command selectedCommand in flowchart.SelectedCommands)
@ -264,7 +277,8 @@ namespace Fungus.EditorUtils
for (int i = Math.Min(firstSelectedIndex, lastSelectedIndex); i < Math.Max(firstSelectedIndex, lastSelectedIndex); ++i)
{
var selectedCommand = flowchart.SelectedBlock.CommandList[i];
BlockEditor.actionList.Add ( delegate {
BlockEditor.actionList.Add(delegate
{
flowchart.AddSelectedCommand(selectedCommand);
});
}
@ -367,13 +381,5 @@ namespace Fungus.EditorUtils
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.onAddCallback = AddButton;
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)

Loading…
Cancel
Save