//change refenced condition to value public void execute() { //TODO maybe improve this so conditonList can be passed by constructor without being reset in Play mode. conditionList = GameObject.FindGameObjectWithTag("NarrativeController").GetComponent <ConditionList>(); Predicate <ConditionList.Condition> condFinder = (ConditionList.Condition c) => { return(c.conditionName == refrencedCondition.conditionName); }; trueCondition = conditionList.conditionList.Find(condFinder); //if its a bool, assign specified bool if (trueCondition.conditonType == ConditionList.ConditionType.Boolean) { trueCondition.boolean = boolValue; } if (trueCondition.conditonType == ConditionList.ConditionType.Integer) { if (assignmentType == AssignmentType.INCREMENT) { trueCondition.integer++; } if (assignmentType == AssignmentType.DECREMENT) { trueCondition.integer--; } if (assignmentType == AssignmentType.SET) { trueCondition.integer = this.integerValue; } } }
public Postcondition(ref ConditionList.Condition condition, ConditionList glovalConditionList) { refrencedCondition = condition; conditionList = glovalConditionList; assignmentType = AssignmentType.INCREMENT; }
//check if precondition is satisfied public bool checkCondition() { conditionList = GameObject.FindGameObjectWithTag("NarrativeController").GetComponent <ConditionList>(); Predicate <ConditionList.Condition> condFinder = (ConditionList.Condition c) => { return(c.conditionName == refrencedCondition.conditionName); }; ConditionList.Condition trueCondition = conditionList.conditionList.Find(condFinder); if (trueCondition.conditonType == ConditionList.ConditionType.Boolean) { if (trueCondition.boolean == boolValue) { return(true); } } if (trueCondition.conditonType == ConditionList.ConditionType.Integer) { if (comparisonType == ComparisonType.Equal) { if (trueCondition.integer == integerValue) { return(true); } } if (comparisonType == ComparisonType.LessThan) { if (trueCondition.integer < integerValue) { return(true); } } if (comparisonType == ComparisonType.GreaterThan) { if (trueCondition.integer > integerValue) { return(true); } } } return(false); }
public Precondition(ref ConditionList.Condition condition) { refrencedCondition = condition; }
public override void OnInspectorGUI() { //Update our list GetTarget.Update(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.PropertyField(actionName); EditorGUILayout.Space(); EditorGUILayout.Space(); //preconditions lists EditorGUILayout.LabelField("Preconditions", EditorStyles.boldLabel); EditorGUILayout.LabelField("Define the Preconditions of this action"); EditorGUILayout.BeginHorizontal(); precondChoice = EditorGUILayout.Popup(precondChoice, t.choices); if (GUILayout.Button("Add New")) { ConditionList.Condition x = t.globalConditionList.conditionList[precondChoice]; Precondition newCond = new Precondition(ref x); //newCond.refrencedCondition = t.globalConditionList.conditionList[precondChoice]; if (t.preconditions == null) { Debug.Log("No t"); } t.preconditions.Add(newCond); } EditorGUILayout.EndHorizontal(); //Display our list to the inspector window for (int i = 0; i < PrecondList.arraySize; i++) { EditorGUILayout.Space(); EditorGUILayout.Space(); SerializedProperty MyListRef = PrecondList.GetArrayElementAtIndex(i); SerializedProperty referencedCond = MyListRef.FindPropertyRelative("refrencedCondition"); SerializedProperty condName = referencedCond.FindPropertyRelative("conditionName"); SerializedProperty condValue = MyListRef.FindPropertyRelative("value"); // Display the property fields EditorGUILayout.BeginHorizontal("box"); EditorGUILayout.LabelField(condName.stringValue); t.preconditions[i].boolValue = EditorGUILayout.Toggle(condValue.boolValue); if (GUILayout.Button("Remove")) { PrecondList.DeleteArrayElementAtIndex(i); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.Space(); } EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); //post conditions list EditorGUILayout.LabelField("Postconditions", EditorStyles.boldLabel); EditorGUILayout.LabelField("Define the Postconditions of this action"); EditorGUILayout.BeginHorizontal(); postcondChoice = EditorGUILayout.Popup(postcondChoice, t.choices); if (GUILayout.Button("Add New")) { ConditionList.Condition x = t.globalConditionList.conditionList[postcondChoice]; Postcondition newCond = new Postcondition(ref x, t.globalConditionList); //newCond.refrencedCondition = t.globalConditionList.conditionList[postcondChoice]; t.postConditions.Add(newCond); } EditorGUILayout.EndHorizontal(); //Display our list to the inspector window for (int i = 0; i < PostcondList.arraySize; i++) { EditorGUILayout.Space(); EditorGUILayout.Space(); SerializedProperty MyListRef = PostcondList.GetArrayElementAtIndex(i); SerializedProperty referencedCond = MyListRef.FindPropertyRelative("refrencedCondition"); SerializedProperty condName = referencedCond.FindPropertyRelative("conditionName"); SerializedProperty condValue = MyListRef.FindPropertyRelative("value"); // Display the property fields EditorGUILayout.BeginHorizontal("box"); EditorGUILayout.LabelField(condName.stringValue); t.postConditions[i].boolValue = EditorGUILayout.Toggle(condValue.boolValue); if (GUILayout.Button("Remove")) { PostcondList.DeleteArrayElementAtIndex(i); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.Space(); } EditorGUILayout.PropertyField(Dialogue); //Apply the changes to our list GetTarget.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { //Update our list GetTarget.Update(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.PropertyField(actionName); EditorGUILayout.Space(); EditorGUILayout.Space(); //preconditions lists EditorGUILayout.LabelField("Preconditions", EditorStyles.boldLabel); EditorGUILayout.LabelField("Define the Preconditions of this action"); EditorGUILayout.BeginHorizontal(); precondChoice = EditorGUILayout.Popup(precondChoice, t.choices); if (GUILayout.Button("Add New")) { ConditionList.Condition x = t.globalConditionList.conditionList[precondChoice]; Precondition newCond = new Precondition(ref x); //newCond.refrencedCondition = t.globalConditionList.conditionList[precondChoice]; if (t.preconditions == null) { Debug.Log("No t"); } t.preconditions.Add(newCond); } EditorGUILayout.EndHorizontal(); //Display our list to the inspector window for (int i = 0; i < PrecondList.arraySize; i++) { EditorGUILayout.Space(); EditorGUILayout.Space(); SerializedProperty MyListRef = PrecondList.GetArrayElementAtIndex(i); SerializedProperty referencedCond = MyListRef.FindPropertyRelative("refrencedCondition"); SerializedProperty condName = referencedCond.FindPropertyRelative("conditionName"); SerializedProperty condBoolValue = MyListRef.FindPropertyRelative("boolValue"); SerializedProperty condintValue = MyListRef.FindPropertyRelative("integerValue"); SerializedProperty compType = MyListRef.FindPropertyRelative("comparisonType"); // Display the property fields EditorGUILayout.BeginHorizontal("box"); EditorGUILayout.LabelField(condName.stringValue); //change what values can be changed depending on type if (t.preconditions [i].refrencedCondition.conditonType == global::ConditionList.ConditionType.Boolean) { //if its a bool t.preconditions [i].boolValue = EditorGUILayout.Toggle(condBoolValue.boolValue); } else { //its an int GUILayout.Label("Integer Value"); t.preconditions [i].integerValue = EditorGUILayout.IntField(condintValue.intValue); EditorGUILayout.PropertyField(compType); } if (GUILayout.Button("Remove")) { PrecondList.DeleteArrayElementAtIndex(i); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.Space(); } EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); //POST CONDITIONS EditorGUILayout.LabelField("Postconditions", EditorStyles.boldLabel); EditorGUILayout.LabelField("Define the Postconditions of this action"); EditorGUILayout.BeginHorizontal(); postcondChoice = EditorGUILayout.Popup(postcondChoice, t.choices); if (GUILayout.Button("Add New")) { ConditionList.Condition x = t.globalConditionList.conditionList[postcondChoice]; Postcondition newCond = new Postcondition(ref x, t.globalConditionList); //newCond.refrencedCondition = t.globalConditionList.conditionList[postcondChoice]; t.postConditions.Add(newCond); } EditorGUILayout.EndHorizontal(); //Display our list to the inspector window for (int i = 0; i < PostcondList.arraySize; i++) { EditorGUILayout.Space(); EditorGUILayout.Space(); SerializedProperty MyListRef = PostcondList.GetArrayElementAtIndex(i); SerializedProperty referencedCond = MyListRef.FindPropertyRelative("refrencedCondition"); SerializedProperty condName = referencedCond.FindPropertyRelative("conditionName"); SerializedProperty boolCondValue = MyListRef.FindPropertyRelative("boolValue"); SerializedProperty intCondValue = MyListRef.FindPropertyRelative("integerValue"); SerializedProperty asngType = MyListRef.FindPropertyRelative("assignmentType"); // Display the property fields EditorGUILayout.BeginHorizontal("box"); EditorGUILayout.LabelField(condName.stringValue); //change what values can be changed depending on type if (t.postConditions [i].refrencedCondition.conditonType == global::ConditionList.ConditionType.Boolean) { //if its a bool t.postConditions[i].boolValue = EditorGUILayout.Toggle(boolCondValue.boolValue); } else { //its an int EditorGUILayout.BeginVertical(); EditorGUILayout.PropertyField(asngType); if (t.postConditions [i].assignmentType == AssignmentType.SET) { t.postConditions[i].integerValue = EditorGUILayout.IntField(intCondValue.intValue); } EditorGUILayout.EndVertical(); } if (GUILayout.Button("Remove")) { PostcondList.DeleteArrayElementAtIndex(i); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.Space(); } //Apply the changes to our list GetTarget.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { GetTarget.Update(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Transition States", EditorStyles.boldLabel); EditorGUILayout.LabelField("Define the Transition states of this node"); ListSize = transitionList.arraySize; sceneIndex = EditorGUILayout.Popup(sceneIndex, t.scenes); //Or add a new item to the List<> with a button if (GUILayout.Button("Add New")) { TransitionState x = new TransitionState(); x.sceneName = t.scenes [sceneIndex]; t.transitionStates.Add(x); } EditorGUILayout.Space(); EditorGUILayout.Space(); //Display our list to the inspector window for (int i = 0; i < transitionList.arraySize; i++) { SerializedProperty transitionState = transitionList.GetArrayElementAtIndex(i); SerializedProperty transitionConditionList = transitionState.FindPropertyRelative("transitionConditions"); SerializedProperty sceneName = transitionState.FindPropertyRelative("sceneName"); // Display the Transition states and their fields EditorGUILayout.BeginVertical("box"); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(sceneName.stringValue); if (GUILayout.Button("Remove Transition")) { transitionConditionList.DeleteCommand(); transitionList.DeleteArrayElementAtIndex(i); //Apply the changes to our list GetTarget.ApplyModifiedProperties(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginVertical(); //field for setting conditions EditorGUILayout.LabelField("Transition Conditions", EditorStyles.boldLabel); //field for adding new conditions EditorGUILayout.BeginHorizontal(); conditionIndex = EditorGUILayout.Popup(conditionIndex, t.conditionChoices); //Or add a new item to the List<> with a button if (GUILayout.Button("Add New Condition")) { ConditionList.Condition refedCond = t.conditionListComponent.conditionList[conditionIndex]; Precondition preCond = new Precondition(ref refedCond); t.transitionStates[i].transitionConditions.Add(preCond); } EditorGUILayout.EndHorizontal(); //if (transitionConditionList.arraySize > 0) { ///SerializedProperty condListcopy = transitionConditionList.Copy(); //list conditions EditorGUILayout.BeginVertical(); for (int z = 0; z < transitionConditionList.arraySize; z++) { //Debug.Log("array size: " + transitionConditionList.arraySize); EditorGUILayout.Space(); EditorGUILayout.Space(); SerializedProperty MyListRef = transitionConditionList.GetArrayElementAtIndex(z); SerializedProperty referencedCond = MyListRef.FindPropertyRelative("refrencedCondition"); SerializedProperty condName = referencedCond.FindPropertyRelative("conditionName"); SerializedProperty condValue = MyListRef.FindPropertyRelative("boolValue"); // Display the property fields EditorGUILayout.BeginHorizontal("box"); EditorGUILayout.LabelField(condName.stringValue); //t.postConditions[i].value = EditorGUILayout.Toggle(condValue.boolValue); t.transitionStates[i].transitionConditions[z].boolValue = EditorGUILayout.Toggle(condValue.boolValue); if (GUILayout.Button("Remove Condition")) { //PostcondList.DeleteArrayElementAtIndex(i); transitionConditionList.DeleteArrayElementAtIndex(z); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.Space(); } EditorGUILayout.EndVertical(); } EditorGUILayout.Space(); EditorGUILayout.Space(); //Apply the changes to our list GetTarget.ApplyModifiedProperties(); }