コード例 #1
0
        public override NodeStatus Tick(BehaviorBlackboard data)
        {
            Transform    player    = (Transform)data.Get("_BTD_Agent");
            Transform    target    = ((Transform)data.Get(entry));
            NavMeshAgent agent     = player.GetComponent <NavMeshAgent>();
            Vector3      playerPos = player.position;

            if (agent == null)
            {
                Debug.LogError("Behavor Tree Designer\nNo NavMeshAgent component found on node: " + this.name);
                return(NodeStatus.ERROR);
            }

            if (target == null)
            {
                return(NodeStatus.ERROR);
            }

            Vector3 targetPos = target.position;

            agent.stoppingDistance = stopDist;
            agent.destination      = targetPos;
            if (Vector3.Distance(targetPos, playerPos) < stopDist)
            {
                return(NodeStatus.SUCCESS);
            }
            else if (agent.hasPath)
            {
                return(NodeStatus.RUNNING);
            }
            else
            {
                return(NodeStatus.FAILURE);
            }
        }
コード例 #2
0
        public override NodeStatus Tick(BehaviorBlackboard data)
        {
            int index = (int)data.Get("_BTD_WaypointIndex");

            waypointParent = (Transform)data.Get("_BTD_Waypoint");

            if (waypointParent == null)
            {
                return(NodeStatus.FAILURE);
            }
            Waypoints waypoints = waypointParent.GetComponent <Waypoints>();

            if (!waypoints.circular && index == waypointParent.childCount - 1)
            {
                backwards = true;
            }
            if (!waypoints.circular && index == 0)
            {
                backwards = false;
            }

            if (backwards)
            {
                index--;
            }
            else
            {
                index++;
            }

            if (index >= waypointParent.childCount)
            {
                index = 0;
            }
            if (index < 0)
            {
                index = waypointParent.childCount - 1;
            }

            Transform target = waypointParent.GetChild(index);

            data.Add(entry, target);
            data.Add("_BTD_WaypointIndex", index);

            if (target == null)
            {
                return(NodeStatus.FAILURE);
            }

            return(NodeStatus.SUCCESS);
        }
コード例 #3
0
        public override NodeStatus Tick(BehaviorBlackboard data)
        {
            Transform agent = (Transform)data.Get("_BTD_Agent");
            Transform child = agent.Find(childName);

            if (child != null)
            {
                ColliderHelper colHelper = child.GetComponent <ColliderHelper>();
                if (colHelper != null)
                {
                    if (colHelper.trigger != null)
                    {
                        data.Add(entry, colHelper.trigger);
                        return(NodeStatus.SUCCESS);
                    }
                    else
                    {
                        return(NodeStatus.FAILURE);
                    }
                }
                else
                {
                    Debug.LogError("Behavor Tree Designer\nNo ColliderHelper script found on child: " + childName + " on object: " + agent.name);
                    return(NodeStatus.ERROR);
                }
            }
            else
            {
                Debug.LogError("Behavor Tree Designer\nChild: " + childName + " not found on object: " + agent.name);
                return(NodeStatus.ERROR);
            }
        }
コード例 #4
0
        public override NodeStatus Tick(BehaviorBlackboard data)
        {
            GameObject[] objects = GameObject.FindGameObjectsWithTag(selectedTag);
            Transform    agent;
            Transform    closest;
            float        minDist;

            if (objects.Length == 0)
            {
                return(NodeStatus.FAILURE);
            }

            agent   = (Transform)data.Get("_BTD_Agent");
            minDist = Vector3.Distance(agent.position, objects[0].transform.position);
            closest = objects[0].transform;

            for (int i = 1; i < objects.Length; i++)
            {
                float distance = Vector3.Distance(agent.position, objects[i].transform.position);
                if (distance < minDist)
                {
                    minDist = distance;
                    closest = objects[i].transform;
                }
            }

            data.Add(entry, closest);
            return(NodeStatus.SUCCESS);
        }
コード例 #5
0
ファイル: Wait.cs プロジェクト: Natsirtt/BehaviorTreeDesigner
        public override NodeStatus Tick(BehaviorBlackboard data)
        {
            if (this.Outputs[0].connections.Count == 0)
            {
                Debug.LogError("Behavor Tree Designer\nOutput node is not connected on node: " + this.name);
                return(NodeStatus.ERROR);
            }

            BaseBehaviorNode node = (BaseBehaviorNode)this.Outputs[0].connections[0].body;

            if (start)
            {
                data.Add(guid.ToString(), Time.time);
            }

            float time = (float)data.Get(guid.ToString());

            if (time + waitTime > Time.time)
            {
                start = false;
                return(NodeStatus.RUNNING);
            }
            else
            {
                start = true;
                return(node.Tick(data));
            }
        }
コード例 #6
0
        public override NodeStatus Tick(BehaviorBlackboard data)
        {
            if (this.Outputs[0].connections.Count == 0)
            {
                Debug.LogError("Behavor Tree Designer\nOutput node is not connected on node: " + this.name);
                return(NodeStatus.ERROR);
            }

            BaseBehaviorNode node   = (BaseBehaviorNode)this.Outputs[0].connections[0].body;
            NodeStatus       status = NodeStatus.SUCCESS;
            int rep = (int)data.Get(guid.ToString());

            status = node.Tick(data);

            if (status == NodeStatus.RUNNING)
            {
                return(status);
            }

            rep += 1;

            if (rep < repNumber)
            {
                status = NodeStatus.RUNNING;
                data.Add(guid.ToString(), rep);
            }
            else
            {
                data.Add(guid.ToString(), 0);
            }

            return(status);
        }
コード例 #7
0
        public override NodeStatus Tick(BehaviorBlackboard data)
        {
            NodeStatus retVal = NodeStatus.FAILURE;

            switch (entType)
            {
            case EntryType.BOOL:
                if (boolEntry == (bool)data.Get(entry))
                {
                    retVal = NodeStatus.SUCCESS;
                }
                break;

            case EntryType.INTEGER:
                if (intEntry == (int)data.Get(entry))
                {
                    retVal = NodeStatus.SUCCESS;
                }
                break;

            case EntryType.FLOAT:
                if (floatEntry == (float)data.Get(entry))
                {
                    retVal = NodeStatus.SUCCESS;
                }
                break;

            case EntryType.CLASS:
                if (data.Get(entry) != null)
                {
                    retVal = NodeStatus.SUCCESS;
                }
                break;

            default:
                retVal = NodeStatus.ERROR;
                break;
            }
            return(retVal);
        }
コード例 #8
0
        public override NodeStatus Tick(BehaviorBlackboard data)
        {
            object classObj;

            if (global)
            {
                classObj = data.GetGlobal(entry);
            }
            else
            {
                classObj = data.Get(entry);
            }
            if (classObj == null)
            {
                classObj = "null";
            }
            Debug.Log("Behavor Tree Designer Logger\nEntry: " + classObj);
            return(NodeStatus.SUCCESS);
        }
コード例 #9
0
        public override NodeStatus Tick(BehaviorBlackboard data)
        {
            GameObject[] objects = (GameObject[])GameObject.FindObjectsOfType(typeof(GameObject));
            Transform    agent;
            Transform    closest;
            float        minDist;

            if (objects.Length == 0)
            {
                return(NodeStatus.FAILURE);
            }

            List <GameObject> layerList = new List <GameObject>();

            for (int i = 0; i < objects.Length; i++)
            {
                if (objects[i].layer == selectedLayer)
                {
                    layerList.Add(objects[i]);
                }
            }

            agent   = (Transform)data.Get("Agent");
            minDist = Vector3.Distance(agent.position, objects[0].transform.position);
            closest = objects[0].transform;

            for (int i = 1; i < objects.Length; i++)
            {
                float distance = Vector3.Distance(agent.position, objects[i].transform.position);
                if (distance < minDist)
                {
                    minDist = distance;
                    closest = objects[i].transform;
                }
            }

            data.Add(entry, closest);
            return(NodeStatus.SUCCESS);
        }
コード例 #10
0
 public override void Init(BehaviorBlackboard data)
 {
     base.Init(data);
     anim = ((Transform)data.Get("_BTD_Agent")).GetComponent <Animator>();
 }