コード例 #1
0
    public BehaviorTree(string xmlPath, MonoBehaviour parent)
    {
        XmlReaderSettings settings = new XmlReaderSettings();
        settings.IgnoreComments = true;
        settings.ConformanceLevel = ConformanceLevel.Fragment;
        settings.ValidationType = ValidationType.None;

        this.parent = parent;

        using(XmlReader reader = XmlReader.Create(xmlPath, settings))
        {
            XDocument doc = XDocument.Load(reader);

            if (doc.Root.Name.ToString().ToLowerInvariant() != "behavior-tree")
                throw new XmlException("Behavior tree root node not found");

            if (doc.Root.Elements().Count() == 0)
                throw new XmlException("The behavior tree is empty!");

            if (doc.Root.Elements().Count() > 1)
                throw new XmlException("The behavior tree must have only one node at the top level");

            Dictionary<string, MethodInfo> leaves, conditions;

            LoadParentLeafFunctions(out leaves, out conditions);

            this.rootNode = ParseXmlElement(doc.Root.Elements().First(), leaves, conditions);
        }
    }
コード例 #2
0
 public void Add(object data)
 {
     if (!(data is IComparable))
         return;
     root = add_internal(root, (IComparable)data);
     count++;
 }
コード例 #3
0
    private void InitTree(BTNode source,AIDebugerTreeNode desc)
    {
        desc.m_NodeData = source;

        for (int i = 0; i < source.GetChildList().Count; ++i)
        {
            InitTree(source.GetChildList()[i], desc.m_ChildList[i]);
        }
    }
コード例 #4
0
		//Duplicate a node along with all children hierarchy
		static Node DuplicateBranch(BTNode root, Graph targetGraph){
			
			if (targetGraph == null)
				return null;

			var newNode = root.Duplicate(targetGraph);
			var dupConnections = new List<Connection>();
			for (var i = 0; i < root.outConnections.Count; i++)
				dupConnections.Add( root.outConnections[i].Duplicate(newNode, DuplicateBranch( (BTNode)root.outConnections[i].targetNode, targetGraph) ));
			newNode.outConnections.Clear();
			foreach (var c in dupConnections)
				newNode.outConnections.Add(c);
			return newNode;
		}
コード例 #5
0
        private BTNode add_internal(BTNode base_node, IComparable data)
        {
            if (base_node == null)
                return(new BTNode(data));

            BTNode node = base_node;
            bool inserted = false;
            //do it iteratively. Recursion is performance killer
            while (!inserted)
            {
                if (node.data.CompareTo(data) < 0)
                {
                    if (node.left == null)
                    {
                        node.left = new BTNode(data);
                        node.left.parent = node;
                        node.left.next = node;
                        inserted = true;
                    }
                    else
                        node = node.left;
                }
                else if (node.data.CompareTo(data) > 0)
                {
                    if (node.right == null)
                    {
                        node.right = new BTNode(data);
                        node.right.parent = node;
                        node.right.next = findNextLargestNode(node);
                        inserted = true;
                    }
                    else
                        node = node.right;
                }
                else  //equal to insert as smallest in the right subtree
                {
                    node.right = add_internal(node.right, data);
                    // for the case when right node is null
                    if (node.right.next == null)
                    {
                        node.right.parent = node;
                        node.right.next = findNextLargestNode(node.right);
                    }
                    inserted = true;
                }
            }

            return base_node;
        }
コード例 #6
0
		///Create a new SubTree out of the branch of the provided root node
		static void MakeNestedSubTree(BTNode root){

			if (!UnityEditor.EditorUtility.DisplayDialog("Convert to SubTree", "This will create a new SubTree out of this branch.\nThe SubTree can NOT be unpacked later on.\nAre you sure?", "Yes", "No!"))
				return;

			var newNestedNode = root.graph.AddNode<SubTree>();
			var newBT = EditorUtils.CreateAsset<BehaviourTree>(true);

			if (newBT == null)
				return;

			newNestedNode.nestedGraph = newBT;
			newNestedNode.nodePosition = root.nodePosition;

			for (var i = 0; i < root.inConnections.Count; i++)
				root.inConnections[i].SetTarget(newNestedNode);

			root.inConnections.Clear();

			newBT.primeNode = DuplicateBranch(root, newBT);;
			DeleteBranch(root);

			UnityEditor.AssetDatabase.SaveAssets();
		}
コード例 #7
0
ファイル: BTEditorDialog.cs プロジェクト: swordlegend/army_ru
        public void OnBtnUtilSucClick()
        {
            BTNode node = this._instantiate("utlsuccess");

            this._scrollView.AddChild(node);
        }
コード例 #8
0
ファイル: BTNode.cs プロジェクト: Cidolfas/CidUtils
 public BTNode AddChild(BTNode child)
 {
     children.Add(child); return child;
 }
コード例 #9
0
 protected Decorator(BTNode child)
 {
     this.child = child;
 }
コード例 #10
0
 public DecoratorNode(BehaviourTree T, BTNode c) : base(T)
 {
     child = c;
 }
コード例 #11
0
ファイル: BTEditorDialog.cs プロジェクト: swordlegend/army_ru
        public void OnBtnSubTreeClick()
        {
            BTNode node = this._instantiate("subtree");

            this._scrollView.AddChild(node);
        }
コード例 #12
0
 public void Reset()
 {
     current = null;
 }
コード例 #13
0
 public BTNode(T value)
 {
     this.Value = value;
     this.Left  = null;
     this.Right = null;
 }
コード例 #14
0
ファイル: BTEditorDialog.cs プロジェクト: swordlegend/army_ru
        public void OnBtnRetrunningClick()
        {
            BTNode node = this._instantiate("retrunning");

            this._scrollView.AddChild(node);
        }
コード例 #15
0
ファイル: BTEditorDialog.cs プロジェクト: swordlegend/army_ru
        public void OnBtnCountLimitClick()
        {
            BTNode node = this._instantiate("countlimit");

            this._scrollView.AddChild(node);
        }
コード例 #16
0
ファイル: BTEditorDialog.cs プロジェクト: swordlegend/army_ru
        public void OnBtnPersistWhileClick()
        {
            BTNode node = this._instantiate("persistwhile");

            this._scrollView.AddChild(node);
        }
コード例 #17
0
ファイル: BTEditorDialog.cs プロジェクト: swordlegend/army_ru
        public void OnBtnLoopUntilClick()
        {
            BTNode node = this._instantiate("loopuntil");

            this._scrollView.AddChild(node);
        }
コード例 #18
0
ファイル: BTEditorDialog.cs プロジェクト: swordlegend/army_ru
        public void OnBtnRandomSequenceClick()
        {
            BTNode node = this._instantiate("randomsequence");

            this._scrollView.AddChild(node);
        }
コード例 #19
0
 private BTNode findSmallestNode(BTNode base_node)
 {
     BTNode mover = base_node;
     while (base_node.left != null)
         mover = base_node.left;
     return mover;
 }
コード例 #20
0
            public bool MoveNext()
            {
                if (current == null)
                    current = btroot;
                else
                    current = current.next;

                if (current == null)
                    return false;
                return true;
            }
コード例 #21
0
ファイル: BTInverseDecoractor.cs プロジェクト: Akirame/IA-RTS
 public BTInverseDecoractor(BTNode node)
 {
     childNode = node;
 }
コード例 #22
0
ファイル: BTEditorDialog.cs プロジェクト: swordlegend/army_ru
        public void OnBtnUtilFailClick()
        {
            BTNode node = this._instantiate("utlfail");

            this._scrollView.AddChild(node);
        }
コード例 #23
0
 public ActionDie(BTNode _parent)
     : base(_parent)
 {
 }
コード例 #24
0
		///Delete the whole branch of provided root node along with the root node
		static void DeleteBranch(BTNode root){
			var graph = root.graph;
			foreach ( var node in root.GetAllChildNodesRecursively(true).ToArray() )
				graph.RemoveNode(node);
		}
コード例 #25
0
 public FleeDecorator(BTNode WrappedNode, Blackboard bb) : base(WrappedNode, bb)
 {
     zBB = (ZombieBB)bb;
 }
コード例 #26
0
 public ActionMoveToPoint(BTNode _parent)
     : base(_parent)
 {
 }
コード例 #27
0
 public BTDecoratorNode(BehaviorTree t, BTNode c) : base(t)
 {
     Child = c;
 }
コード例 #28
0
 protected override bool IsThisType(BTNode _btNode)
 {
     return(_btNode.GetType().IsSubclassOf(typeof(BTCompositeNode)));
 }
コード例 #29
0
ファイル: BTDecorator.cs プロジェクト: twglhk/Unity-Lib
 public BTDecorator(BehaviourTree tree, BTNode child) : base(tree)
 {
     Child = child;
 }
コード例 #30
0
 public override bool ContainsChild(BTNode child)
 {
     throw new System.InvalidOperationException(string.Format("{0} cannot have child connections", this));
 }
コード例 #31
0
    private void DivideArea(BTNode node)
    {
        int w = node.area.width;
        int h = node.area.height;
        int division; //1 means vertical, 0 means horizontal

        if (w < minAreaWidth)
        {
            if (h < minAreaHeight)
            {
                CreateRoom(node);
                return;
            }
            else
            {
                division = 0;
            }
        }
        else if (h < minAreaHeight)
        {
            division = 1;
        }
        else
        {
            division = pseudoRandom.Next(0, 2);
        }

        BTNode newLeaf1, newLeaf2;
        BTArea newArea1, newArea2;

        if (division == 0) // horizontal bisection
        {
            int lowend         = node.area.btmLeft.tileY + offset;
            int highend        = node.area.btmLeft.tileY + node.area.height - offset;
            int divisionHeight = pseudoRandom.Next(lowend, highend);

            newArea1 = new BTArea(node.area.btmLeft, node.area.width, divisionHeight - node.area.btmLeft.tileY);
            Tile newTile = new Tile(node.area.btmLeft.tileX, divisionHeight + 1);
            newArea2 = new BTArea(newTile, node.area.width, node.area.btmLeft.tileY + node.area.height - 1 - divisionHeight);

            newLeaf1 = new BTNode(newArea1, node);
            newLeaf2 = new BTNode(newArea2, node);
        }
        else // vertical bisection
        {
            int lowend        = node.area.btmLeft.tileX + offset;
            int highend       = node.area.btmLeft.tileX + node.area.width - offset;
            int divisionWidth = pseudoRandom.Next(lowend, highend);

            newArea1 = new BTArea(node.area.btmLeft, divisionWidth - node.area.btmLeft.tileX, node.area.height);
            Tile newTile = new Tile(divisionWidth + 1, node.area.btmLeft.tileY);
            newArea2 = new BTArea(newTile, node.area.btmLeft.tileX + node.area.width - 1 - divisionWidth, node.area.height);

            newLeaf1 = new BTNode(newArea1, node);
            newLeaf2 = new BTNode(newArea2, node);
        }

        node.child1 = newLeaf1;
        node.child2 = newLeaf2;

        DivideArea(newLeaf1);
        DivideArea(newLeaf2);
    }
コード例 #32
0
 public BehaviorTree(BTNode rootNode, MonoBehaviour parent)
 {
     this.rootNode = rootNode;
     this.parent = parent;
 }
コード例 #33
0
    private void CreateRoom(BTNode node)
    {
        int roomWidth;
        int roomHeight;
        int maxWidth, maxHeight;

        if (alternativeMinCheck)
        {
            if (node.area.width < minRoomWidth && node.area.height < minRoomHeight)
            {
                node = null;
                return;
            }
        }
        else
        {
            if (node.area.width < minRoomWidth || node.area.height < minRoomHeight)
            {
                node = null;
                return;
            }
        }
        roomCount++;

        if (maxRoomWidth > node.area.width)
        {
            maxWidth = node.area.width;
        }
        else
        {
            maxWidth = maxRoomWidth;
        }
        if (maxRoomHeight > node.area.height)
        {
            maxHeight = node.area.height;
        }
        else
        {
            maxHeight = maxRoomHeight;
        }


        if (node.area.width < minRoomWidth)
        {
            roomWidth = node.area.width;
        }
        else
        {
            roomWidth = pseudoRandom.Next(minRoomWidth, maxWidth + 1);
        }
        if (node.area.height < minRoomHeight)
        {
            roomHeight = node.area.height;
        }
        else
        {
            roomHeight = pseudoRandom.Next(minRoomHeight, maxHeight + 1);
        }

        int coordX = node.area.btmLeft.tileX + pseudoRandom.Next(0, node.area.width + 1 - roomWidth);
        int coordY = node.area.btmLeft.tileY + pseudoRandom.Next(0, node.area.height + 1 - roomHeight);

        BTRoom newRoom = new BTRoom(new Tile(coordX, coordY), roomWidth, roomHeight);

        node.area.rooms.Add(newRoom);
        DrawRooms(node.area.rooms);
    }
コード例 #34
0
        private BTNode findNextLargestNode(BTNode base_node)
        {
            BTNode mover = base_node;
            while (mover.parent != null && mover.parent.right == mover)
                mover = mover.parent;

            // reached root, base_node must be largest in the tree
            if (mover.parent == null)
                return null;

            if (mover.parent.left == mover)
                return mover;
            //should never get here
            return null;
        }
コード例 #35
0
    private List <BTRoom> ConnectRooms(BTNode node)
    {
        if (node.child1 == null && node.child2 == null)
        {
            return(node.area.rooms);
        }
        if (node.child1 == null)
        {
            List <BTRoom> roomComplex = ConnectRooms(node.child2);
            node.area.rooms.AddRange(roomComplex);
            return(node.area.rooms);
        }

        if (node.child2 == null)
        {
            List <BTRoom> roomComplex = ConnectRooms(node.child1);
            node.area.rooms.AddRange(roomComplex);
            return(node.area.rooms);
        }

        List <BTRoom> roomComplex1 = ConnectRooms(node.child1);
        List <BTRoom> roomComplex2 = ConnectRooms(node.child2);

        node.area.rooms.AddRange(roomComplex1);
        node.area.rooms.AddRange(roomComplex2);

        List <BTConnection> connectionsList = new List <BTConnection>();
        int bestDistance = -1;

        foreach (BTRoom room1 in roomComplex1)
        {
            BTConnection connectionBetweenRooms = null;
            foreach (BTRoom room2 in roomComplex2)
            {
                int          tmpBest;
                BTConnection tmpConnection = GetBestConnection(room1, room2, out tmpBest);

                if (tmpBest != -1 && (tmpBest < bestDistance || bestDistance == -1))
                {
                    bestDistance           = tmpBest;
                    connectionBetweenRooms = tmpConnection;
                }
            }

            if (connectionBetweenRooms != null)
            {
                connectionsList.Add(connectionBetweenRooms);
            }
            bestDistance = -1;
        }

        int depth             = GetTreeDepth(node);
        int connectionsAmount = pseudoRandom.Next(1 + depth / 3, 1 + depth / 2);

        for (int i = 0; i < connectionsAmount; i++)
        {
            if (connectionsList.Count == 0)
            {
                break;
            }

            int          index      = pseudoRandom.Next(0, connectionsList.Count);
            BTConnection connection = connectionsList[index];

            List <Tile> corridor = CreateCorridorRoom(connection);
            node.area.rooms.Add(new BTRoom(corridor));

            connectionsList.Remove(connection);
        }

        return(node.area.rooms);
    }
コード例 #36
0
 public BTEnumerator(BTNode _btroot)
 {
     btroot = _btroot;
     current = null;
 }
コード例 #37
0
ファイル: ActionIdle.cs プロジェクト: Enanyy/LuaGame-slua
 public ActionIdle(BTNode _parent)
     : base(_parent)
 {
 }
コード例 #38
0
 public BinaryTree()
 {
     root = null;
     threads = new ArrayList(4);
 }
コード例 #39
0
 public NodeCounter(BTNode child, float maxCount)
 {
     this.child    = child;
     this.maxCount = maxCount;
     count         = int.MaxValue;
 }
コード例 #40
0
 public BTNode(IComparable _data)
 {
     data = _data;
     left = null;
     right = null;
     parent = null;
     next = null;
 }
コード例 #41
0
ファイル: RepeaterNode.cs プロジェクト: gauravpba/Lumi
 public RepeaterNode(BehaviourTree T, BTNode child) : base(T, child)
 {
 }
コード例 #42
0
 public void Clear()
 {
     root = null;
 }
コード例 #43
0
ファイル: BehaviorTree.cs プロジェクト: Cidolfas/CidUtils
 // If you're new to this, take a look at http://www.altdevblogaday.com/2011/02/24/introduction-to-behavior-trees/
 public BehaviorTree(BTNode rootNode)
 {
     mp_root = rootNode;
 }
コード例 #44
0
ファイル: BTTreeWindow.cs プロジェクト: zs9024/Jungle
    private BTNodeInfo ParseNodeInfo(BTNode node, int level, int indexInParent)
    {
        int maxNodeSize = 1;
        List<BTNodeInfo> infos = new List<BTNodeInfo>();

        if (node is BTSimpleParallel) {		// simple parallel has a primary child
            BTSimpleParallel simpleParallel = (BTSimpleParallel) node;
            List<BTNode> children = simpleParallel.children;
            children.Insert(0, simpleParallel.primaryChild);

            if (children.Count > 0) {
                maxNodeSize = 0;
            }

            int i=0;
            foreach (BTNode child in children) {
                BTNodeInfo info = ParseNodeInfo(child, level+1, i++);
                maxNodeSize += info.maxNodeSize;
                infos.Add(info);
            }
        }
        else if (node is BTComposite) {
            BTComposite composite = (BTComposite) node;
            List<BTNode> children = composite.children;

            if (children.Count > 0) {
                maxNodeSize = 0;
            }

            int i=0;
            foreach (BTNode child in children) {
                BTNodeInfo info = ParseNodeInfo(child, level+1, i++);
                maxNodeSize += info.maxNodeSize;
                infos.Add(info);
            }
        }
        else if (node is BTDecorator) {
            BTDecorator decorator = (BTDecorator) node;

            if (decorator.child != null) {
                BTNodeInfo info = ParseNodeInfo(decorator.child, level+1, 0);
                if (info.maxNodeSize > maxNodeSize) {
                    maxNodeSize = info.maxNodeSize;
                }
                infos.Add(info);
            }
        }

        int countInLevel;
        _levelToCount.TryGetValue(level, out countInLevel);

        _levelToCount[level] = countInLevel + maxNodeSize;

        return new BTNodeInfo(node, infos, maxNodeSize, level, countInLevel, indexInParent);
    }
コード例 #45
0
ファイル: BTEditorDialog.cs プロジェクト: swordlegend/army_ru
        public void OnBtnSuccessClick()
        {
            BTNode node = this._instantiate("retsuccess");

            this._scrollView.AddChild(node);
        }
コード例 #46
0
 public BinaryTree()
 {
     root = null;
 }
コード例 #47
0
ファイル: BTEditorDialog.cs プロジェクト: swordlegend/army_ru
        public void OnBtnTaskClick()
        {
            BTNode node = this._instantiate("task");

            this._scrollView.AddChild(node);
        }
コード例 #48
0
 /// <summary>
 /// This method is used to add a new numeric value to a referenced instance
 /// </summary>
 /// <param name="data"></param>
 public void Insert(int data)
 {
     this.root = this.Insert(data, this.root);
 }
コード例 #49
0
 public ExecuteOnce(BTNode child) : base(child)
 {
 }
コード例 #50
0
ファイル: BTTreeWindow.cs プロジェクト: zs9024/Jungle
 public BTNodeInfo(BTNode node, List<BTNodeInfo> childrenInfo, int maxNodeSize, int level, int countInLevel, int indexInParent)
 {
     this.node = node;
     this.childrenInfo = childrenInfo;
     this.maxNodeSize = maxNodeSize;
     this.level = level;
     this.countInLevel = countInLevel;
     this.indexInParent = indexInParent;
 }
コード例 #51
0
ファイル: BTNotNode.cs プロジェクト: ViralKaos/Ambulance-Wars
 public BTNotNode(BTNode childNode)
 {
     this.childNode = childNode;
 }