コード例 #1
0
        private void UpdateActionQueue()
        {
            // If no more actions, remove goal and planner
            if (actionQueue != null && actionQueue.Count == 0)
            {
                if (currentGoal.remove)
                {
                    goals.Remove(currentGoal);
                }
                planner = null;
            }

            // If there are more actions to take, send the next one
            if (actionQueue != null && actionQueue.Count > 0)
            {
                currentAction = actionQueue.Dequeue();
                if (currentAction.PrePerform())
                {
                    if (currentAction.target == null && currentAction.targetTag != "")
                    {
                        currentAction.target = GameObject.FindWithTag(currentAction.targetTag);
                    }
                    if (currentAction.target != null)
                    {
                        currentAction.running = true;

                        destination = currentAction.target.transform.position;
                        Transform dest = currentAction.target.transform.Find("Destination");
                        if (dest != null)
                        {
                            destination = dest.position;
                        }
                        currentAction.agent.SetDestination(destination);
                    }
                }
                else
                {
                    actionQueue = null;
                }
            }
        }
コード例 #2
0
        private void FormPlan()
        {
            // If there is no plan or action queue
            if (planner == null || actionQueue == null)
            {
                planner = new GPlanner();

                // Sort the goals by importance
                var sortedGoals = from entry in goals orderby entry.Value descending select entry;

                // Form a plan from the first successful goal in the sorted dictionary of goals.
                foreach (KeyValuePair <SubGoal, int> sg in sortedGoals)
                {
                    actionQueue = planner.plan(actions, sg.Key.sgoals, beliefs);
                    if (actionQueue != null)
                    {
                        currentGoal = sg.Key;
                        break;
                    }
                }
            }
        }