示例#1
0
        /// <summary>Get a component from the game object related to the current blackboard.</summary>
        protected T GetComponent <T>(string key) where T : MonoBehaviour
        {
            // Get Chooser.
            T component = BT.GetValue <T>(key) as T;

            if (component == null)
            {
                component = AddComponent <T>();
            }
            // Return it.
            return(component);
        }
示例#2
0
        /// <summary>Add a component to the game object related to the current blackboard.</summary>
        protected T AddComponent <T>() where T : MonoBehaviour
        {
            // Get game object.
            GameObject go = BT.GetValue <GameObject>("GameObject");

            if (go == null)
            {
                Debug.LogError("No game object running this finite state machine.");
                return(null);
            }
            // Add component and save it in blackboard.
            T component = go.AddComponent <T>();

            Debug.LogWarning(string.Format("Adding component {0} on execution.", component.ToString()));
            return(component);
        }
示例#3
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);
        }
示例#4
0
        /// <summary>Execute task.</summary>
        protected override BTGraphResult InternalRun()
        {
            // Get value of variable
            object target = GetBlackboardValue <object>("_target", _target, _notSet);

            // Make sure target is set.
            if (target == _notSet)
            {
                return(BTGraphResult.Failure);
            }
            // 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, target));
            }
            // Return success.
            return(BTGraphResult.Success);
        }