Skip to content
This repository has been archived by the owner on Apr 3, 2022. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosecchi committed Dec 31, 2019
2 parents 1218c33 + 4d5e694 commit 1934970
Show file tree
Hide file tree
Showing 16 changed files with 205 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Scripts/Agents/AI/Graph/AIActionNode.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MoreMountains.Tools;
using System;
using MoreMountains.Tools;
using UnityEngine;

namespace TheBitCave.MMToolsExtensions.AI.Graph
Expand All @@ -10,7 +11,6 @@ namespace TheBitCave.MMToolsExtensions.AI.Graph
[CreateNodeMenu("")]
public class AIActionNode : AINode
{

/// <summary>
/// The Corgi Action label.
/// </summary>
Expand Down
20 changes: 20 additions & 0 deletions Scripts/Agents/AI/Graph/AIBrainGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class AIBrainGraph : NodeGraph, IBrainGraph
{
public AIStartSelectableNode startingNode;

protected bool _nodeCollapseModeOn;

/// <summary>
/// Which state should be initialized as the starting one.
/// </summary>
Expand All @@ -21,5 +23,23 @@ public AIStartSelectableNode StartingNode
get => startingNode;
set => startingNode = value;
}

public bool IsNodeCollapseModeOn => _nodeCollapseModeOn;

/// <summary>
/// Enables node collapsing.
/// </summary>
public void EnableNodeCollapse()
{
_nodeCollapseModeOn = true;
}

/// <summary>
/// Disables node collapsing.
/// </summary>
public void DisableNodeCollapse()
{
_nodeCollapseModeOn = false;
}
}
}
19 changes: 19 additions & 0 deletions Scripts/Agents/AI/Graph/AIBrainSubgraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class AIBrainSubgraph : NodeGraph, IBrainGraph
{
public AIStartSelectableNode startingNode;

protected bool _nodeCollapseModeOn;

/// <summary>
/// Which state should be initialized as the starting one.
/// </summary>
Expand All @@ -37,5 +39,22 @@ public IEnumerable<AISubgraphTransitionOutNode> GetTransitionsOut()
.ToList();
}

public bool IsNodeCollapseModeOn => _nodeCollapseModeOn;

/// <summary>
/// Enables node collapsing.
/// </summary>
public void EnableNodeCollapse()
{
_nodeCollapseModeOn = true;
}

/// <summary>
/// Disables node collapsing.
/// </summary>
public void DisableNodeCollapse()
{
_nodeCollapseModeOn = false;
}
}
}
2 changes: 2 additions & 0 deletions Scripts/Agents/AI/Graph/AINode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace TheBitCave.MMToolsExtensions.AI.Graph
/// </summary>
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ public class AIActionChangeAIBrainStateCommandNodeEditor : AIActionNodeEditor
private SerializedProperty _channel;
private SerializedProperty _stateName;

public override void OnBodyGUI()
protected override void SerializeAdditionalProperties()
{
base.OnBodyGUI();

EditorGUIUtility.labelWidth = 100;
_channel = serializedObject.FindProperty("channel");
_stateName = serializedObject.FindProperty("stateName");
Expand Down
12 changes: 12 additions & 0 deletions Scripts/Agents/AI/Graph/Editor/AIActionNodeEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ", "");
Expand All @@ -25,6 +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;
}
}
15 changes: 14 additions & 1 deletion Scripts/Agents/AI/Graph/Editor/AIBrainGraphEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
}
46 changes: 39 additions & 7 deletions Scripts/Agents/AI/Graph/Editor/AIBrainStateAliasNodeEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -46,16 +46,48 @@ 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();
NodeEditorGUILayout.PropertyField(_statesIn);
serializedObject.ApplyModifiedProperties();
}

/// <summary> Add items for the context menu when right-clicking this node. Disables the 'Rename' option. </summary>
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);
}
}

}
}
14 changes: 14 additions & 0 deletions Scripts/Agents/AI/Graph/Editor/AIBrainSubgraphEditor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using UnityEditor;
using UnityEngine;
using XNodeEditor;
using Object = UnityEngine.Object;
Expand All @@ -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());
}
}
}
}
10 changes: 3 additions & 7 deletions Scripts/Agents/AI/Graph/Editor/AICommentNodeEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
12 changes: 12 additions & 0 deletions Scripts/Agents/AI/Graph/Editor/AIDecisionNodeEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class AIDecisionNodeEditor : NodeEditor
private SerializedProperty _label;
private SerializedProperty _output;

protected AIDecisionNode DecisionNode => target as AIDecisionNode;

public override void OnHeaderGUI()
{
var title = target.name.Replace("AI Decision ", "");
Expand All @@ -25,7 +27,17 @@ 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;

}
}
6 changes: 6 additions & 0 deletions Scripts/Agents/AI/Graph/Interfaces/IBrainGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@ namespace TheBitCave.MMToolsExtensions.AI.Graph
public interface IBrainGraph
{
AIStartSelectableNode StartingNode { get; set; }

bool IsNodeCollapseModeOn { get; }

void EnableNodeCollapse();

void DisableNodeCollapse();
}
}
1 change: 1 addition & 0 deletions Scripts/Agents/AI/Graph/Utils/C.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
8 changes: 8 additions & 0 deletions Scripts/Agents/AI/Utils.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions Scripts/Agents/AI/Utils/MenuItems.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using MoreMountains.Tools;
using UnityEngine;
using UnityEditor;

namespace TheBitCave.MMToolsExtensions.AI.Graph
{
public static class MenuItems
{

[MenuItem("GameObject/The Bit Cave/Remove Brain System", true, 30)]
private static bool RemoveAIBrainSystemValidator()
{
if (Selection.activeGameObject == null) return false;
var aiBrain = Selection.activeGameObject.GetComponent<AIBrain>();
var aiActions = Selection.activeGameObject.GetComponents<AIAction>();
var aiDecisions = Selection.activeGameObject.GetComponents<AIDecision>();

return (aiBrain != null) || (aiActions.Length > 0) || (aiDecisions.Length > 0);
}

/// <summary>
/// Removes all the AI System (AIBrain, AIActions and AIDecisions)
/// </summary>
[MenuItem("GameObject/AI Brain/Remove Brain System", false, 30)]
private static void RemoveAIBrainSystem()
{
if (Selection.activeGameObject == null) return;
var aiBrain = Selection.activeGameObject.GetComponent<AIBrain>();
var aiActions = Selection.activeGameObject.GetComponents<AIAction>();
var aiDecisions = Selection.activeGameObject.GetComponents<AIDecision>();

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.");
}
}
}
11 changes: 11 additions & 0 deletions Scripts/Agents/AI/Utils/MenuItems.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1934970

Please sign in to comment.