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); } }
public static void GenerateQueue(Queue <DrawerNodeClass> drawingQueue, BehaviorTree bt) { Queue <INode> bfsQueue = new Queue <INode>(); bfsQueue.Enqueue(bt.Child); int i = 0; drawingQueue.Clear(); while (bfsQueue.Count > 0) { INode n = bfsQueue.Dequeue(); if (n != null) { DrawerNodeClass newElement = new DrawerNodeClass(); newElement.Index = i; newElement.Node = n; newElement.Depth = CountDepth(n); newElement.Parent = GetParent(drawingQueue, n.GetParent(), newElement.Depth - 1); drawingQueue.Enqueue(newElement); i++; Type t = n.GetType(); if (t == typeof(Decorator)) { FillQueueWithDecorator(bfsQueue, (Decorator)n); } else if (t == typeof(Sequence)) { FillQueueWithSequence(bfsQueue, (Sequence)n); } else if (t == typeof(Selector)) { FillQueueWithSelector(bfsQueue, (Selector)n); } } } int maxDepth = 0; foreach (DrawerNodeClass dnc in drawingQueue) { if (dnc.Depth > maxDepth) { maxDepth = dnc.Depth; } } maxDepth += 1; _widths = new int[maxDepth]; foreach (DrawerNodeClass dnc in drawingQueue) { dnc.Width = _widths[dnc.Depth]; if (dnc.Parent != null && dnc.Width < dnc.Parent.Width) { dnc.Width = Mathf.Max(dnc.Width, dnc.Parent.Width); _widths[dnc.Depth] = dnc.Parent.Width; } _widths[dnc.Depth] += 1; dnc.CalculateRect(); } BehaviorTreeEditor.BTEditorWindow.Repaint(); }
public static void GenerateQueue(Queue<DrawerNodeClass> drawingQueue, BehaviorTree bt) { Queue<INode> bfsQueue = new Queue<INode>(); bfsQueue.Enqueue(bt.Child); int i = 0; drawingQueue.Clear(); while (bfsQueue.Count > 0) { INode n = bfsQueue.Dequeue(); if (n != null) { DrawerNodeClass newElement = new DrawerNodeClass(); newElement.Index = i; newElement.Node = n; newElement.Depth = CountDepth(n); newElement.Parent = GetParent(drawingQueue, n.GetParent(), newElement.Depth - 1); drawingQueue.Enqueue(newElement); i++; Type t = n.GetType(); if (t == typeof(Decorator)) { FillQueueWithDecorator(bfsQueue, (Decorator)n); } else if (t == typeof(Sequence)) { FillQueueWithSequence(bfsQueue, (Sequence)n); } else if (t == typeof(Selector)) { FillQueueWithSelector(bfsQueue, (Selector)n); } } } int maxDepth = 0; foreach (DrawerNodeClass dnc in drawingQueue) { if (dnc.Depth > maxDepth) { maxDepth = dnc.Depth; } } maxDepth += 1; _widths = new int[maxDepth]; foreach (DrawerNodeClass dnc in drawingQueue) { dnc.Width = _widths[dnc.Depth]; if(dnc.Parent != null && dnc.Width < dnc.Parent.Width) { dnc.Width = Mathf.Max(dnc.Width, dnc.Parent.Width); _widths[dnc.Depth] = dnc.Parent.Width; } _widths[dnc.Depth] += 1; dnc.CalculateRect(); } BehaviorTreeEditor.BTEditorWindow.Repaint(); }