/// <summary> /// Get's all actions that fit as a child to the input action /// </summary> /// <param name="parent"></param> /// <returns></returns> List <GoapAction> GetMatchingActionChilds(GoapAction parent) { List <GoapAction> matches = new List <GoapAction>(); // loop through all preconditions of the parent foreach (string condition in parent.preconditions.Keys) { // loop through all possible actions foreach (GoapAction action in possibleActions) { // prevent it from endless looping if (parent.GetType() == action.GetType()) { continue; } // loop through all effects of the possible actions foreach (string effect in action.effects.Keys) { // the keys and values are the same if (condition == effect && parent.preconditions[condition] == action.effects[effect]) { GoapAction tAction = action.Clone(); tAction.SetChilds(GetMatchingActionChilds(tAction)); matches.Add(tAction); } } } } return(matches); }
/// <summary> /// Draws the given action /// </summary> /// <param name="action"></param> private void DrawAvailableAction(GoapAction action) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(action.GetType().Name, EditorStyles.boldLabel); if (GUILayout.Button("Add")) { agent.AddAction(action.Clone().GenerateNewGUID()); } EditorGUILayout.EndHorizontal(); }
/// <summary> /// Draws the given action /// </summary> /// <param name="action"></param> private void DrawAction(GoapAction action, bool drawChildren = true) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(action.GetType().Name, EditorStyles.boldLabel); //if (GUILayout.Button("delete")) //{ // agent.RemoveAction(action); //} EditorGUILayout.EndHorizontal(); EditorGUILayout.Toggle("Preconditions Valid", action.preconditionsValid); EditorGUILayout.Toggle("Procedural Valid", action.proceduralConditionsValid); if (drawChildren && action.childs.Count > 0) { //EditorGUILayout.BeginVertical("Box"); foreach (GoapAction child in action.childs) { DrawAction(child); } //EditorGUILayout.EndVertical(); } }