public override WorldState getGoalState() { var goalState = _planner.createWorldState(); if (goal != null) { foreach (var condition in goal.conditions) { goalState.set(cond.GetName(condition.id), condition.value); } } return(goalState); }
public void Setup(AIScenario scenario, GameObject target) { // foreach ( var condition in conditions ) { // if ( condition.Value != null ) { // if ( condition.Value is MonoBehaviour ) { // Object.DestroyImmediate ( condition.Value as MonoBehaviour ); // } // } // } resetPlanner(); conditions.Clear(); foreach (var condition in scenario.conditions.list) { if (condition.type != null) { conditions.Add(condition.name, (AICondition)condition.Load()); AICondition cond = conditions[condition.name]; if (cond == null) { Debug.LogError($"AIScenarioAgent::Setup AICondition:{condition.name} == null"); continue; } cond.agent = this; cond.gameObject = target; cond.transform = target.transform; cond.Awake(); } } goals = scenario.goals; cond = scenario.conditions; foreach (var action in scenario.actions) { if (!action.isActived) { continue; } var actionIns = new Action(action.name, action.cost); foreach (var pre in action.pre) { actionIns.setPrecondition(cond.GetName(pre.id), pre.value); // Debug.Log ( $"setPrecondition: {cond.GetName ( pre.id )} {pre.value}" ); } foreach (var post in action.post) { actionIns.setPostcondition(cond.GetName(post.id), post.value); // Debug.Log ( $"setPostcondition: {cond.GetName ( post.id )} {post.value}" ); } _planner.addAction(actionIns); } if (goals != null && goals.Length != 0) { SetupGoal(goals[0]); } }