From 1f119cd78abf1c9d0a9b9b7ae365e4f0fdbb8196 Mon Sep 17 00:00:00 2001 From: Marco Secchi Date: Mon, 30 Dec 2019 15:21:09 +0100 Subject: [PATCH 01/12] Fix issue #11. --- .../Editor/AIBrainStateAliasNodeEditor.cs | 21 ++++++++++++------- Scripts/Agents/AI/Graph/Utils/C.cs | 1 + 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Scripts/Agents/AI/Graph/Editor/AIBrainStateAliasNodeEditor.cs b/Scripts/Agents/AI/Graph/Editor/AIBrainStateAliasNodeEditor.cs index 33e61fd..2da94c1 100644 --- a/Scripts/Agents/AI/Graph/Editor/AIBrainStateAliasNodeEditor.cs +++ b/Scripts/Agents/AI/Graph/Editor/AIBrainStateAliasNodeEditor.cs @@ -23,8 +23,8 @@ public override void OnCreate() public override void OnHeaderGUI() { - _node.name = _node.stateName; - GUILayout.Label(_node.stateName, NodeEditorResources.styles.nodeHeader, GUILayout.Height(30)); + _node.name = !string.IsNullOrEmpty(_node.stateName) ? _node.stateName : C.LABEL_STATE_ALIAS; + base.OnHeaderGUI(); } public override void OnBodyGUI() @@ -46,11 +46,18 @@ public override void OnBodyGUI() } } - var options = optionsList.ToArray(); - _stateIndex = EditorGUILayout.Popup(_stateIndex, options); - - EditorGUILayout.Space(); - _node.stateName = options[_stateIndex]; + if (optionsList.Count > 0) + { + var options = optionsList.ToArray(); + _stateIndex = EditorGUILayout.Popup(_stateIndex, options); + EditorGUILayout.Space(); + _node.stateName = options[_stateIndex]; + } + else + { + EditorGUILayout.LabelField(C.LABEL_NO_STATE_AVAILABLE); + EditorGUILayout.Space(); + } } serializedObject.Update(); diff --git a/Scripts/Agents/AI/Graph/Utils/C.cs b/Scripts/Agents/AI/Graph/Utils/C.cs index 7cbc91c..19f04b5 100644 --- a/Scripts/Agents/AI/Graph/Utils/C.cs +++ b/Scripts/Agents/AI/Graph/Utils/C.cs @@ -43,6 +43,7 @@ public static class C public const string LABEL_INSERT_COMMENT = "Insert Comment"; public const string LABEL_ANY_STATE = "Any State"; public const string LABEL_STATE_ALIAS = "State Alias"; + public const string LABEL_NO_STATE_AVAILABLE = "No State Available"; // Colors public const string COLOR_STARTING_STATE = "#E63946"; From 0cfafddf2ec581ca69a4704baf7ae9f2780c82e5 Mon Sep 17 00:00:00 2001 From: marcosecchi Date: Mon, 30 Dec 2019 21:27:55 +0100 Subject: [PATCH 02/12] Fix issue #10 --- Scripts/Agents/AI/Graph/Editor/AICommentNodeEditor.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Scripts/Agents/AI/Graph/Editor/AICommentNodeEditor.cs b/Scripts/Agents/AI/Graph/Editor/AICommentNodeEditor.cs index 9910eda..e8b5f63 100644 --- a/Scripts/Agents/AI/Graph/Editor/AICommentNodeEditor.cs +++ b/Scripts/Agents/AI/Graph/Editor/AICommentNodeEditor.cs @@ -24,23 +24,19 @@ public override void OnHeaderGUI() public override void OnBodyGUI() { - var wordWrap = EditorStyles.textField.wordWrap; - EditorStyles.textField.wordWrap = true; + var style = GUIStyle.none; + style.wordWrap = true; if (Selection.activeObject == _node) { - _node.comment = EditorGUILayout.TextArea(_node.comment); + _node.comment = EditorGUILayout.TextArea(_node.comment, style); } else { EditorGUI.BeginDisabledGroup(true); - var style = GUIStyle.none; - style.wordWrap = true; EditorGUILayout.TextArea(_node.comment, style); EditorGUI.EndDisabledGroup(); } - - EditorStyles.textField.wordWrap = wordWrap; } } } \ No newline at end of file From 41e0135a70a114ae4c3ab0868e5672a9d03b7dc7 Mon Sep 17 00:00:00 2001 From: marcosecchi Date: Tue, 31 Dec 2019 09:02:16 +0100 Subject: [PATCH 03/12] Disable Rename option on StateAlias node. --- .../Editor/AIBrainStateAliasNodeEditor.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Scripts/Agents/AI/Graph/Editor/AIBrainStateAliasNodeEditor.cs b/Scripts/Agents/AI/Graph/Editor/AIBrainStateAliasNodeEditor.cs index 2da94c1..a841e48 100644 --- a/Scripts/Agents/AI/Graph/Editor/AIBrainStateAliasNodeEditor.cs +++ b/Scripts/Agents/AI/Graph/Editor/AIBrainStateAliasNodeEditor.cs @@ -64,5 +64,30 @@ public override void OnBodyGUI() NodeEditorGUILayout.PropertyField(_statesIn); serializedObject.ApplyModifiedProperties(); } + + /// Add items for the context menu when right-clicking this node. Disables the 'Rename' option. + public override void AddContextMenuItems(GenericMenu menu) + { + // Actions if only one node is selected + if (Selection.objects.Length == 1 && Selection.activeObject is XNode.Node) + { + var node = Selection.activeObject as XNode.Node; + menu.AddItem(new GUIContent("Move To Top"), false, () => NodeEditorWindow.current.MoveNodeToTop(node)); + menu.AddDisabledItem(new GUIContent("Rename")); + } + + // Add actions to any number of selected nodes + menu.AddItem(new GUIContent("Copy"), false, NodeEditorWindow.current.CopySelectedNodes); + menu.AddItem(new GUIContent("Duplicate"), false, NodeEditorWindow.current.DuplicateSelectedNodes); + menu.AddItem(new GUIContent("Remove"), false, NodeEditorWindow.current.RemoveSelectedNodes); + + // Custom sections if only one node is selected + if (Selection.objects.Length == 1 && Selection.activeObject is XNode.Node) + { + var node = Selection.activeObject as XNode.Node; + menu.AddCustomContextMenuItems(node); + } + } + } } \ No newline at end of file From 1670f0fe04d8b9c041e9f0cef8012e4f0876141a Mon Sep 17 00:00:00 2001 From: marcosecchi Date: Tue, 31 Dec 2019 10:22:07 +0100 Subject: [PATCH 04/12] Add utility method to remove the AI System. --- Scripts/Agents/AI/Utils.meta | 8 ++++++++ Scripts/Agents/AI/Utils/MenuItems.cs | 18 ++++++++++++++++++ Scripts/Agents/AI/Utils/MenuItems.cs.meta | 11 +++++++++++ 3 files changed, 37 insertions(+) create mode 100644 Scripts/Agents/AI/Utils.meta create mode 100644 Scripts/Agents/AI/Utils/MenuItems.cs create mode 100644 Scripts/Agents/AI/Utils/MenuItems.cs.meta diff --git a/Scripts/Agents/AI/Utils.meta b/Scripts/Agents/AI/Utils.meta new file mode 100644 index 0000000..8ade04a --- /dev/null +++ b/Scripts/Agents/AI/Utils.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e07bf99fbacd240409fa05ed4d6e8ac8 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Agents/AI/Utils/MenuItems.cs b/Scripts/Agents/AI/Utils/MenuItems.cs new file mode 100644 index 0000000..db35c95 --- /dev/null +++ b/Scripts/Agents/AI/Utils/MenuItems.cs @@ -0,0 +1,18 @@ +using UnityEngine; +using UnityEditor; + +namespace TheBitCave.MMToolsExtensions.AI.Graph +{ + public static class MenuItems + { + /// + /// Removes all the AI System (AIBrain, AIActions and AIDecisions) + /// + [MenuItem("GameObject/AI Brain/Remove AI Brain System", false, 100)] + private static void RemoveAIBrainSystem() + { + if (Selection.activeGameObject == null) return; + GeneratorUtils.Cleanup(Selection.activeGameObject); + } + } +} diff --git a/Scripts/Agents/AI/Utils/MenuItems.cs.meta b/Scripts/Agents/AI/Utils/MenuItems.cs.meta new file mode 100644 index 0000000..2335512 --- /dev/null +++ b/Scripts/Agents/AI/Utils/MenuItems.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3b6934dd3cb944a5b8d96ba0ce042615 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From e22280745ec2a9bf0deac0a9873a00a1f3acce85 Mon Sep 17 00:00:00 2001 From: marcosecchi Date: Tue, 31 Dec 2019 11:14:06 +0100 Subject: [PATCH 05/12] Update MenuItems.cs --- Scripts/Agents/AI/Utils/MenuItems.cs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/Scripts/Agents/AI/Utils/MenuItems.cs b/Scripts/Agents/AI/Utils/MenuItems.cs index db35c95..1322030 100644 --- a/Scripts/Agents/AI/Utils/MenuItems.cs +++ b/Scripts/Agents/AI/Utils/MenuItems.cs @@ -1,18 +1,41 @@ -using UnityEngine; +using MoreMountains.Tools; +using UnityEngine; using UnityEditor; namespace TheBitCave.MMToolsExtensions.AI.Graph { public static class MenuItems { + + [MenuItem("GameObject/AI Brain/RemoveAIBrainSystem", true)] + private static bool RemoveAIBrainSystemValidator() + { + if (Selection.activeGameObject == null) return false; + var aiBrain = Selection.activeGameObject.GetComponent(); + var aiActions = Selection.activeGameObject.GetComponents(); + var aiDecisions = Selection.activeGameObject.GetComponents(); + + return (aiBrain != null) || (aiActions.Length > 0) || (aiDecisions.Length > 0); + } + /// /// Removes all the AI System (AIBrain, AIActions and AIDecisions) /// - [MenuItem("GameObject/AI Brain/Remove AI Brain System", false, 100)] + [MenuItem("GameObject/AI Brain/RemoveAIBrainSystem _PGUP", false, 100)] private static void RemoveAIBrainSystem() { if (Selection.activeGameObject == null) return; + var aiBrain = Selection.activeGameObject.GetComponent(); + var aiActions = Selection.activeGameObject.GetComponents(); + var aiDecisions = Selection.activeGameObject.GetComponents(); + + if(aiBrain) Debug.Log("Removing AIBrain"); + if(aiActions.Length > 0) Debug.Log("Removing " + aiActions.Length + " AIActions"); + if(aiDecisions.Length > 0) Debug.Log("Removing " + aiDecisions.Length + " AIDecisions"); + GeneratorUtils.Cleanup(Selection.activeGameObject); + + Debug.Log("AIBrain cleanup complete."); } } } From c74b8d9e5c85ed9d05a21dafd19a1f2d6b439876 Mon Sep 17 00:00:00 2001 From: marcosecchi Date: Tue, 31 Dec 2019 13:10:55 +0100 Subject: [PATCH 06/12] Update MenuItems.cs --- Scripts/Agents/AI/Utils/MenuItems.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scripts/Agents/AI/Utils/MenuItems.cs b/Scripts/Agents/AI/Utils/MenuItems.cs index 1322030..6a76684 100644 --- a/Scripts/Agents/AI/Utils/MenuItems.cs +++ b/Scripts/Agents/AI/Utils/MenuItems.cs @@ -21,7 +21,7 @@ private static bool RemoveAIBrainSystemValidator() /// /// Removes all the AI System (AIBrain, AIActions and AIDecisions) /// - [MenuItem("GameObject/AI Brain/RemoveAIBrainSystem _PGUP", false, 100)] + [MenuItem("GameObject/AI Brain/RemoveAIBrainSystem", false, 100)] private static void RemoveAIBrainSystem() { if (Selection.activeGameObject == null) return; From a8788aa059fd1a2d993bcd9382c8cf5002e4da8e Mon Sep 17 00:00:00 2001 From: marcosecchi Date: Tue, 31 Dec 2019 14:16:05 +0100 Subject: [PATCH 07/12] Add collapse mode. --- Scripts/Agents/AI/Graph/AIActionNode.cs | 4 ++-- Scripts/Agents/AI/Graph/AIBrainGraph.cs | 20 +++++++++++++++++++ Scripts/Agents/AI/Graph/AIBrainSubgraph.cs | 19 ++++++++++++++++++ Scripts/Agents/AI/Graph/AINode.cs | 2 ++ .../AI/Graph/Editor/AIActionNodeEditor.cs | 4 ++++ .../AI/Graph/Editor/AIBrainGraphEditor.cs | 15 +++++++++++++- .../AI/Graph/Editor/AIBrainSubgraphEditor.cs | 14 +++++++++++++ .../AI/Graph/Editor/AIDecisionNodeEditor.cs | 4 ++++ .../Agents/AI/Graph/Interfaces/IBrainGraph.cs | 6 ++++++ 9 files changed, 85 insertions(+), 3 deletions(-) diff --git a/Scripts/Agents/AI/Graph/AIActionNode.cs b/Scripts/Agents/AI/Graph/AIActionNode.cs index 36b3802..2f9fe74 100644 --- a/Scripts/Agents/AI/Graph/AIActionNode.cs +++ b/Scripts/Agents/AI/Graph/AIActionNode.cs @@ -1,4 +1,5 @@ -using MoreMountains.Tools; +using System; +using MoreMountains.Tools; using UnityEngine; namespace TheBitCave.MMToolsExtensions.AI.Graph @@ -10,7 +11,6 @@ namespace TheBitCave.MMToolsExtensions.AI.Graph [CreateNodeMenu("")] public class AIActionNode : AINode { - /// /// The Corgi Action label. /// diff --git a/Scripts/Agents/AI/Graph/AIBrainGraph.cs b/Scripts/Agents/AI/Graph/AIBrainGraph.cs index a998ca0..bd1cfe4 100644 --- a/Scripts/Agents/AI/Graph/AIBrainGraph.cs +++ b/Scripts/Agents/AI/Graph/AIBrainGraph.cs @@ -13,6 +13,8 @@ public class AIBrainGraph : NodeGraph, IBrainGraph { public AIStartSelectableNode startingNode; + protected bool _nodeCollapseModeOn; + /// /// Which state should be initialized as the starting one. /// @@ -21,5 +23,23 @@ public AIStartSelectableNode StartingNode get => startingNode; set => startingNode = value; } + + public bool IsNodeCollapseModeOn => _nodeCollapseModeOn; + + /// + /// Enables node collapsing. + /// + public void EnableNodeCollapse() + { + _nodeCollapseModeOn = true; + } + + /// + /// Disables node collapsing. + /// + public void DisableNodeCollapse() + { + _nodeCollapseModeOn = false; + } } } diff --git a/Scripts/Agents/AI/Graph/AIBrainSubgraph.cs b/Scripts/Agents/AI/Graph/AIBrainSubgraph.cs index 48aa1c2..b4f441f 100644 --- a/Scripts/Agents/AI/Graph/AIBrainSubgraph.cs +++ b/Scripts/Agents/AI/Graph/AIBrainSubgraph.cs @@ -14,6 +14,8 @@ public class AIBrainSubgraph : NodeGraph, IBrainGraph { public AIStartSelectableNode startingNode; + protected bool _nodeCollapseModeOn; + /// /// Which state should be initialized as the starting one. /// @@ -37,5 +39,22 @@ public IEnumerable GetTransitionsOut() .ToList(); } + public bool IsNodeCollapseModeOn => _nodeCollapseModeOn; + + /// + /// Enables node collapsing. + /// + public void EnableNodeCollapse() + { + _nodeCollapseModeOn = true; + } + + /// + /// Disables node collapsing. + /// + public void DisableNodeCollapse() + { + _nodeCollapseModeOn = false; + } } } \ No newline at end of file diff --git a/Scripts/Agents/AI/Graph/AINode.cs b/Scripts/Agents/AI/Graph/AINode.cs index 9355383..90bcd24 100644 --- a/Scripts/Agents/AI/Graph/AINode.cs +++ b/Scripts/Agents/AI/Graph/AINode.cs @@ -7,6 +7,8 @@ namespace TheBitCave.MMToolsExtensions.AI.Graph /// public class AINode : Node { + public IBrainGraph BrainGraph => graph as IBrainGraph; + // We don't care about the return value of the ports. // Just return null to stop the console spam. public override object GetValue(NodePort port) diff --git a/Scripts/Agents/AI/Graph/Editor/AIActionNodeEditor.cs b/Scripts/Agents/AI/Graph/Editor/AIActionNodeEditor.cs index ebd7d0a..89b6665 100644 --- a/Scripts/Agents/AI/Graph/Editor/AIActionNodeEditor.cs +++ b/Scripts/Agents/AI/Graph/Editor/AIActionNodeEditor.cs @@ -10,6 +10,8 @@ public class AIActionNodeEditor : NodeEditor private SerializedProperty _label; private SerializedProperty _output; + protected AIActionNode ActionNode => target as AIActionNode; + public override void OnHeaderGUI() { var title = target.name.Replace("AI Action ", ""); @@ -26,5 +28,7 @@ public override void OnBodyGUI() NodeEditorGUILayout.PropertyField(_output); serializedObject.ApplyModifiedProperties(); } + + protected bool CollapseNodeOn => ActionNode.BrainGraph.IsNodeCollapseModeOn && !Selection.activeObject == target; } } \ No newline at end of file diff --git a/Scripts/Agents/AI/Graph/Editor/AIBrainGraphEditor.cs b/Scripts/Agents/AI/Graph/Editor/AIBrainGraphEditor.cs index d486754..31885b4 100644 --- a/Scripts/Agents/AI/Graph/Editor/AIBrainGraphEditor.cs +++ b/Scripts/Agents/AI/Graph/Editor/AIBrainGraphEditor.cs @@ -47,6 +47,19 @@ public override void OnOpen() window.titleContent.text = target.name; RefreshCanvas(); } - + + public override void AddContextMenuItems(GenericMenu menu) { + base.AddContextMenuItems(menu); + var graph = target as IBrainGraph; + menu.AddSeparator(""); + if (graph.IsNodeCollapseModeOn) + { + menu.AddItem(new GUIContent("Disable Node Collapsing"), false, () => graph.DisableNodeCollapse()); + } + else + { + menu.AddItem(new GUIContent("Enable Node Collapsing"), false, () => graph.EnableNodeCollapse()); + } + } } } \ No newline at end of file diff --git a/Scripts/Agents/AI/Graph/Editor/AIBrainSubgraphEditor.cs b/Scripts/Agents/AI/Graph/Editor/AIBrainSubgraphEditor.cs index 57fda7f..0b427a4 100644 --- a/Scripts/Agents/AI/Graph/Editor/AIBrainSubgraphEditor.cs +++ b/Scripts/Agents/AI/Graph/Editor/AIBrainSubgraphEditor.cs @@ -1,4 +1,5 @@ using System; +using UnityEditor; using UnityEngine; using XNodeEditor; using Object = UnityEngine.Object; @@ -23,5 +24,18 @@ public override void OnOpen() window.titleContent.text = target.name; } + public override void AddContextMenuItems(GenericMenu menu) { + base.AddContextMenuItems(menu); + var graph = target as IBrainGraph; + menu.AddSeparator(""); + if (graph.IsNodeCollapseModeOn) + { + menu.AddItem(new GUIContent("Disable Node Collapsing"), false, () => graph.DisableNodeCollapse()); + } + else + { + menu.AddItem(new GUIContent("Enable Node Collapsing"), false, () => graph.EnableNodeCollapse()); + } + } } } \ No newline at end of file diff --git a/Scripts/Agents/AI/Graph/Editor/AIDecisionNodeEditor.cs b/Scripts/Agents/AI/Graph/Editor/AIDecisionNodeEditor.cs index 7203c9b..832f52f 100644 --- a/Scripts/Agents/AI/Graph/Editor/AIDecisionNodeEditor.cs +++ b/Scripts/Agents/AI/Graph/Editor/AIDecisionNodeEditor.cs @@ -10,6 +10,8 @@ public class AIDecisionNodeEditor : NodeEditor private SerializedProperty _label; private SerializedProperty _output; + protected AIDecisionNode ActionNode => target as AIDecisionNode; + public override void OnHeaderGUI() { var title = target.name.Replace("AI Decision ", ""); @@ -27,5 +29,7 @@ public override void OnBodyGUI() serializedObject.ApplyModifiedProperties(); } + protected bool CollapseNodeOn => ActionNode.BrainGraph.IsNodeCollapseModeOn && !Selection.activeObject == target; + } } \ No newline at end of file diff --git a/Scripts/Agents/AI/Graph/Interfaces/IBrainGraph.cs b/Scripts/Agents/AI/Graph/Interfaces/IBrainGraph.cs index 93c9a88..3af35b2 100644 --- a/Scripts/Agents/AI/Graph/Interfaces/IBrainGraph.cs +++ b/Scripts/Agents/AI/Graph/Interfaces/IBrainGraph.cs @@ -7,5 +7,11 @@ namespace TheBitCave.MMToolsExtensions.AI.Graph public interface IBrainGraph { AIStartSelectableNode StartingNode { get; set; } + + bool IsNodeCollapseModeOn { get; } + + void EnableNodeCollapse(); + + void DisableNodeCollapse(); } } \ No newline at end of file From c457f88cc1e4ee6534e8d55a2bcc1a1309e3d132 Mon Sep 17 00:00:00 2001 From: marcosecchi Date: Tue, 31 Dec 2019 14:33:42 +0100 Subject: [PATCH 08/12] Fix wrong collapse check. --- .../Editor/AIActionChangeAIBrainStateCommandNodeEditor.cs | 2 ++ Scripts/Agents/AI/Graph/Editor/AIActionNodeEditor.cs | 2 +- Scripts/Agents/AI/Graph/Editor/AIDecisionNodeEditor.cs | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Scripts/Agents/AI/Graph/Actions/Editor/AIActionChangeAIBrainStateCommandNodeEditor.cs b/Scripts/Agents/AI/Graph/Actions/Editor/AIActionChangeAIBrainStateCommandNodeEditor.cs index fe18896..ddff600 100644 --- a/Scripts/Agents/AI/Graph/Actions/Editor/AIActionChangeAIBrainStateCommandNodeEditor.cs +++ b/Scripts/Agents/AI/Graph/Actions/Editor/AIActionChangeAIBrainStateCommandNodeEditor.cs @@ -13,6 +13,8 @@ public override void OnBodyGUI() { base.OnBodyGUI(); + if (CollapseNodeOn) return; + EditorGUIUtility.labelWidth = 100; _channel = serializedObject.FindProperty("channel"); _stateName = serializedObject.FindProperty("stateName"); diff --git a/Scripts/Agents/AI/Graph/Editor/AIActionNodeEditor.cs b/Scripts/Agents/AI/Graph/Editor/AIActionNodeEditor.cs index 89b6665..66aa10a 100644 --- a/Scripts/Agents/AI/Graph/Editor/AIActionNodeEditor.cs +++ b/Scripts/Agents/AI/Graph/Editor/AIActionNodeEditor.cs @@ -29,6 +29,6 @@ public override void OnBodyGUI() serializedObject.ApplyModifiedProperties(); } - protected bool CollapseNodeOn => ActionNode.BrainGraph.IsNodeCollapseModeOn && !Selection.activeObject == target; + protected bool CollapseNodeOn => ActionNode.BrainGraph.IsNodeCollapseModeOn && Selection.activeObject != target; } } \ No newline at end of file diff --git a/Scripts/Agents/AI/Graph/Editor/AIDecisionNodeEditor.cs b/Scripts/Agents/AI/Graph/Editor/AIDecisionNodeEditor.cs index 832f52f..4dc7afb 100644 --- a/Scripts/Agents/AI/Graph/Editor/AIDecisionNodeEditor.cs +++ b/Scripts/Agents/AI/Graph/Editor/AIDecisionNodeEditor.cs @@ -29,7 +29,7 @@ public override void OnBodyGUI() serializedObject.ApplyModifiedProperties(); } - protected bool CollapseNodeOn => ActionNode.BrainGraph.IsNodeCollapseModeOn && !Selection.activeObject == target; + protected bool CollapseNodeOn => ActionNode.BrainGraph.IsNodeCollapseModeOn && Selection.activeObject != target; } } \ No newline at end of file From 6d3266eb078472a411e1e42067aad712fff4cb17 Mon Sep 17 00:00:00 2001 From: Marco Secchi Date: Tue, 31 Dec 2019 15:01:34 +0100 Subject: [PATCH 09/12] Update MenuItems.cs --- Scripts/Agents/AI/Utils/MenuItems.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Scripts/Agents/AI/Utils/MenuItems.cs b/Scripts/Agents/AI/Utils/MenuItems.cs index 6a76684..1e0ec85 100644 --- a/Scripts/Agents/AI/Utils/MenuItems.cs +++ b/Scripts/Agents/AI/Utils/MenuItems.cs @@ -7,7 +7,7 @@ namespace TheBitCave.MMToolsExtensions.AI.Graph public static class MenuItems { - [MenuItem("GameObject/AI Brain/RemoveAIBrainSystem", true)] + [MenuItem("GameObject/AI Brain/Remove Brain System", true, 30)] private static bool RemoveAIBrainSystemValidator() { if (Selection.activeGameObject == null) return false; @@ -21,7 +21,7 @@ private static bool RemoveAIBrainSystemValidator() /// /// Removes all the AI System (AIBrain, AIActions and AIDecisions) /// - [MenuItem("GameObject/AI Brain/RemoveAIBrainSystem", false, 100)] + [MenuItem("GameObject/AI Brain/Remove Brain System", false, 30)] private static void RemoveAIBrainSystem() { if (Selection.activeGameObject == null) return; From 105c3010dc06672db4e28c2b81721c03613d6a4f Mon Sep 17 00:00:00 2001 From: Marco Secchi Date: Tue, 31 Dec 2019 15:09:00 +0100 Subject: [PATCH 10/12] Update AIDecisionNodeEditor.cs --- Scripts/Agents/AI/Graph/Editor/AIDecisionNodeEditor.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Scripts/Agents/AI/Graph/Editor/AIDecisionNodeEditor.cs b/Scripts/Agents/AI/Graph/Editor/AIDecisionNodeEditor.cs index 4dc7afb..d022b2f 100644 --- a/Scripts/Agents/AI/Graph/Editor/AIDecisionNodeEditor.cs +++ b/Scripts/Agents/AI/Graph/Editor/AIDecisionNodeEditor.cs @@ -10,7 +10,7 @@ public class AIDecisionNodeEditor : NodeEditor private SerializedProperty _label; private SerializedProperty _output; - protected AIDecisionNode ActionNode => target as AIDecisionNode; + protected AIDecisionNode DecisionNode => target as AIDecisionNode; public override void OnHeaderGUI() { @@ -29,7 +29,7 @@ public override void OnBodyGUI() serializedObject.ApplyModifiedProperties(); } - protected bool CollapseNodeOn => ActionNode.BrainGraph.IsNodeCollapseModeOn && Selection.activeObject != target; + protected bool CollapseNodeOn => DecisionNode.BrainGraph.IsNodeCollapseModeOn && Selection.activeObject != target; } } \ No newline at end of file From 799eb9b6376da56ee72395bb884be299106182b0 Mon Sep 17 00:00:00 2001 From: Marco Secchi Date: Tue, 31 Dec 2019 15:31:13 +0100 Subject: [PATCH 11/12] Refactor Node editors. --- .../Editor/AIActionChangeAIBrainStateCommandNodeEditor.cs | 6 +----- Scripts/Agents/AI/Graph/Editor/AIActionNodeEditor.cs | 8 ++++++++ Scripts/Agents/AI/Graph/Editor/AIDecisionNodeEditor.cs | 8 ++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Scripts/Agents/AI/Graph/Actions/Editor/AIActionChangeAIBrainStateCommandNodeEditor.cs b/Scripts/Agents/AI/Graph/Actions/Editor/AIActionChangeAIBrainStateCommandNodeEditor.cs index ddff600..004b58f 100644 --- a/Scripts/Agents/AI/Graph/Actions/Editor/AIActionChangeAIBrainStateCommandNodeEditor.cs +++ b/Scripts/Agents/AI/Graph/Actions/Editor/AIActionChangeAIBrainStateCommandNodeEditor.cs @@ -9,12 +9,8 @@ public class AIActionChangeAIBrainStateCommandNodeEditor : AIActionNodeEditor private SerializedProperty _channel; private SerializedProperty _stateName; - public override void OnBodyGUI() + protected override void SerializeAdditionalProperties() { - base.OnBodyGUI(); - - if (CollapseNodeOn) return; - EditorGUIUtility.labelWidth = 100; _channel = serializedObject.FindProperty("channel"); _stateName = serializedObject.FindProperty("stateName"); diff --git a/Scripts/Agents/AI/Graph/Editor/AIActionNodeEditor.cs b/Scripts/Agents/AI/Graph/Editor/AIActionNodeEditor.cs index 66aa10a..264c8e0 100644 --- a/Scripts/Agents/AI/Graph/Editor/AIActionNodeEditor.cs +++ b/Scripts/Agents/AI/Graph/Editor/AIActionNodeEditor.cs @@ -27,8 +27,16 @@ public override void OnBodyGUI() NodeEditorGUILayout.PropertyField(_label); NodeEditorGUILayout.PropertyField(_output); serializedObject.ApplyModifiedProperties(); + + if (CollapseNodeOn) return; + SerializeAdditionalProperties(); } + protected virtual void SerializeAdditionalProperties() + { + // Add Action properties. + } + protected bool CollapseNodeOn => ActionNode.BrainGraph.IsNodeCollapseModeOn && Selection.activeObject != target; } } \ No newline at end of file diff --git a/Scripts/Agents/AI/Graph/Editor/AIDecisionNodeEditor.cs b/Scripts/Agents/AI/Graph/Editor/AIDecisionNodeEditor.cs index d022b2f..224644c 100644 --- a/Scripts/Agents/AI/Graph/Editor/AIDecisionNodeEditor.cs +++ b/Scripts/Agents/AI/Graph/Editor/AIDecisionNodeEditor.cs @@ -27,6 +27,14 @@ public override void OnBodyGUI() NodeEditorGUILayout.PropertyField(_label); NodeEditorGUILayout.PropertyField(_output); serializedObject.ApplyModifiedProperties(); + + if (CollapseNodeOn) return; + SerializeAdditionalProperties(); + } + + protected virtual void SerializeAdditionalProperties() + { + // Add Decision properties. } protected bool CollapseNodeOn => DecisionNode.BrainGraph.IsNodeCollapseModeOn && Selection.activeObject != target; From 4d5e69440747cd535ef47e761ca774688e89a55e Mon Sep 17 00:00:00 2001 From: Marco Secchi Date: Tue, 31 Dec 2019 16:56:01 +0100 Subject: [PATCH 12/12] Update MenuItems.cs --- Scripts/Agents/AI/Utils/MenuItems.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scripts/Agents/AI/Utils/MenuItems.cs b/Scripts/Agents/AI/Utils/MenuItems.cs index 1e0ec85..6125eff 100644 --- a/Scripts/Agents/AI/Utils/MenuItems.cs +++ b/Scripts/Agents/AI/Utils/MenuItems.cs @@ -7,7 +7,7 @@ namespace TheBitCave.MMToolsExtensions.AI.Graph public static class MenuItems { - [MenuItem("GameObject/AI Brain/Remove Brain System", true, 30)] + [MenuItem("GameObject/The Bit Cave/Remove Brain System", true, 30)] private static bool RemoveAIBrainSystemValidator() { if (Selection.activeGameObject == null) return false;