/** * Updates the current goal */ public void UpdateCurrentGoal() { if (CurrentGoal != null) { if (CurrentGoal.UpdateGoal()) { if (CurrentGoal.ReplanRequired()) { ReplanCurrentGoal(); } if (CurrentGoal.IsPlanFinished()) // goal is finished, so clear it and make new one { CurrentGoal.Deactivate(); CurrentGoal = null; } } else { CurrentGoal.Deactivate(); CurrentGoal = null; } } }
public void Loop() { if (_currGoal == null) { _currGoal = FindNewGoal(); if (_currGoal == null) { return; } _currGoal.BuildPlan(actions, _ws); } else if (_currGoal.IsInterruptible()) { GOAPGoal newGoal = FindNewGoal(); // 遇见更优的目标 if (newGoal != null && /*newGoal.GoalType != _currGoal.GoalType &&*/ newGoal.Weight > _currGoal.Weight) { GOAPGoalFactory.Collect(_currGoal); _currGoal = newGoal; _currGoal.BuildPlan(actions, _ws); } } if (!_currGoal.UpdateGoal(_ws)) { GOAPGoalFactory.Collect(_currGoal); _currGoal = null; } }
void FindMostImportantGoal() { GOAPGoal newGoal = GetMostImportantGoal(CurrentGoal.GoalRelevancy); if (newGoal == null) { return; } if (newGoal == CurrentGoal) { //if (Owner.debugGOAP) Debug.Log(Time.timeSinceLevelLoad + " Current goal " + CurrentGoal.ToString() + ": " + "is most important still (" + newGoal.GoalRelevancy + ")"); return; } if (Owner.debugGOAP && CurrentGoal != null) { Debug.Log( Time.timeSinceLevelLoad + " More important goal (" + newGoal.ToString() + " >" + CurrentGoal.GoalRelevancy + ") " + Owner.WorldState.ToString(), Owner); } CreatePlan(newGoal); }
void CreatePlan(GOAPGoal goal) { GOAPPlan plan = BuildPlan(goal); if (plan == null) { if (Owner.debugGOAP) { Debug.Log(Time.timeSinceLevelLoad + " BUILD PLAN - " + goal.ToString() + " FAILED !!! " + Owner.WorldState.ToString(), Owner); } goal.SetDisableTime(); return; } if (CurrentGoal != null) { CurrentGoal.Deactivate(); CurrentGoal = null; } if (Owner.debugGOAP) { Debug.Log(Time.timeSinceLevelLoad + " BUILD " + goal.ToString() + " - " + plan.ToString() + " " + Owner.WorldState.ToString(), Owner); foreach (KeyValuePair <E_GOAPGoals, GOAPGoal> pair in Goals) { if (pair.Value != goal && pair.Value.GoalRelevancy > 0) { Debug.Log(pair.Value.ToString()); } } } CurrentGoal = goal; CurrentGoal.Activate(plan); }
/** * Updates the current goal */ public void UpdateCurrentGoal() { if (CurrentGoal != null) { if (CurrentGoal.UpdateGoal()) { if (CurrentGoal.ReplanRequired()) { if (Owner.debugGOAP) { Debug.Log(Time.timeSinceLevelLoad + " " + CurrentGoal.ToString() + " - REPLAN required !!"); } ReplanCurrentGoal(); } if (CurrentGoal.IsPlanFinished()) { // goal is finished, so clear it and make new one if (Owner.debugGOAP) { Debug.Log(Time.timeSinceLevelLoad + " " + CurrentGoal.ToString() + " - FINISHED"); } CurrentGoal.Deactivate(); CurrentGoal = null; } } else // something bad happened, clear it { CurrentGoal.Deactivate(); CurrentGoal = null; } } }
/** * Gets the most relevant goal at the moment * * GOAPGoal GetMostRelevantGoal(bool recalculate) * { * GOAPGoal maxGoal = null; * float highestRelevancy = 0.0f; * float currentTime = Time.timeSinceLevelLoad; * float nextEvalTime; * * float goalRelevance = 0.0f; * for (int i = 0; i < m_GoalSet.Count; i++) * { //First check for timing checks?! * //Don't recalculate the goal relevancy if not asked to do so * * if (recalculate) * { * nextEvalTime = m_GoalSet[i].NextEvaluationTime; * * if (currentTime < nextEvalTime) * { //clear relevancy , we dont want to select these goals * m_GoalSet[i].ClearGoalRelevancy(); * } * else if (!m_GoalSet[i].GetReEvalOnSatisfication() && m_GoalSet[i].IsWSSatisfied(Ai.GetWorldState())) * { * m_GoalSet[i].ClearGoalRelevancy(); * } * else * {// recalculate goal relevancy !!!! * m_GoalSet[i].CalculateGoalRelevancy(); * //m_GoalSet[i].SetNewEvaluationTime(); * //set new timing check time?! * * } * } * // check all goal relevancy * goalRelevance = m_GoalSet[i].GoalRelevancy; * if (goalRelevance > highestRelevancy) * { * highestRelevancy = goalRelevance; * maxGoal = m_GoalSet[i]; * } * * } * return maxGoal; * }*/ /** * Builds a new plan for this agent * @param the agent to build the plan for * @return true if the plan builds successfully, false otherwise */ public GOAPPlan BuildPlan(GOAPGoal goal) { if (goal == null) { return(null); } //if (Owner.debugGOAP) Debug.Log(Time.timeSinceLevelLoad + " " + goal.ToString() + " - build plan"); //initialize shit Map.Initialise(Owner); Goal.Initialise(Owner, Map, goal); Storage.ResetStorage(Map); AStar.End = -1; AStar.RunAStar(Owner); AStarNode currNode = AStar.CurrentNode; if (currNode == null || currNode.NodeID == -1) { Debug.LogError(Time.timeSinceLevelLoad + " " + goal.ToString() + " - FAILED , no node "); return(null); //Building of plan failed } GOAPPlan plan = new GOAPPlan(); //create a new plan GOAPAction action; /** * We need to push each new plan step onto the list of steps until we reach the last action * Which is going to be the goal node and of no use */ //if (Owner.debugGOAP) Debug.Log(Time.timeSinceLevelLoad + " " + goal.ToString() + " current node id :" + currNode.NodeID); while (currNode.NodeID != -1) { action = Map.GetAction(currNode.NodeID); if (action == null) //If we tried to cast an node to an action that can't be done, quit out { Debug.LogError(Time.timeSinceLevelLoad + " " + goal.ToString() + ": canot find action (" + currNode.NodeID + ")"); return(null); } plan.PushBack(action); currNode = currNode.Parent; } //Finally tell the ai what its plan is if (plan.IsDone()) { Debug.LogError(Time.timeSinceLevelLoad + " " + goal.ToString() + ": plan is already done !!! (" + plan.CurrentStepIndex + "," + plan.NumberOfSteps + ")"); return(null); } return(plan); }
GOAPGoal GetMostImportantGoal(float minRelevancy) { GOAPGoal maxGoal = null; float highestRelevancy = minRelevancy; GOAPGoal goal; for (int i = 0; i < m_GoalSet.Count; i++) { //First check for timing checks?! goal = m_GoalSet[i]; if (goal.IsDisabled()) { continue;//we dont want to select these goals } if (highestRelevancy >= goal.GetMaxRelevancy()) { continue; // nema cenu resit goal ktery ma mensi prioritu nez uz vybrany } if (goal.Active == false) {// recalculate goal relevancy !!!! goal.CalculateGoalRelevancy(); //m_GoalSet[i].SetNewEvaluationTime(); //set new timing check time?! } // check all goal relevancy if (goal.GoalRelevancy > highestRelevancy) { highestRelevancy = goal.GoalRelevancy; maxGoal = goal; } } return(maxGoal); }
void FindNewGoal() { if (CurrentGoal != null) { CurrentGoal.Deactivate(); CurrentGoal = null; } GOAPGoal newGoal = GetMostImportantGoal(0); if (newGoal == null) { //if (Owner.debugGOAP) Debug.Log(" Find new goal: none" ); return; } /*if (Owner.debugGOAP) * { * Debug.Log(" Find new goal: " + newGoal.ToString()); * * Debug.Log(Owner.WorldState.ToString()); * * for (int i = 0; i < m_GoalSet.Count; i++) * { * Debug.Log(m_GoalSet[i].ToString()); * } * }*/ CreatePlan(newGoal); }
public void AddGoal(GOAPGoal goal) { if (!mGoals.Contains(goal)) { mGoals.Add(goal); } }
void FindNewGoal() { if (CurrentGoal != null) { CurrentGoal.Deactivate(); CurrentGoal = null; } while (CurrentGoal == null) { GOAPGoal newGoal = GetMostImportantGoal(0); if (newGoal == null) { break; } if (Owner.debugGOAP) { Debug.Log("Find new goal " + newGoal.ToString() + "WorldState - " + Owner.WorldState.ToString()); } CreatePlan(newGoal); if (CurrentGoal == null) { newGoal.SetDisableTime(); } } }
public static void Collect(GOAPGoal goal) { if (goal == null) { return; } _buffers[(int)goal.GoalType].Enqueue(goal); }
/** * Adds the goal to the list of goals * @param the new goal */ public GOAPGoal AddGoal(E_GOAPGoals newGoal) { if (!IsGoalInGoalSet(newGoal)) { GOAPGoal goal = GOAPGoalFactory.Create(newGoal, Owner); m_GoalSet.Add(goal); return(goal); } return(null); }
/** * Adds the goal to the list of goals * @param the new goal */ public GOAPGoal AddGoal(E_GOAPGoals type) { if (Goals.ContainsKey(type) == false) { GOAPGoal goal = GOAPGoalFactory.Create(type, Owner); Goals.Add(type, goal); return(goal); } return(null); }
public void Reset() { if (curGoal != null) { curGoal.Deactivate(); curGoal = null; } for (int i = 0; i < mGoals.Count; i++) { mGoals[i].Reset(); } }
void CreatePlan(GOAPGoal goal) { GOAPPlan plan = BuildPlan(goal); if (plan == null) { Debug.LogError(Time.timeSinceLevelLoad + " " + goal.ToString() + " - BUILD PLAN FAILED !!!"); return; } CurrentGoal = goal; CurrentGoal.Activate(plan); }
/** * Reset the goal manager after a run */ public void Reset() { if (CurrentGoal != null) { CurrentGoal.Deactivate(); CurrentGoal = null; } foreach (KeyValuePair <E_GOAPGoals, GOAPGoal> pair in Goals) { pair.Value.Reset(); } }
/** * Reset the goal manager after a run */ public void Reset() { if (CurrentGoal != null) { CurrentGoal.Deactivate(); CurrentGoal = null; } for (int i = 0; i < m_GoalSet.Count; i++) { m_GoalSet [i].Reset(); } }
protected virtual GOAPGoal FindNewGoal() { if (goals.Length == 0) { return(null); } //if (_owner.BlackBoard.desiredTarget == null) //{ // return null; //} float maxWeight = 0; GOAPGoal maxGoal = null; foreach (var goalType in goals) { GOAPGoal goal = GOAPGoalFactory.Get(goalType, _owner); goal.CalcWeight(_ws, _owner.BlackBoard); if (goal.Weight > maxWeight) { maxWeight = goal.Weight; maxGoal = goal; } } return(maxGoal); /*if (Input.GetKeyUp(KeyCode.Alpha1)) * { * return GOAPGoalFactory.Get(GOAPGoalType.ATTACK_TARGET, _owner); * } * if (Input.GetKeyUp(KeyCode.Alpha2)) * { * return GOAPGoalFactory.Get(GOAPGoalType.BLOCK, _owner); * } * if (Input.GetKeyUp(KeyCode.Alpha3)) * { * return GOAPGoalFactory.Get(GOAPGoalType.STEP_IN, _owner); * } * if (Input.GetKeyUp(KeyCode.Alpha4)) * { * return GOAPGoalFactory.Get(GOAPGoalType.STEP_OUT, _owner); * } * if (Input.GetKeyUp(KeyCode.Alpha5)) * { * return GOAPGoalFactory.Get(GOAPGoalType.STEP_AROUND, _owner); * } * * return null;*/ }
public void Update() { if (curGoal == null) { return; } if (curGoal.Update()) { } else { curGoal.Deactivate(); curGoal = null; } }
GOAPGoal GetCriticalGoal() { GOAPGoal maxGoal = null; float highestRelevancy = 0.0f; float goalRelevance = 0.0f; if (CurrentGoal != null && CurrentGoal.Active) { goalRelevance = CurrentGoal.GoalRelevancy; } for (int i = 0; i < m_GoalSet.Count; i++) //First check for timing checks?! { if (m_GoalSet [i].IsDisabled()) { continue; //we dont want to select these goals } if (m_GoalSet [i].Critical == false) { continue; } if (m_GoalSet [i].Active == false) // recalculate goal relevancy !!!! { m_GoalSet [i].CalculateGoalRelevancy(); //m_GoalSet[i].SetNewEvaluationTime(); //set new timing check time?! } // check all goal relevancy goalRelevance = m_GoalSet [i].GoalRelevancy; if (goalRelevance > highestRelevancy) { highestRelevancy = goalRelevance; maxGoal = m_GoalSet [i]; } } return(maxGoal); }
GOAPGoal GetMostImportantGoal(float minRelevancy) { GOAPGoal maxGoal = null; float highestRelevancy = minRelevancy; GOAPGoal goal; foreach (KeyValuePair <E_GOAPGoals, GOAPGoal> pair in Goals) { //First check for timing checks?! goal = pair.Value; if (goal.IsDisabled()) { continue; //we dont want to select these goals } if (highestRelevancy >= goal.GetMaxRelevancy()) { continue; // nema cenu resit goal ktery ma mensi prioritu nez uz vybrany } if (goal.Active == false) { // recalculate goal relevancy !!!! goal.CalculateGoalRelevancy(); //m_GoalSet[i].SetNewEvaluationTime(); //set new timing check time?! } // check all goal relevancy if (goal.GoalRelevancy > highestRelevancy) { highestRelevancy = goal.GoalRelevancy; maxGoal = goal; } //if (Owner.debugGOAP) Debug.Log(i + "." + goal.ToString() + " relevancy:" + goal.GoalRelevancy); } return(maxGoal); }
/* * Activate the GOAP plan */ public bool Activate(Agent ai, GOAPGoal goal) { Owner = ai; /*if(ai.debugGOAP) * { * string s = this.ToString() + " - Activated for " + goal.ToString() + " do actions:"; * for (int i = 0 ; i < m_Actions.Count ; i++) * s += " " + m_Actions[i].ToString(); * * Debug.Log(Time.timeSinceLevelLoad + " " + s); * }*/ if (m_Actions.Count == 0) { return(false); } //Get the first action CurrentStep = 0; //For the first action, first check if context preconditions are satisfied. GOAPAction a = CurrentAction; if (a != null) { if (a.ValidateContextPreconditions(Owner) == false) {//Are the context preconditions validated???? //if (Owner.debugGOAP) Debug.Log(Time.timeSinceLevelLoad + " " + this.ToString() + " - " + a.ToString() + " ValidateContextPreconditions failed !!"); return(false); } a.Activate(); // if(a.IsActionComplete()) // AdvancePlan(); } return(true); }
void FindMostImportantGoal() { GOAPGoal newGoal = GetMostImportantGoal(CurrentGoal.GoalRelevancy); if (newGoal == null) { return; } if (newGoal == CurrentGoal) { //if (Owner.debugGOAP) Debug.Log(Time.timeSinceLevelLoad + " Current goal " + CurrentGoal.ToString() + ": " + "is most important still (" + newGoal.GoalRelevancy + ")"); return; } //if (Owner.debugGOAP) Debug.Log(Time.timeSinceLevelLoad + " " + CurrentGoal.ToString() + ": " + newGoal.ToString() + " is more important (" + newGoal.GoalRelevancy + ")"); /*if (Owner.debugGOAP) * { * Debug.Log("FindMostImportantGoal: " + newGoal.ToString()); * if (Owner.debugGOAP) Debug.Log(Owner.WorldState.ToString()); * * for (int i = 0; i < m_GoalSet.Count; i++) * { * Debug.Log(m_GoalSet[i].ToString()); * } * }*/ if (CurrentGoal != null) { CurrentGoal.Deactivate(); CurrentGoal = null; } CreatePlan(newGoal); }
public bool FindCriticalGoal() { GOAPGoal newGoal = GetCriticalGoal(); if (newGoal == null) { return(false); } if (newGoal == CurrentGoal) { //if (Owner.debugGOAP) Debug.Log(Time.timeSinceLevelLoad + " Current goal " + CurrentGoal.ToString() + ": " + "is most important still (" + newGoal.GoalRelevancy + ")"); return(false); } /*if (Owner.debugGOAP) * { * Debug.Log("CRITICAL GOAL: " + newGoal.ToString()); * * if (Owner.debugGOAP) Debug.Log(Owner.WorldState.ToString()); * * for (int i = 0; i < m_GoalSet.Count; i++) * { * Debug.Log(m_GoalSet[i].ToString()); * } * }*/ if (CurrentGoal != null) { CurrentGoal.Deactivate(); CurrentGoal = null; } CreatePlan(newGoal); return(true); }
public void AddGoal(GOAPGoal goal) { _goals.Add(goal); _dirty = true; }
//AgentHuman Owner; public void Initialise(AgentHuman ai, AStarGOAPMap map, GOAPGoal goal) { // Owner = ai; Map = map; Goal = goal; }
public GOAPPlan GetPlan(GOAPGoal goal) { return(null); }
void DrawBase() { AgentDebugInfo debugInfo = target as AgentDebugInfo; AgentHuman agent = debugInfo.GetComponent <AgentHuman>(); if (agent.Transform == null) { return; } BlackBoard bb = agent.BlackBoard; GUILayout.BeginVertical(); //GUILayout.Label("Base Settings", "OL Title" ); ShowBase = EditorGUILayout.Foldout(ShowBase, "Base Setings "); if (ShowBase && agent.WeaponComponent) { EditorGUILayout.FloatField("Health ", bb.Health, GUILayout.Width(250), GUILayout.ExpandWidth(false)); EditorGUILayout.EnumPopup("Weapon", agent.WeaponComponent.CurrentWeapon, GUILayout.Width(250), GUILayout.ExpandWidth(false)); EditorGUILayout.ObjectField("Melee Target ", bb.Desires.MeleeTarget, typeof(GameObject), true, GUILayout.Width(250), GUILayout.ExpandWidth(false)); } GUILayout.Space(10); GUILayout.EndVertical(); GUILayout.BeginVertical(); MoveInfo = EditorGUILayout.Foldout(MoveInfo, "Move info "); if (MoveInfo) { EditorGUILayout.EnumPopup("Motion", agent.BlackBoard.MotionType, GUILayout.Width(250), GUILayout.ExpandWidth(false)); EditorGUILayout.EnumPopup("Move", agent.BlackBoard.MoveType, GUILayout.Width(250), GUILayout.ExpandWidth(false)); EditorGUILayout.FloatField("Speed ", agent.BlackBoard.Speed, GUILayout.Width(250), GUILayout.ExpandWidth(false)); EditorGUILayout.Vector3Field("Rotation", agent.Forward, GUILayout.Width(250), GUILayout.ExpandWidth(false)); EditorGUILayout.Vector3Field("Fire Dir", agent.BlackBoard.FireDir, GUILayout.Width(250), GUILayout.ExpandWidth(false)); } GUILayout.Space(10); GUILayout.EndVertical(); GUILayout.BeginVertical(); ShowGoap = EditorGUILayout.Foldout(ShowGoap, "Goap Manager "); if (ShowGoap) { GUILayout.BeginHorizontal(); GUILayout.Label("Name", "OL Title", GUILayout.Width(100)); GUILayout.Label("Relevancy", "OL Title", GUILayout.Width(60)); GUILayout.Label("Enabled", "OL Title", GUILayout.Width(60)); GUILayout.EndHorizontal(); foreach (E_GOAPGoals key in System.Enum.GetValues(typeof(E_GOAPGoals))) { GOAPGoal goal = agent.GetGOAPGoal(key); if (goal == null) { continue; } GUILayout.BeginHorizontal(); if (goal.Active) { GUILayout.Label(goal.GoalType.ToString(), EditorStyles.whiteLabel, GUILayout.Width(100), GUILayout.ExpandWidth(false)); } else { GUILayout.Label(goal.GoalType.ToString(), GUILayout.Width(100), GUILayout.ExpandWidth(false)); } EditorGUILayout.LabelField(goal.GoalRelevancy.ToString(), "", GUILayout.Width(60), GUILayout.ExpandWidth(false)); EditorGUILayout.LabelField((goal.IsDisabled() == false).ToString(), "", GUILayout.Width(60), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); } } GUILayout.Space(10); GUILayout.EndVertical(); GUILayout.BeginVertical(); ShowWorldState = EditorGUILayout.Foldout(ShowWorldState, "World States "); if (ShowWorldState && agent.WorldState != null) { for (E_PropKey key = E_PropKey.Start; key < E_PropKey.Count; key++) { if (agent.WorldState == null) { continue; } WorldStateProp prop = agent.WorldState.GetWSProperty(key); if (prop == null) { continue; } switch (prop.PropType) { case E_PropType.Bool: EditorGUILayout.LabelField(prop.PropName, prop.GetBool().ToString(), GUILayout.Width(250), GUILayout.ExpandWidth(false)); break; case E_PropType.Int: EditorGUILayout.LabelField(prop.PropName, prop.GetBool().ToString(), GUILayout.Width(250), GUILayout.ExpandWidth(false)); break; case E_PropType.Float: EditorGUILayout.LabelField(prop.PropName, prop.GetFloat().ToString(), GUILayout.Width(250), GUILayout.ExpandWidth(false)); break; case E_PropType.Vector: EditorGUILayout.LabelField(prop.PropName, prop.GetVector().ToString(), GUILayout.Width(250), GUILayout.ExpandWidth(false)); break; case E_PropType.Agent: EditorGUILayout.LabelField(prop.PropName, prop.GetAgent().name, GUILayout.Width(250), GUILayout.ExpandWidth(false)); break; case E_PropType.CoverState: EditorGUILayout.LabelField(prop.PropName, prop.GetCoverState().ToString(), GUILayout.Width(250), GUILayout.ExpandWidth(false)); break; default: Debug.LogError("Unknow prop type " + prop.PropType); break; } } } GUILayout.Space(10); GUILayout.EndVertical(); GUILayout.BeginVertical(); ShowAnim = EditorGUILayout.Foldout(ShowAnim, "Animations"); if (ShowAnim && agent.AnimComponent != null) { EditorGUILayout.LabelField("Current State: ", agent.AnimComponent.CurrentAnimState != null? agent.AnimComponent.CurrentAnimState.ToString() : " none", GUILayout.Width(250), GUILayout.ExpandWidth(false)); GUILayout.BeginHorizontal(); GUILayout.Label("Name", "OL Title", GUILayout.Width(200)); GUILayout.Label("Layer", "OL Title", GUILayout.Width(40)); GUILayout.Label("Weight", "OL Title", GUILayout.Width(100)); GUILayout.Label("Time", "OL Title", GUILayout.Width(100)); GUILayout.EndHorizontal(); if (Application.isPlaying) { foreach (AnimationState state in agent.GetComponent <Animation>()) { if (agent.GetComponent <Animation>().IsPlaying(state.clip.name) == false) { continue; } GUILayout.BeginHorizontal(); GUILayout.Label(state.name, GUILayout.Width(200), GUILayout.ExpandWidth(false)); EditorGUILayout.LabelField(state.layer.ToString(), "", GUILayout.Width(40), GUILayout.ExpandWidth(false)); EditorGUILayout.LabelField(state.weight.ToString(), "", GUILayout.Width(100), GUILayout.ExpandWidth(false)); EditorGUILayout.LabelField(state.time.ToString(), "", GUILayout.Width(100), GUILayout.ExpandWidth(false)); GUILayout.EndHorizontal(); } } } GUILayout.Space(10); GUILayout.EndVertical(); /* * GUILayout.BeginVertical(); * EditorGUI.indentLevel++; * GUILayout.Label("User Settings", "OL Title"); * interaction.EntryTransform = EditorGUILayout.ObjectField("Entry position", interaction.EntryTransform, typeof(Transform), true, GUILayout.Width(250), GUILayout.ExpandWidth(false)) as Transform; * interaction.LeaveTransform = EditorGUILayout.ObjectField("Leave position", interaction.LeaveTransform, typeof(Transform), true, GUILayout.Width(250), GUILayout.ExpandWidth(false)) as Transform; * interaction.UserAnimationClip = EditorGUILayout.ObjectField("User animation", interaction.UserAnimationClip, typeof(AnimationClip), false, GUILayout.Width(250), GUILayout.ExpandWidth(false)) as AnimationClip; * EditorGUI.indentLevel--; * GUILayout.EndVertical(); * * GUILayout.BeginVertical(); * EditorGUI.indentLevel++; * GUILayout.Label("Cutscene Settings", "OL Title"); * interaction.CutsceneCamera = EditorGUILayout.ObjectField("Camera", interaction.CutsceneCamera, typeof(GameObject), true, GUILayout.Width(250), GUILayout.ExpandWidth(false)) as GameObject; * interaction.CameraAnim = EditorGUILayout.ObjectField("Animation", interaction.CameraAnim, typeof(AnimationClip), true, GUILayout.Width(250), GUILayout.ExpandWidth(false)) as AnimationClip; * interaction.FadeInTime= EditorGUILayout.FloatField("Fade In", interaction.FadeInTime, GUILayout.Width(250), GUILayout.ExpandWidth(false)); * interaction.FadeOutTime = EditorGUILayout.FloatField("Fade out", interaction.FadeOutTime, GUILayout.Width(250), GUILayout.ExpandWidth(false)); * EditorGUI.indentLevel--; * GUILayout.EndVertical();*/ }
public virtual void Build(GOAPActionType[] candidates, WorldState curWS, GOAPGoal goal) { _actions.Clear(); // 测试用,后续改成A* /*foreach (var actionType in candidates) * { * GOAPAction action = GOAPActionFactory.Get(actionType, _agent); * if (action == null) * { * Debug.LogWarning("null for actiontype: " + actionType); * continue; * } * if (actionType == GOAPActionType.GOTO_MELEE_RANGE) * { * _actions.Enqueue(action); * } * }*/ GOAPAction action = null; switch (goal.GoalType) { case GOAPGoalType.STEP_IN: action = GOAPActionFactory.Get(GOAPActionType.STEP_IN, _owner); _actions.Enqueue(action); break; case GOAPGoalType.STEP_OUT: action = GOAPActionFactory.Get(GOAPActionType.STEP_OUT, _owner); _actions.Enqueue(action); break; case GOAPGoalType.STEP_AROUND: action = GOAPActionFactory.Get(GOAPActionType.STEP_AROUND, _owner); _actions.Enqueue(action); break; case GOAPGoalType.ATTACK_TARGET: action = GOAPActionFactory.Get(GOAPActionType.GOTO_MELEE_RANGE, _owner); _actions.Enqueue(action); if (_owner.agentType == AgentType.PEASANT || _owner.agentType == AgentType.SWORD_MAN) { action = GOAPActionFactory.Get(GOAPActionType.ATTACK_MELEE_ONCE, _owner); _actions.Enqueue(action); } else if (_owner.agentType == AgentType.DOUBLE_SWORDS_MAN) { if (UnityEngine.Random.Range(0, 2) == 0) { action = GOAPActionFactory.Get(GOAPActionType.ATTACK_MELEE_TWO_SWORDS, _owner); } else { action = GOAPActionFactory.Get(GOAPActionType.ATTACK_WHIRL, _owner); } _actions.Enqueue(action); } break; case GOAPGoalType.REACT_TO_DAMAGE: if (curWS.GetWSProperty(WorldStatePropKey.EVENT).GetEvent() == EventTypes.HIT) { action = GOAPActionFactory.Get(GOAPActionType.INJURY, _owner); _actions.Enqueue(action); } else if (curWS.GetWSProperty(WorldStatePropKey.EVENT).GetEvent() == EventTypes.DEAD) { action = GOAPActionFactory.Get(GOAPActionType.DEATH, _owner); _actions.Enqueue(action); } else if (curWS.GetWSProperty(WorldStatePropKey.EVENT).GetEvent() == EventTypes.KNOCKDOWN) { action = GOAPActionFactory.Get(GOAPActionType.KNOCKDOWN, _owner); _actions.Enqueue(action); } break; case GOAPGoalType.BLOCK: action = GOAPActionFactory.Get(GOAPActionType.BLOCK, _owner); _actions.Enqueue(action); break; default: break; } if (_actions.Count > 0) { _actions.Peek().Activate(); } }