void SubTreeCallback() { BehaviourTreeSubTreeNode newNode = (BehaviourTreeSubTreeNode)ScriptableObject.CreateInstance("BehaviourTreeSubTreeNode"); newNode.ID = GetNextWindowID(); this.selectedNode.AddChild(newNode); newNode.displayedName = "SUB TREE"; AddNodeToAssets(newNode); SaveBehaviourTree(); this.selectedNode = newNode; }
void SubTreeWindowFunction(int windowID) { BehaviourTreeSubTreeNode node = (BehaviourTreeSubTreeNode)FindNodeByID(BehaviourTreeEditorWindow.behaviourTree, windowID); Event current = Event.current; if (current.mousePosition.x >= 0.0f && current.mousePosition.x <= nodeSize.x * zoomScale && current.mousePosition.y >= 0.0f && current.mousePosition.y <= nodeSize.y * zoomScale && DragAndDrop.objectReferences.Length == 1) { Object subTreeScriptAsset = DragAndDrop.objectReferences[0]; if (!(subTreeScriptAsset is MonoScript)) { DragAndDrop.visualMode = DragAndDropVisualMode.Rejected; } else { DragAndDrop.visualMode = DragAndDropVisualMode.Link; } } if (current.type == EventType.MouseDown && current.button == 1) { this.selectedNode = node; if (Selection.activeObject != BehaviourTreeEditorWindow.behaviourTree) { SelectNodeButDontChangeProjectView(); } GenericMenu menu = new GenericMenu(); AddInsertNewParentOptions(menu); AddMoveOption(menu); menu.AddItem(new GUIContent("Delete Node"), false, DeleteNodeCallback); menu.ShowAsContext(); current.Use(); } else if (current.type.Equals(EventType.DragExited)) { Object subTreeScriptAsset = DragAndDrop.objectReferences[0]; if (!(subTreeScriptAsset is MonoScript)) { Debug.Log("not a MonoScript"); current.Use(); return; } System.Type subTreeType = (subTreeScriptAsset as MonoScript).GetClass(); ScriptableObject so = ScriptableObject.CreateInstance(subTreeType); if (!(so is BehaviourTree)) { Debug.Log("not a BehaviourTree"); current.Use(); return; } node.subTree = so as BehaviourTree; node.displayedName = subTreeType.ToString(); BehaviourTreeEditorWindow.SaveBehaviourTree(); this.selectedNode = node; if (Selection.activeObject != BehaviourTreeEditorWindow.behaviourTree) { SelectNodeButDontChangeProjectView(); } current.Use(); } else if (current.type == EventType.MouseDown && current.button == 0 && current.clickCount == 2) { Selection.activeObject = node.subTree; OnOpenAsset(0, 0); current.Use(); } else if (current.type == EventType.MouseDown && current.button == 0) { this.selectedNode = node; if (Selection.activeObject != BehaviourTreeEditorWindow.behaviourTree) { SelectNodeButDontChangeProjectView(); } current.Use(); } }
public override void OnInspectorGUI() { Repaint(); GUIStyle titleStyle = new GUIStyle(); titleStyle.fontSize = 20; GUIStyle partStyle = new GUIStyle(); partStyle.fontSize = 15; if (BehaviourTreeEditorWindow.Instance == null) { return; } BehaviourTreeNode selectedNode = BehaviourTreeEditorWindow.Instance.selectedNode; if (selectedNode == null) { return; } GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label(selectedNode.displayedName, titleStyle); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.Space(30); if (selectedNode is BehaviourTreeControlNode) { BehaviourTreeControlNode node = (BehaviourTreeControlNode)selectedNode; GUI.color = Color.white; BehaviourTreeControlNode.Type initialTypeValue = node.type; BehaviourTreeControlNode.Type typeValue = (BehaviourTreeControlNode.Type)EditorGUILayout.EnumPopup("Type", initialTypeValue); if (typeValue != initialTypeValue) { node.type = typeValue; node.displayedName = typeValue.ToString().Replace('_', ' '); BehaviourTreeEditorWindow.SaveNodeAnChildren(node); BehaviourTreeEditorWindow.Instance.Repaint(); } if (node.type != BehaviourTreeControlNode.Type.PARALLEL) { bool initialMemorizeValue = node.startFromFirstNodeEachTick; GUILayout.Space(5); GUILayout.BeginHorizontal(); GUI.color = Color.black; GUILayout.Label("Don't memorize running node", GUI.skin.label); GUI.color = Color.white; bool memorizeValue = EditorGUILayout.Toggle(initialMemorizeValue); if (memorizeValue != initialMemorizeValue) { node.startFromFirstNodeEachTick = memorizeValue; BehaviourTreeEditorWindow.SaveNodeAnChildren(node); BehaviourTreeEditorWindow.Instance.Repaint(); } GUILayout.EndHorizontal(); } } else if (selectedNode is BehaviourTreeExecutionNode) { BehaviourTreeExecutionNode node = (BehaviourTreeExecutionNode)selectedNode; if (node.task != null) { // GUILayout.Space(nodeSize.y * zoomScale); PropertyReader.Variable[] variables = PropertyReader.GetFields(node.task.GetType()); GUILayout.Label("PARAMETER", partStyle); foreach (PropertyReader.Variable variable in variables) { if (variable.name.StartsWith("param_")) { GUILayout.Space(5); AddParameterField(node, variable); } } GUILayout.Space(20); GUILayout.Label("INPUT", partStyle); foreach (PropertyReader.Variable variable in variables) { if (variable.name.StartsWith("in_")) { GUILayout.Space(5); AddContextField(node, variable); } } GUILayout.Space(20); GUILayout.Label("OUTPUT", partStyle); foreach (PropertyReader.Variable variable in variables) { if (variable.name.StartsWith("out_")) { GUILayout.Space(5); AddContextField(node, variable); } } } } else if (selectedNode is BehaviourTreeDecoratorNode) { BehaviourTreeDecoratorNode node = (BehaviourTreeDecoratorNode)selectedNode; GUI.color = Color.white; BehaviourTreeDecoratorNode.Type initialTypeValue = node.type; BehaviourTreeDecoratorNode.Type typeValue = (BehaviourTreeDecoratorNode.Type)EditorGUILayout.EnumPopup("Type", initialTypeValue); if (typeValue != initialTypeValue) { node.type = typeValue; node.displayedName = typeValue.ToString().Replace('_', ' '); BehaviourTreeEditorWindow.SaveNodeAnChildren(node); BehaviourTreeEditorWindow.Instance.Repaint(); } } else if (selectedNode is BehaviourTreeSubTreeNode) { BehaviourTreeSubTreeNode node = (BehaviourTreeSubTreeNode)selectedNode; GUI.color = Color.white; BehaviourTree initialValue = node.subTree; BehaviourTree newValue = (BehaviourTree)EditorGUILayout.ObjectField(node.subTree, typeof(BehaviourTree), false); if (newValue != initialValue) { node.subTree = newValue; node.displayedName = newValue.ToString().Replace('_', ' ').Split('(')[0]; BehaviourTreeEditorWindow.SaveNodeAnChildren(node); BehaviourTreeEditorWindow.Instance.Repaint(); } } }