예제 #1
0
        public override NodeStatus Tick(BehaviorBlackboard data)
        {
            switch (entType)
            {
            case EntryType.BOOL:
                data.Add(entry, boolEntry);
                break;

            case EntryType.INTEGER:
                data.Add(entry, intEntry);
                break;

            case EntryType.FLOAT:
                data.Add(entry, floatEntry);
                break;

            case EntryType.CLASS:
                data.Add(entry, null);
                break;

            default:
                return(NodeStatus.ERROR);
            }
            return(NodeStatus.SUCCESS);
        }
예제 #2
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);
        }
예제 #3
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);
        }
        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);
            }
        }
예제 #5
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);
        }
예제 #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;

            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));
            }
        }
        private void Awake()
        {
            if (behaviorTree == null)
            {
                Debug.LogError("Behavor Tree Designer\nNo behavior assigned!");
                return;
            }
            if (agent == null)
            {
                Debug.LogError("Behavor Tree Designer\nNo agent assigned!");
                return;
            }

            data = new BehaviorBlackboard();
            data.Add("_BTD_Agent", agent);
            rootNode = behaviorTree.GetRootNode();
        }
        private void Start()
        {
            if (behaviorTree == null)
            {
                Debug.LogError("Behavor Tree Designer\nNo behavior assigned!");
                return;
            }
            if (agent == null)
            {
                Debug.LogError("Behavor Tree Designer\nNo agent assigned!");
                return;
            }

            data = new BehaviorBlackboard();
            data.Add("Agent", agent);
            rootNode = behaviorTree.GetRootNode();
            rootNode.Init(data);
            InvokeRepeating("DoTick", 0, tickTime);
        }
예제 #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);
     data.Add("_BTD_WaypointIndex", -1);
 }
예제 #11
0
 public override void Init(BehaviorBlackboard data)
 {
     base.Init(data);
     data.Add(guid.ToString(), 0.0f);
 }