From 0432b3cb8ce7879e632f09855ddf1ca7efb5a4e8 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Fri, 25 Jul 2014 15:44:15 +0100 Subject: [PATCH] Highlight command in inspector when clicked in editor --- Assets/Fungus/Editor/FungusCommandEditor.cs | 5 +++- Assets/Fungus/Editor/FungusEditorWindow.cs | 29 +++++++++++++++++++-- Assets/Fungus/VisualScripting/Sequence.cs | 5 ++-- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/Assets/Fungus/Editor/FungusCommandEditor.cs b/Assets/Fungus/Editor/FungusCommandEditor.cs index 9e0de73d..ad26320d 100644 --- a/Assets/Fungus/Editor/FungusCommandEditor.cs +++ b/Assets/Fungus/Editor/FungusCommandEditor.cs @@ -8,6 +8,8 @@ using Fungus; public class FungusCommandEditor : Editor { + public static FungusCommand selectedCommand; + public override void OnInspectorGUI() { Rect rect = EditorGUILayout.BeginVertical(); @@ -24,7 +26,8 @@ public class FungusCommandEditor : Editor EditorGUILayout.LabelField(new GUIContent("Error: " + t.errorMessage), style); } - if (t.IsExecuting()) + if (t.IsExecuting() || + t == selectedCommand) { EditorGUI.DrawRect(rect, new Color(1f, 1f, 0f, 0.25f)); } diff --git a/Assets/Fungus/Editor/FungusEditorWindow.cs b/Assets/Fungus/Editor/FungusEditorWindow.cs index 2ba6a028..f0178c0b 100755 --- a/Assets/Fungus/Editor/FungusEditorWindow.cs +++ b/Assets/Fungus/Editor/FungusEditorWindow.cs @@ -111,9 +111,29 @@ public class FungusEditorWindow : EditorWindow } } + if (FungusCommandEditor.selectedCommand != null) + { + if (Selection.activeGameObject == null) + { + FungusCommandEditor.selectedCommand = null; + } + else + { + FungusCommand command = Selection.activeGameObject.GetComponent(); + if (command == null) + { + FungusCommandEditor.selectedCommand = null; + } + else if (command.gameObject != FungusCommandEditor.selectedCommand.gameObject) + { + FungusCommandEditor.selectedCommand = null; + } + } + } + Sequence sequence = windowSequenceMap[windowId]; - GUIStyle style = new GUIStyle(GUI.skin.box); + GUIStyle style = new GUIStyle(GUI.skin.button); FungusCommand[] commands = sequence.gameObject.GetComponents(); foreach (FungusCommand command in commands) @@ -134,7 +154,12 @@ public class FungusEditorWindow : EditorWindow GUI.backgroundColor = Color.white; } - GUILayout.Label(commandName, style, GUILayout.ExpandWidth(true)); + if (GUILayout.Button(commandName, style, GUILayout.ExpandWidth(true))) + { + // Highlight the command in inspector + FungusCommandEditor.selectedCommand = command; + EditorUtility.SetDirty( command ); + } } GUI.DragWindow(); diff --git a/Assets/Fungus/VisualScripting/Sequence.cs b/Assets/Fungus/VisualScripting/Sequence.cs index 9274a8b6..8b41c058 100644 --- a/Assets/Fungus/VisualScripting/Sequence.cs +++ b/Assets/Fungus/VisualScripting/Sequence.cs @@ -2,6 +2,7 @@ using UnityEditor; #endif using UnityEngine; +using System; using System.Collections; using System.Collections.Generic; @@ -15,10 +16,10 @@ namespace Fungus [HideInInspector] public Rect nodeRect = new Rect(10, 10, 100, 100); - [HideInInspector] + [System.NonSerialized] public SequenceController sequenceController; - [HideInInspector] + [System.NonSerialized] public FungusCommand activeCommand; public virtual void Start()