private static void DrawBlackboard(BehaviorTreeExecutor treeExecutor, SerializedProperty blackboard)
 {
     if (treeExecutor.tree == null)
     {
         return;
     }
     EditorGUILayout.Space(10);
     EditorGUILayout.LabelField("Blackboard");
     EditorGUILayout.PropertyField(blackboard);
     //if (GUILayout.Button("Create variable override"))
     //{
     //    treeExecutor.RebuildInstanceOverrideList();
     //    GenericMenu instanceOverrideMenu = new GenericMenu();
     //    CreateListMenuItems(treeExecutor.tree.blackboard.bools, treeExecutor.variableOverrides.bools, instanceOverrideMenu);
     //    CreateListMenuItems(treeExecutor.tree.blackboard.ints, treeExecutor.variableOverrides.ints, instanceOverrideMenu);
     //    CreateListMenuItems(treeExecutor.tree.blackboard.floats, treeExecutor.variableOverrides.floats, instanceOverrideMenu);
     //    CreateListMenuItems(treeExecutor.tree.blackboard.strings, treeExecutor.variableOverrides.strings, instanceOverrideMenu);
     //    CreateListMenuItems(treeExecutor.tree.blackboard.Colors, treeExecutor.variableOverrides.Colors, instanceOverrideMenu);
     //    CreateListMenuItems(treeExecutor.tree.blackboard.Vector2s, treeExecutor.variableOverrides.Vector2s, instanceOverrideMenu);
     //    CreateListMenuItems(treeExecutor.tree.blackboard.Vector3s, treeExecutor.variableOverrides.Vector3s, instanceOverrideMenu);
     //    CreateListMenuItems(treeExecutor.tree.blackboard.Vector4s, treeExecutor.variableOverrides.Vector4s, instanceOverrideMenu);
     //    CreateListMenuItems(treeExecutor.tree.blackboard.Vector2Ints, treeExecutor.variableOverrides.Vector2Ints, instanceOverrideMenu);
     //    CreateListMenuItems(treeExecutor.tree.blackboard.Vector3Ints, treeExecutor.variableOverrides.Vector3Ints, instanceOverrideMenu);
     //    CreateListMenuItems(treeExecutor.tree.blackboard.GameObjects, treeExecutor.variableOverrides.GameObjects, instanceOverrideMenu);
     //    if (instanceOverrideMenu.GetItemCount() == 0)
     //    {
     //        Debug.Log("You have not added any variables to the behavior tree's blackboard that can be overriden. Please do that first.", treeExecutor.tree);
     //        instanceOverrideMenu.AddDisabledItem(new GUIContent("No variables to override"));
     //    }
     //    instanceOverrideMenu.ShowAsContext();
     //}
 }
Exemple #2
0
    // This is called when the node is updated
    public override Result OnUpdate(BehaviorTreeExecutor behaviorTreeExecutor)
    {
        GameObject prefab = behaviorTreeExecutor.GetGameObjectVariable(prefabID);

        if (prefab == null)
        {
            return(Result.Failure);
        }
        GameObject spawnedObject;

        if (spawnAsChild)
        {
            spawnedObject = Instantiate(prefab, behaviorTreeExecutor.transform);
        }
        else
        {
            spawnedObject = Instantiate(prefab, behaviorTreeExecutor.transform.TransformPoint(prefab.transform.position), prefab.transform.rotation);
        }

        if (storeInVariable)
        {
            TypedVariable <GameObject> gameObjectVariableOverride = behaviorTreeExecutor.variableOverrides.GameObjects.Find(x => x.id == spawnedObjectID);
            if (gameObjectVariableOverride == null)
            {
                UnityEngine.Debug.LogWarning("Object ID " + spawnedObjectID + " not found in variable overrides of " + behaviorTreeExecutor.name);
            }
            else
            {
                gameObjectVariableOverride.value = spawnedObject;
            }
        }
        return(Result.Success);
    }
Exemple #3
0
 public override Result OnUpdate(BehaviorTreeExecutor behaviorTreeExecutor)
 {
     if (Time.time - startTime > duration)
     {
         return(Result.Success);
     }
     return(Result.Running);
 }
Exemple #4
0
    // This is called when the node is updated
    public override Result OnUpdate(BehaviorTreeExecutor behaviorTreeExecutor)
    {
        NavMeshAgent navMeshAgent = behaviorTreeExecutor.GetComponent <NavMeshAgent>();

        if (navMeshAgent == null)
        {
            UnityEngine.Debug.LogError(behaviorTreeExecutor + " has no nav mesh agent component assigned.", behaviorTreeExecutor);
        }
        navMeshAgent.isStopped = true;
        return(Result.Success);
    }
Exemple #5
0
        public override Result OnUpdate(BehaviorTreeExecutor behaviorTreeExecutor)
        {
            GameObject obj      = behaviorTreeExecutor.variableOverrides.GetGameObjectVariable(objectID);
            float      distance = Vector3.Distance(behaviorTreeExecutor.transform.position, obj.transform.position);

            if (distance <= range)
            {
                return(Result.Success);
            }
            return(Result.Failure);
        }
Exemple #6
0
        public override Result OnUpdate(BehaviorTreeExecutor behaviorTreeExecutor)
        {
            i = 0;
            Result result = Result.Success;

            for (; i < children.Count; i++)
            {
                result = children[i].BTUpdate(behaviorTreeExecutor);
            }
            return(result);
        }
Exemple #7
0
        public override Result OnUpdate(BehaviorTreeExecutor behaviorTreeExecutor)
        {
            switch (child.result)
            {
            case Result.Success:
                return(Result.Failure);

            case Result.Failure:
                return(Result.Success);

            case Result.Running:
                break;
            }
            return(Result.Running);
        }
Exemple #8
0
        public Result BTUpdate(BehaviorTreeExecutor behaviorTreeExecutor)
        {
            if (!started)
            {
                OnStart();
                started = true;
            }

            result = OnUpdate(behaviorTreeExecutor);

            if (result == Result.Failure || result == Result.Success)
            {
                OnStop();
                started = false;
            }
            return(result);
        }
Exemple #9
0
        public override Result OnUpdate(BehaviorTreeExecutor behaviorTreeExecutor)
        {
            for (; i < children.Count; i++)
            {
                Result result = children[i].BTUpdate(behaviorTreeExecutor);
                switch (result)
                {
                case Result.Failure:
                    i = 0;
                    return(result);

                case Result.Running:
                    return(result);
                }
            }
            i = 0;
            return(Result.Success);
        }
Exemple #10
0
    // This is called when the node is updated
    public override Result OnUpdate(BehaviorTreeExecutor behaviorTreeExecutor)
    {
        GameObject gameObject = behaviorTreeExecutor.GetGameObjectVariable(objectID);

        if (gameObject == null)
        {
            return(Result.Failure);
        }
        if (delay > 0)
        {
            Destroy(gameObject, delay);
        }
        else
        {
            Destroy(gameObject);
        }
        return(Result.Success);
    }
Exemple #11
0
    // This is called when the node is updated
    public override Result OnUpdate(BehaviorTreeExecutor behaviorTreeExecutor)
    {
        TypedVariable <GameObject> objectVariable = behaviorTreeExecutor.variableOverrides.GameObjects.Find(x => x.id == objectID);

        if (objectVariable == null)
        {
            return(Result.Failure);
        }
        GameObject objectToApplyForceTo = objectVariable.value;

        if (objectToApplyForceTo == null)
        {
            UnityEngine.Debug.LogError("No object to apply a force to", behaviorTreeExecutor);
            return(Result.Failure);
        }
        Rigidbody rigidbody = objectToApplyForceTo.GetComponent <Rigidbody>();

        if (rigidbody == null)
        {
            UnityEngine.Debug.LogError("Provided prefab object of " + name + " in behavior tree of " + behaviorTreeExecutor.name + " has no rigidbody.");
            return(Result.Failure);
        }

        switch (relativeObject)
        {
        default:
        case RelativeObjectOption.None:
            rigidbody.AddForce(force, forceMode);
            break;

        case RelativeObjectOption.Self:
            rigidbody.AddForce(
                behaviorTreeExecutor.transform.TransformVector(force),
                forceMode);
            break;

        case RelativeObjectOption.Other:
            rigidbody.AddForce(
                behaviorTreeExecutor.GetGameObjectVariable(otherObjectID).transform.TransformVector(force),
                forceMode);
            break;
        }
        return(Result.Success);
    }
Exemple #12
0
    // This is called when the node is updated
    public override Result OnUpdate(BehaviorTreeExecutor behaviorTreeExecutor)
    {
        GameObject obj = behaviorTreeExecutor.GetGameObjectVariable(objectID);

        if (obj == null)
        {
            return(Result.Failure);
        }

        Vector3 lookTarget = obj.transform.position;

        if (stayUpright)
        {
            lookTarget.y = behaviorTreeExecutor.transform.position.y;
        }

        behaviorTreeExecutor.transform.LookAt(lookTarget);
        return(Result.Success);
    }
Exemple #13
0
    // This is called when the node is updated
    public override Result OnUpdate(BehaviorTreeExecutor behaviorTreeExecutor)
    {
        if (conditionMet)
        {
            return(Result.Failure);
        }
        Result childResult = child.BTUpdate(behaviorTreeExecutor);

        switch (repeatCondition)
        {
        case RepeatCondition.Fail:
            if (childResult == Result.Failure)
            {
                conditionMet = true;
            }
            break;

        default:
            break;
        }
        return(childResult);
    }
        public static void Queue(IEnumerable <ProfileBehavior> profileBehaviors, ShouldRunCondition condition, string name = "")
        {
            var behaviorList = profileBehaviors.ToList();

            if (string.IsNullOrWhiteSpace(name))
            {
                name = behaviorList.Aggregate(name, (current, behavior) => current + (behavior.ToString() + ","));
            }

            var item = new QueueItem
            {
                Name      = name,
                Nodes     = behaviorList,
                Condition = condition,
            };

            Queue(item);

            if (!BotMain.IsRunning || BotMain.IsPausedForStateExecution)
            {
                BehaviorTreeExecutor.CreateBotThread();
            }
        }
    // This is called when the node is updated
    public override Result OnUpdate(BehaviorTreeExecutor behaviorTreeExecutor)
    {
        if (agent == null)
        {
            agent = behaviorTreeExecutor.GetComponent <NavMeshAgent>();
            if (agent == null)
            {
                UnityEngine.Debug.LogError(behaviorTreeExecutor.name + " has no NavMeshAgent component assigned but " + name + " is trying to access it.", behaviorTreeExecutor);
                return(Result.Failure);
            }
        }

        GameObject target = behaviorTreeExecutor.GetGameObjectVariable(targetID);

        if (target == null)
        {
            UnityEngine.Debug.LogError("Did not find target object with id " + targetID + " for " + GetType(), behaviorTreeExecutor);
            return(Result.Failure);
        }

        agent.SetDestination(target.transform.position);

        return(Result.Success);
    }
        public override void OnInspectorGUI()
        {
            BehaviorTreeExecutor treeExecutor = (BehaviorTreeExecutor)target;

            EditorGUI.BeginChangeCheck();
            treeExecutor.tree = (BehaviorTree)EditorGUILayout.ObjectField("Tree", treeExecutor.tree, typeof(BehaviorTree), false);
            if (EditorGUI.EndChangeCheck())
            {
                treeExecutor.RebuildInstanceOverrideList();
            }
            if (GUILayout.Button("Open editor"))
            {
                if (treeExecutor.tree == null)
                {
                    treeExecutor.tree = CreateInstance <BehaviorTree>();
                    treeExecutor.tree.SaveToNew("Behavior Tree");
                }
                BehaviorTreeEditorView.OpenBehaviorTreeWindow().Load(treeExecutor.tree);
            }

            SerializedProperty blackboard = serializedObject.FindProperty("variableOverrides");

            DrawBlackboard(treeExecutor, blackboard);
        }
Exemple #17
0
 public override Result OnUpdate(BehaviorTreeExecutor behaviorTreeExecutor)
 {
     return(Result.Failure);
 }
Exemple #18
0
 public override Result OnUpdate(BehaviorTreeExecutor behaviorTreeExecutor)
 {
     return(Result.Success);
 }
Exemple #19
0
 public override Result OnUpdate(BehaviorTreeExecutor behaviorTreeExecutor)
 {
     UnityEngine.Debug.Log("Update: " + message);
     return(Result.Success);
 }
Exemple #20
0
 public override Result OnUpdate(BehaviorTreeExecutor behaviorTreeExecutor)
 {
     child.BTUpdate(behaviorTreeExecutor);
     return(Result.Running);
 }
Exemple #21
0
 public abstract Result OnUpdate(BehaviorTreeExecutor behaviorTreeExecutor);