public void DrawBehaviorTree(BehaviorTree behaviorTree) { if (behaviorTree == null || BehaviorTreeEditor.BTEditorWindow == null) { return; } if (behaviorTree != _behaviorTree) { BehaviorTreeEditorHelper.GenerateQueue(_drawingQueue, behaviorTree); BehaviorTreeEditor.BTEditorWindow.Repaint(); } _behaviorTree = behaviorTree; if (_behaviorTree.Child == null) { int i = EditorGUI.Popup(_addRootRect, "Add root: ", 0, _addChildOptions, BehaviorTreeEditorSettings.Instance.AddButtonStyle); switch (i) { case 1: Sequence newSequence = new Sequence(); behaviorTree.AddChild(newSequence); break; case 2: Selector newSelector = new Selector(); behaviorTree.AddChild(newSelector); break; case 3: Decorator newDecorator = new Decorator(); behaviorTree.AddChild(newDecorator); break; case 4: Task t = new Task(); behaviorTree.AddChild(t); break; default: break; } BehaviorTreeEditorHelper.GenerateQueue(_drawingQueue, _behaviorTree); } _scrollPos = GUI.BeginScrollView(new Rect(0, 100, BehaviorTreeEditor.BTEditorWindow.position.width - BehaviorTreeEditorSettings.Instance.SideMenuRect.width - 10, BehaviorTreeEditor.BTEditorWindow.position.height - _addRootRect.height - 100), _scrollPos, new Rect(0, 100, BehaviorTreeEditorHelper.GetWidth() * (BehaviorTreeEditorSettings.Instance.ElementWidth + BehaviorTreeEditorSettings.Instance.HorizontalSpaceBetweenElements) + 110 + _infoRect.x, BehaviorTreeEditorHelper.GetDepth(_drawingQueue) * (BehaviorTreeEditorSettings.Instance.ElementHeight + BehaviorTreeEditorSettings.Instance.VerticalSpaceBetweenElements) + 100)); BehaviorTreeEditor.BTEditorWindow.BeginWindows(); GUILayout.Window(-1, _infoRect, DrawInfo, "Behavior Tree Info"); DrawStack(); BehaviorTreeEditor.BTEditorWindow.EndWindows(); GUI.EndScrollView(); }
private void DrawNode(int id) { //GUI.DragWindow(); DrawerNodeClass dnc = BehaviorTreeEditorHelper.GetNodeById(_drawingQueue, id); if (dnc == null) { return; } Type t = dnc.Node.GetType(); if (t == typeof(Selector)) { DrawSelector((Selector)dnc.Node); } else if (t == typeof(Sequence)) { DrawSequence((Sequence)dnc.Node); } else if (t == typeof(Decorator)) { DrawDecorator((Decorator)dnc.Node); } else { DrawTask((Task)dnc.Node); } }
private void DrawRemoveChildOption(INode node) { if (GUILayout.Button("X", BehaviorTreeEditorSettings.Instance.RemoveButtonStyle)) { if (node.IsRoot()) { _behaviorTree.RemoveChild(); } else { node.GetParent().RemoveChild(node); } BehaviorTreeEditorHelper.GenerateQueue(_drawingQueue, _behaviorTree); } }
private void DrawAddChildOption(INode node) { int i = EditorGUILayout.Popup(0, _addChildOptions, BehaviorTreeEditorSettings.Instance.AddButtonStyle); if (i == 0) { return; } switch (i) { case 1: Sequence newSequence = new Sequence(); node.AddChild(newSequence); newSequence.SetParent(node); break; case 2: Selector newSelector = new Selector(); node.AddChild(newSelector); newSelector.SetParent(node); break; case 3: Decorator newDecorator = new Decorator(); node.AddChild(newDecorator); newDecorator.SetParent(node); break; case 4: Task t = new Task(); node.AddChild(t); t.SetParent(node); break; default: break; } BehaviorTreeEditorHelper.GenerateQueue(_drawingQueue, _behaviorTree); }