예제 #1
0
        void DrawDecorator(BTDecorator decorator)
        {
            EditorData nodeData = _editorData[decorator.id];

            CreateNodeWindow(nodeData, _nodeWidth, _decoratorHeight);

            // ensure that the node has a child
            if (!decorator.child)
            {
                decorator.child = CreateNodeWithParent(typeof(BTActionBlank), decorator);
            }

            EditorData childData = _editorData[decorator.child.id];

            if (DrawPlusButton(nodeData, childData))
            {
                BTDecorator newNode = (BTDecorator)CreateNodeWithParent(typeof(BTInverter), decorator);
                newNode.child   = decorator.child;
                decorator.child = newNode;
            }

            // handle drawing the child
            DrawNodeCurve(nodeData.rect, childData.rect);
            DrawNode(decorator.child);
        }
예제 #2
0
        void ReplaceNode(EditorData nodeData, Type newType)
        {
            BTNode oldNode = nodeData.node;
            BTNode newNode = CreateNode(newType);

            // Transfer editor data.
            newNode.id    = nodeData.id;
            nodeData.node = newNode;

            // Swap children, then delete old node.
            if (oldNode is BTDecorator && newNode is BTDecorator)
            {
                ((BTDecorator)newNode).child = ((BTDecorator)oldNode).child;
                ((BTDecorator)oldNode).child = null;
            }
            else if (oldNode is BTComposite && newNode is BTComposite)
            {
                ((BTComposite)newNode).children = ((BTComposite)oldNode).children;
                ((BTComposite)oldNode).children = null;
            }
            DeleteNode(oldNode, false);

            // Update parent's reference to the node.
            if (nodeData.parent)
            {
                if (nodeData.parent is BTDecorator)
                {
                    BTDecorator parentDecorator = (BTDecorator)nodeData.parent;
                    parentDecorator.child = nodeData.node;
                }
                else if (nodeData.parent is BTComposite)
                {
                    BTComposite parentCompositor = (BTComposite)nodeData.parent;
                    parentCompositor.children[nodeData.parentIndex] = nodeData.node;
                }
                else
                {
                    Debug.LogError("Parent node is neither a Decorator nor a Compositor!");
                }
            }
            else
            {
                // Node is root node.
                _behaviorTree.root = nodeData.node;
            }

            // Editor data will have changed, so we must rebuild
            // it before continuing with rendering the GUI.
            BuildEditorData();
        }
예제 #3
0
        void DrawCompositor(BTComposite compositor)
        {
            EditorData nodeData = _editorData[compositor.id];

            CreateNodeWindow(nodeData, _nodeWidth, _compositorHeight);

            for (int index = 0; index < compositor.children.Count; ++index)
            {
                BTNode     child     = compositor.children[index];
                EditorData childData = _editorData[child.id];

                if (DrawPlusButton(nodeData, childData))
                {
                    BTDecorator newChild = (BTDecorator)CreateNodeWithParent(typeof(BTInverter), compositor);
                    newChild.child             = child;
                    compositor.children[index] = newChild;

                    _editorData[newChild.id].parentIndex = index;

                    child = newChild;
                }

                if (index > 0 &&
                    DrawLeftButton(childData))
                {
                    SwapCompositorChildren(compositor, index, index - 1);
                }

                if (index < compositor.children.Count - 1 &&
                    DrawRightButton(childData))
                {
                    SwapCompositorChildren(compositor, index, index + 1);
                }

                DrawNodeCurve(nodeData.rect, childData.rect, index, compositor.children.Count);
                DrawNode(child);
            }
        }
예제 #4
0
		void DrawDecorator( BTDecorator decorator )
		{
			EditorData nodeData = _editorData[decorator.id];
			CreateNodeWindow( nodeData, _nodeWidth, _decoratorHeight );

			// ensure that the node has a child
			if ( !decorator.child )
			{
				decorator.child = CreateNodeWithParent( typeof( BTActionBlank ), decorator );
			}

			EditorData childData = _editorData[decorator.child.id];

			if ( DrawPlusButton( nodeData, childData ) )
			{
				BTDecorator newNode = (BTDecorator)CreateNodeWithParent( typeof( BTInverter ), decorator );
				newNode.child = decorator.child;
				decorator.child = newNode;
			}

			// handle drawing the child
			DrawNodeCurve( nodeData.rect, childData.rect );
			DrawNode( decorator.child );
		}