Browse Source

Merge pull request #643 from stevehalliwell/ShowVariableList

Added ability to show variable list in the Flowchart Inspector
master
Steve Halliwell 7 years ago committed by GitHub
parent
commit
63d28329ad
  1. 29
      Assets/Fungus/Scripts/Editor/FlowchartEditor.cs
  2. 2
      Assets/Fungus/Scripts/Editor/FlowchartWindow.cs
  3. 21
      Assets/Fungus/Scripts/Editor/FungusEditorPreferences.cs
  4. 20
      Assets/Fungus/Scripts/Editor/VariableListAdaptor.cs

29
Assets/Fungus/Scripts/Editor/FlowchartEditor.cs

@ -82,13 +82,20 @@ namespace Fungus.EditorUtils
EditorWindow.GetWindow(typeof(FlowchartWindow), false, "Flowchart");
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
serializedObject.ApplyModifiedProperties();
//Show the variables in the flowchart inspector
GUILayout.Space(20);
DrawVariablesGUI(false, Mathf.FloorToInt(EditorGUIUtility.currentViewWidth) - VariableListAdaptor.ReorderListSkirts);
}
public virtual void DrawVariablesGUI()
public virtual void DrawVariablesGUI(bool showVariableToggleButton, int w)
{
serializedObject.Update();
@ -97,9 +104,10 @@ namespace Fungus.EditorUtils
if (t.Variables.Count == 0)
{
t.VariablesExpanded = true;
//showVariableToggleButton = true;
}
if (!t.VariablesExpanded)
if (showVariableToggleButton && !t.VariablesExpanded)
{
if (GUILayout.Button ("Variables (" + t.Variables.Count + ")", GUILayout.Height(24)))
{
@ -116,8 +124,6 @@ namespace Fungus.EditorUtils
{
Rect listRect = new Rect();
if (t.Variables.Count > 0)
{
// Remove any null variables from the list
// Can sometimes happen when upgrading to a new version of Fungus (if .meta GUID changes for a variable class)
for (int i = t.Variables.Count - 1; i >= 0; i--)
@ -129,19 +135,13 @@ namespace Fungus.EditorUtils
}
ReorderableListGUI.Title("Variables");
VariableListAdaptor adaptor = new VariableListAdaptor(variablesProp, 0);
VariableListAdaptor adaptor = new VariableListAdaptor(variablesProp, 0, w == 0 ? VariableListAdaptor.DefaultWidth : w);
ReorderableListFlags flags = ReorderableListFlags.DisableContextMenu | ReorderableListFlags.HideAddButton;
ReorderableListControl.DrawControlFromState(adaptor, null, flags);
listRect = GUILayoutUtility.GetLastRect();
}
else
{
GUILayoutUtility.GetRect(300, 24);
listRect = GUILayoutUtility.GetLastRect();
listRect.y += 20;
}
float plusWidth = 32;
float plusHeight = 24;
@ -156,7 +156,7 @@ namespace Fungus.EditorUtils
buttonRect.width -= 30;
}
if (GUI.Button (buttonRect, "Variables"))
if (showVariableToggleButton && GUI.Button(buttonRect, "Variables"))
{
t.VariablesExpanded = false;
}
@ -165,6 +165,9 @@ namespace Fungus.EditorUtils
Rect lastRect = buttonRect;
lastRect.x += 5;
lastRect.y += 5;
//this is not required, seems to be legacy that is hidden in the normal reorderable
if(showVariableToggleButton)
EditorGUI.Foldout(lastRect, true, "");
Rect plusRect = listRect;

2
Assets/Fungus/Scripts/Editor/FlowchartWindow.cs

@ -497,7 +497,7 @@ namespace Fungus.EditorUtils
GUILayout.Space(8);
FlowchartEditor flowchartEditor = Editor.CreateEditor (flowchart) as FlowchartEditor;
flowchartEditor.DrawVariablesGUI();
flowchartEditor.DrawVariablesGUI(true, 0);
DestroyImmediate(flowchartEditor);
Rect variableWindowRect = GUILayoutUtility.GetLastRect();

21
Assets/Fungus/Scripts/Editor/FungusEditorPreferences.cs

@ -1,5 +1,6 @@
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
namespace Fungus
{
@ -10,23 +11,27 @@ namespace Fungus
///
/// ref https://docs.unity3d.com/ScriptReference/PreferenceItem.html
/// </summary>
public class FungusEditorPreferences
[InitializeOnLoad]
public static class FungusEditorPreferences
{
// Have we loaded the prefs yet
private static bool prefsLoaded = false;
public static bool hideMushroomInHierarchy = false;
public static bool hideMushroomInHierarchy;
static FungusEditorPreferences()
{
LoadOnScriptLoad();
}
// Add preferences section named "My Preferences" to the Preferences Window
[PreferenceItem("Fungus")]
public static void PreferencesGUI()
{
// Load the preferences
if (!prefsLoaded)
{
hideMushroomInHierarchy = EditorPrefs.GetBool("hideMushroomInHierarchy", false);
prefsLoaded = true;
LoadOnScriptLoad();
}
// Preferences GUI
@ -38,6 +43,12 @@ namespace Fungus
EditorPrefs.SetBool("hideMushroomInHierarchy", hideMushroomInHierarchy);
}
}
public static void LoadOnScriptLoad()
{
hideMushroomInHierarchy = EditorPrefs.GetBool("hideMushroomInHierarchy", false);
prefsLoaded = true;
}
}
}
}

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

@ -14,9 +14,15 @@ namespace Fungus.EditorUtils
{
public class VariableListAdaptor : IReorderableListAdaptor {
public static readonly int DefaultWidth = 80 + 100 + 140 + 60;
public static readonly int ScrollSpacer = 8;
public static readonly int ReorderListSkirts = 70;
protected SerializedProperty _arrayProperty;
public float fixedItemHeight;
public int widthOfList;
public SerializedProperty this[int index] {
get { return _arrayProperty.GetArrayElementAtIndex(index); }
@ -26,7 +32,7 @@ namespace Fungus.EditorUtils
get { return _arrayProperty; }
}
public VariableListAdaptor(SerializedProperty arrayProperty, float fixedItemHeight) {
public VariableListAdaptor(SerializedProperty arrayProperty, float fixedItemHeight, int widthOfList) {
if (arrayProperty == null)
throw new ArgumentNullException("Array property was null.");
if (!arrayProperty.isArray)
@ -34,9 +40,10 @@ namespace Fungus.EditorUtils
this._arrayProperty = arrayProperty;
this.fixedItemHeight = fixedItemHeight;
this.widthOfList = widthOfList - ScrollSpacer;
}
public VariableListAdaptor(SerializedProperty arrayProperty) : this(arrayProperty, 0f) {
public VariableListAdaptor(SerializedProperty arrayProperty) : this(arrayProperty, 0f, DefaultWidth) {
}
public int Count {
@ -103,7 +110,14 @@ namespace Fungus.EditorUtils
return;
}
float[] widths = { 80, 100, 140, 60 };
int width = widthOfList;
int totalRatio = DefaultWidth;
float[] widths = { (80.0f/ totalRatio) * width,
(100.0f / totalRatio) * width,
(140.0f/ totalRatio) * width,
(60.0f/ totalRatio) * width };
Rect[] rects = new Rect[4];
for (int i = 0; i < 4; ++i)

Loading…
Cancel
Save