コード例 #1
0
        /// <summary>Execute the behavior tree in the blackboard.</summary>
        public override AIGraphResult Run(AIBlackboard blackboard)
        {
            // Save blackboard while executing.
            _blackboard = blackboard;
            // Execute root.
            BTGraphResult result = root.Run();

            // Nullify references to the blackboard.
            _blackboard = null;
            // Return result.
            return(result);
        }
コード例 #2
0
        /// <summary>Execute decorator.</summary>
        protected override BTGraphResult InternalRun()
        {
            // Set default exit value.
            BTGraphResult result = BTGraphResult.Success;

            // Execute all childs, exit when one succeeds.
            if (_child != null)
            {
                result = _child.Run();
            }
            // Return negation of result.
            return(result.Invert());
        }
コード例 #3
0
        /// <summary>Execute the Behavior Tree.</summary>
        protected override BTGraphResult InternalRun()
        {
            // Init loop.
            int[]  indices;
            object value;

            if (BT.Blackboard.variables.TryGetValue("CompositeIndices" + GetInstanceID(), out value))
            {
                indices = (int[])value;
            }
            else
            {
                indices = PrepareChildren();
            }
            // Traverse all children running them until break point.
            BTGraphResult result = BTGraphResult.Failure;

            for (int i = 0; i < indices.Length; i++)
            {
                // Run target child.
                BTConnection connection = _children[indices[i]];
                result = connection.Run();
                // Break if result is running.
                if (result.IsRunning)
                {
                    indices = indices.Where((a, index) => index >= i).ToArray();
                    BT.Blackboard.variables["CompositeIndices" + GetInstanceID()] = indices;
                    break;
                }
                // Check if we need to break loop.
                if (ShouldBreakLoop(result))
                {
                    break;
                }
            }

            // Reset running child index if not still running.
            if (!result.IsRunning)
            {
                BT.Blackboard.variables.Remove("CompositeIndices" + GetInstanceID());
            }

            return(result);
        }
コード例 #4
0
        /// <summary>Execute the subtree node.</summary>
        protected override BTGraphResult InternalRun()
        {
            // Check if machine has been initialized.
            AIBlackboard blackboard  = BT.Blackboard;
            object       initialized = null;

            blackboard.variables.TryGetValue("Init" + GetInstanceID(), out initialized);
            // If machine hasn't been initialized it is time to do so.
            if (initialized == null)
            {
                _tree.Init(blackboard);
                blackboard.variables["Init" + GetInstanceID()] = true;
            }

            // Execute and return isolating running statuses.
            BTGraphResult result = _tree.Run(blackboard) as BTGraphResult;

            return(result.IsRunning ? BTGraphResult.Success : result);
        }
コード例 #5
0
        /// <summary>Execute decorator.</summary>
        protected override BTGraphResult InternalRun()
        {
            // Set default exit value.
            BTGraphResult result = BTGraphResult.Success;

            // Execute all childs, exit when one succeeds.
            if (_child != null)
            {
                result = _child.Run();
            }
            // Only debug if the current game object is selected.
            GameObject go = BT.GetValue <GameObject>("GameObject");

            if (Selection.activeGameObject == go)
            {
                Debug.Log(string.Format("{0}: Result {1}", name, result));
            }
            // Return negation of result.
            return(result);
        }
コード例 #6
0
ファイル: Selector.cs プロジェクト: Ushio-Aria/qAI
 /// <summary>When to break the loop of children execution.</summary>
 protected override bool ShouldBreakLoop(BTGraphResult result)
 {
     return(result.IsSuccess);
 }
コード例 #7
0
 /// <summary>When to break the loop of children execution.</summary>
 protected override bool ShouldBreakLoop(BTGraphResult result)
 {
     return(result.IsFailure);
 }
コード例 #8
0
 /// <summary>Whether the last result should break exexcution or not.</summary>
 /// <param name="result">The result of the last executed child.</param>
 protected abstract bool ShouldBreakLoop(BTGraphResult result);