Beispiel #1
0
        private void Start()
        {
            this.EnsureRequiredFieldsAreSetInEditor();

            // Init AI
            var knowledgeProvider = new KnowledgeProvider(this);
            var goalSelector      = new GoalSelector.Builder()
                                    .WithReevaluationPeriod(3.0f)
                                    .WithGoal(
                new Goal("BuildHouse",
                         new List <IPrecondition>
            {
                new IsTrue(new SymbolId("HouseBuilt"))
            }
                         ),
                () => town.House.IsBuilt ? -1 : 1
                )
                                    .WithGoal(
                new Goal("DestroyHouse",
                         new List <IPrecondition>
            {
                new IsTrue(new SymbolId("HouseBuilt"))
            }
                         ),
                () => town.House.IsBuilt ? 1 : -1
                )
                                    .WithGoal(
                new Goal("BuildHouse",
                         new List <IPrecondition>
            {
                new IsTrue(new SymbolId("HouseBuilt"))
            }
                         ),
                () => town.House.IsBuilt ? -1 : 1
                )
                                    .Build();
            var actionFactory = GetActionFactory();

            var planner      = new ForwardPlanner(100, 200, learn, experienceWeight);
            var planExecutor = new PlanExecutor(actionFactory);

            agent = new Agent(
                new AgentConfiguration.Builder()
                .WithKnowledgeProvider(knowledgeProvider)
                .WithGoalSelector(goalSelector)
                .WithPlanner(planner)
                .WithPlanExecutor(planExecutor)
                .Build()
                );

            navMeshAgent = GetComponent <NavMeshAgent>();
            DebugUtils.Assert(navMeshAgent != null, "{0} requires {1} to be present", GetType(), typeof(NavMeshAgent));

            // Init view
            toolAnimationTimer = new ResettableStopwatchExecutionTimer(true);

            // Init UI
            planExecutionStatePanel.PlanExecution = planExecutor.CurrentExecution;
        }
Beispiel #2
0
        void Start()
        {
            this.EnsureRequiredFieldsAreSetInEditor();

            // Init AI
            var knowledgeProvider = new KnowledgeProvider(this);
            var goalSelector      = new GoalSelector.Builder()
                                    .WithReevaluationPeriod(3.0f)
                                    .WithGoal(
                new Goal(
                    "BuildHouse",
                    new List <IPrecondition>()
            {
                new IsTrue(new SymbolId("HouseBuilt"))
            }
                    ),
                () => town.House.IsBuilt ? -1 : 1
                )
                                    .Build();
            var actionFactory = this.GetActionFactory();
            var planner       = new RegressivePlanner(20, 5);
            var planExecutor  = new PlanExecutor(actionFactory);

            this.agent = new Agent(
                new AgentEnvironment.Builder()
                .WithKnowledgeProvider(knowledgeProvider)
                .WithGoalSelector(goalSelector)
                .WithPlanner(planner)
                .WithPlanExecutor(planExecutor)
                .Build()
                );

            this.navMeshAgent = this.GetComponent <NavMeshAgent>();
            DebugUtils.Assert(this.navMeshAgent != null, "{0} requires {1} to be present", this.GetType(), typeof(NavMeshAgent));

            // Init view
            this.toolAnimationTimer = new ResettableExecutionTimer(true);

            // Init UI
            this.planExecutionStatePanel.PlanExecution = planExecutor.CurrentExecution;
        }