예제 #1
0
		public BTConditionEvaluator (BTLogic logicOpt, bool reevaluateEveryTick, ClearChildOpt clearOpt, BTNode child = null) : base (child) {
			this._conditionals = new List<BTConditional>();
			this._conditionalInverts = new List<bool>();
			this.logicOpt = logicOpt;
			this.reevaludateEveryTick = reevaluateEveryTick;
			this.clearOpt = clearOpt;
		}
예제 #2
0
 public void AddChild(BTNode node, bool selectForClear)
 {
     AddChild(node);
     if (selectForClear) {
         selectedChildrenForClear.Add(node);
     }
 }
예제 #3
0
		public override void Clear () {
			if (_activeChild != null) {
				_activeChild.Clear();
				_activeChild = null;
			}

		}
예제 #4
0
		public virtual void AddChild (BTNode aNode) {
			if (_children == null) {
				_children = new List<BTNode>();	
			}
			if (aNode != null) {
				_children.Add(aNode);
			}
		}
예제 #5
0
파일: BTTree.cs 프로젝트: zs9024/Jungle
        void Start()
        {
            _root = Init();

            if (_root.name == null) {
                _root.name = "Root";
            }
            _root.Activate(_database);
        }
예제 #6
0
		public void SetPrimaryChild (BTNode node, bool selectForClear = false) {
			if (_primaryChild != null) {
				selectedChildrenForClear.Remove(_primaryChild);
			}

			_primaryChild = node;
			if (selectForClear) {
				selectedChildrenForClear.Add(_primaryChild);
			}
		}
예제 #7
0
		public override void Clear () {
			if (_activeChild != null) {
				_activeChild = null;
				_activeIndex = -1;
			}

			foreach (BTNode child in children) {
				child.Clear();
			}
		}
예제 #8
0
		public override BTResult Tick () {
			if (_activeChild == null) {
				return BTResult.Ended;
			}

			BTResult result = _activeChild.Tick();
			if (result != BTResult.Running) {
				_activeChild.Clear();
				_activeChild = null;
			}
			return result;
		}
예제 #9
0
		protected override bool DoEvaluate () {
			if (_activeChild != null) {
				bool result = _activeChild.Evaluate();
				if (!result) {
					_activeChild.Clear();
					_activeChild = null;
					_activeIndex = -1;
				}
				return result;
			}
			else {
				return children[0].Evaluate();
			}
		}
예제 #10
0
		// selects the active child
		protected override bool DoEvaluate () {
			foreach (BTNode child in children) {
				if (child.Evaluate()) {
					if (_activeChild != null && _activeChild != child) {
						_activeChild.Clear();	
					}
					_activeChild = child;
					return true;
				}
			}

			if (_activeChild != null) {
				_activeChild.Clear();
				_activeChild = null;
			}

			return false;
		}
예제 #11
0
		public override BTResult Tick () {
			// first time
			if (_activeChild == null) {
				_activeChild = children[0];
				_activeIndex = 0;
			}

			BTResult result = _activeChild.Tick();
			if (result == BTResult.Ended) {	// Current active node over
				_activeIndex++;
				if (_activeIndex >= children.Count) {	// sequence is over
					_activeChild.Clear();
					_activeChild = null;
					_activeIndex = -1;
				}
				else {	// next node
					_activeChild.Clear();
					_activeChild = children[_activeIndex];
					result = BTResult.Running;
				}
			}
			return result;
		}
예제 #12
0
 public override void RemoveChild(BTNode aNode)
 {
     Debug.LogError("BTAction: Cannot remove a node into BTAction.");
 }
예제 #13
0
 public override void AddChild(BTNode aNode)
 {
     base.AddChild(aNode);
     _activeList.Add(false);
 }
예제 #14
0
 protected BTNodeType(BTNode node)
 {
     BelongNode = node;
 }
예제 #15
0
 public Composite(BTNode node) : base(node)
 {
 }
예제 #16
0
		public override void AddChild (BTNode aNode) {
			base.AddChild (aNode);
			_activeList.Add(false);
		}
예제 #17
0
		Type CreateNodeTypeDropdown( BTNode node )
		{
			int selectedType = ( node != null ? Array.IndexOf<Type>( nodeTypes, node.GetType() ) : Array.IndexOf<Type>( nodeTypes, typeof( BTActionBlank ) ) );
			Rect rect = new Rect( 0, 0, _nodeWidth - 40.0f, 20.0f );
			selectedType = EditorGUI.Popup( rect, selectedType, nodeTypeNames );
			return nodeTypes[selectedType];
		}
예제 #18
0
 public void AddChild(BTNode pChild)
 {
     pChild.mParent = this;
     this.mChildren.Add(pChild);
 }
예제 #19
0
파일: BTTimer.cs 프로젝트: dqtoy/ActDemo
 public BTTimer(float interval, BTNode child) : base(child)
 {
     this.mInterval = interval;
 }
예제 #20
0
 public void AddOrphanNode(BTNode node)
 {
     OrphanNodeDict.Add(node.Guid, node);
 }
예제 #21
0
 public void RemoveNode(BTNode node)
 {
     BTNodeDict.Remove(node.Guid);
 }
예제 #22
0
 public void AddNode(BTNode node)
 {
     BTNodeDict.Add(node.Guid, node);
 }
예제 #23
0
 public BTRepeater(bool endOnFailure, BTNode child = null) : this(0, true, endOnFailure, child)
 {
 }
예제 #24
0
 public BTInverter(BTNode child) : base(child)
 {
 }
예제 #25
0
		public virtual void RemoveChild (BTNode aNode) {
			if (_children != null && aNode != null) {
				_children.Remove(aNode);
			}
		}
예제 #26
0
 public void DelChild(BTNode pChild)
 {
     this.mChildren.Remove(pChild);
 }
예제 #27
0
		void DeleteNode( BTNode node, bool deleteEditorData = true )
		{
			if ( node is BTDecorator && ( (BTDecorator)node ).child )
			{
				DeleteNode( ( (BTDecorator)node ).child );
			}
			else if ( node is BTComposite && ( (BTComposite)node ).children != null )
			{
				foreach ( BTNode child in ( (BTComposite)node ).children )
				{
					DeleteNode( child );
				}
			}

			if ( deleteEditorData )
			{
				// Remove the editor data from the list held by the behavior tree.
				_behaviorTree._editorData.Remove( _editorData[node.id] );

				// Remove the data from the local dict.
				_editorData.Remove( node.id );
			}

			DestroyImmediate( node, true );
		}
예제 #28
0
 public void RemoveChild(BTNode node)
 {
     ChildNodes.Remove(node);
 }
예제 #29
0
 public BTRepeater(int count, bool endOnFailure, BTNode child = null) : this(count, false, endOnFailure, child)
 {
 }
예제 #30
0
파일: BTRepeater.cs 프로젝트: zs9024/BTtree
		private BTRepeater (int count, bool repeatForever, bool endOnFailure, BTNode child = null) : base (child) {
			this.count = count;
			this.repeatForever = repeatForever;
			this.endOnFailure = endOnFailure;
		}
예제 #31
0
 public Task(BTNode node) : base(node)
 {
 }
예제 #32
0
파일: BTRepeater.cs 프로젝트: zs9024/BTtree
		public BTRepeater (int count, bool endOnFailure, BTNode child = null) : this (count, false, endOnFailure, child) {}
예제 #33
0
 public Decorator(BTNode node) : base(node)
 {
 }
예제 #34
0
파일: BTRepeater.cs 프로젝트: zs9024/BTtree
		public BTRepeater (bool endOnFailure, BTNode child = null) : this (0, true, endOnFailure, child) {}
예제 #35
0
파일: BTTimer.cs 프로젝트: zs9024/BTtree
		public BTTimer (float interval, BTNode child = null) : base (child) {
			this.interval = interval;
		}
예제 #36
0
 public BTDecorator(BTNode node)
 {
     this.child = node;
 }
예제 #37
0
 public override void AddChild(BTNode aNode)
 {
     Debug.LogError("BTAction: Cannot add a node into BTAction.");
 }
예제 #38
0
		public override void AddChild (BTNode aNode) {
			base.AddChild (aNode);
			_results.Add(BTResult.Running);
		}
예제 #39
0
 public void RemoveChild(BTNode node)
 {
     children.Remove(node);
     selectedChildrenForClear.Remove(node);
 }
예제 #40
0
		public override void RemoveChild (BTNode aNode) {
			int index = _children.IndexOf(aNode);
			_results.RemoveAt(index);
			base.RemoveChild (aNode);
		}
예제 #41
0
		public void RemoveChild (BTNode node) {
			children.Remove(node);
			selectedChildrenForClear.Remove(node);
		}
예제 #42
0
파일: BTInverter.cs 프로젝트: zs9024/BTtree
		public BTInverter (BTNode child = null) : base (child) {}
예제 #43
0
		void DrawNode( BTNode node )
		{
			if ( !node )
			{
				Debug.LogError( "Node is null!" );
				return;
			}

			// Handle children.
			if ( node is BTDecorator )
			{
				DrawDecorator( (BTDecorator)node );
			}
			else if ( node is BTComposite )
			{
				DrawCompositor( (BTComposite)node );
			}
			else
			{
				DrawLeaf( (BTLeaf)node );
			}
		}
예제 #44
0
		public override void RemoveChild (BTNode aNode) {
			Debug.LogError("BTAction: Cannot remove a node into BTAction.");
		}
예제 #45
0
		BTNode CreateNodeWithParent( Type nodeType, BTNode parent )
		{
			BTNode newNode = CreateNode( nodeType );
			EditorData nodeData = new EditorData( newNode, parent );
			nodeData.rect.position = _editorData[parent.id].rect.position + new Vector2( 0.0f, 100.0f );
			_behaviorTree._editorData.Add( nodeData );
			BuildEditorData();
			return newNode;
		}
예제 #46
0
 public BTNode(int d)
 {
     data = d;
     left = right = null;
 }
예제 #47
0
		public EditorData( BTNode node, BTNode parent )
		{
			this.node = node;
			this.parent = parent;
			this.id = node.id;

			if ( parent is BTComposite )
			{
				// EditorData is always created before adding the node
				// to the parent's list of children, so we can assume its
				// index with be _children.Count.
				parentIndex = ( (BTComposite)parent ).children.Count;
			}
		}
예제 #48
0
 public Root(BTNode node) : base(node)
 {
 }
예제 #49
0
		public override void RemoveChild (BTNode aNode) {
			int index = _children.IndexOf(aNode);
			_activeList.RemoveAt(index);
			base.RemoveChild (aNode);
		}
예제 #50
0
 private BTRepeater(int count, bool repeatForever, bool endOnFailure, BTNode child = null) : base(child)
 {
     this.count         = count;
     this.repeatForever = repeatForever;
     this.endOnFailure  = endOnFailure;
 }
예제 #51
0
		public override void AddChild (BTNode aNode) {
			Debug.LogError("BTAction: Cannot add a node into BTAction.");
		}
예제 #52
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;
                _editorData[((BTDecorator)newNode).child.id].parent = ((BTDecorator)newNode);
            }
            else if (oldNode is BTComposite && newNode is BTComposite)
            {
                ((BTComposite)newNode).children = ((BTComposite)oldNode).children;
                ((BTComposite)oldNode).children = null;
                for (int i = 0; i < ((BTComposite)newNode).children.Count; i++)
                {
                    _editorData[((BTComposite)newNode).children[i].id].parent = ((BTComposite)newNode);
                }
            }
            else if (oldNode is BTDecorator && newNode is BTComposite)
            {
                ((BTComposite)newNode).children = new List <BTNode> {
                    ((BTDecorator)oldNode).child
                };
                ((BTDecorator)oldNode).child = null;
                _editorData[((BTComposite)newNode).children[0].id].parent = ((BTComposite)newNode);
            }
            else if (oldNode is BTComposite && newNode is BTDecorator)
            {
                if (((BTComposite)oldNode).children.Count > 0)
                {
                    ((BTDecorator)newNode).child = ((BTComposite)oldNode).children[0];
                    _editorData[((BTDecorator)newNode).child.id].parent = ((BTDecorator)newNode);
                }
                ((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();
        }
예제 #53
0
		public BTDecorator (BTNode node) {
			this.child = node;
		}
 public void AddChild(BTNode child)
 {
     NameDisambiguation(child.Name);
     children.Add(child);
 }