// This function is static such that it can be called without an editor being instanced. public static Condition CreateCondition() { // Create a new instance of Condition. Condition newCondition = CreateInstance <Condition> (); string blankDescription = "No conditions set."; // Try and set the new condition's description to the first condition in the AllConditions array. Condition globalCondition = AllConditionsEditor.TryGetConditionAt(0); newCondition.Description = globalCondition != null ? globalCondition.Description : blankDescription; // Set the hash based on this description. SetHash(newCondition); return(newCondition); }
private void InteractableGUI() { // Pull the information from the target into the serializedObject. serializedObject.Update(); // The width for the Popup, Toggle and remove Button. float width = EditorGUIUtility.currentViewWidth / 3f; EditorGUILayout.BeginHorizontal(); // Find the index for the target based on the AllConditions array. int conditionIndex = AllConditionsEditor.TryGetConditionIndex(condition); // If the target can't be found in the AllConditions array use the first condition. if (conditionIndex == -1) { conditionIndex = 0; } // Set the index based on the user selection of the condition by the user. conditionIndex = EditorGUILayout.Popup(conditionIndex, AllConditionsEditor.AllConditionDescriptions, GUILayout.Width(width)); // Find the equivalent condition in the AllConditions array. Condition globalCondition = AllConditionsEditor.TryGetConditionAt(conditionIndex); // Set the description based on the globalCondition's description. descriptionProperty.stringValue = globalCondition != null ? globalCondition.Description : blankDescription; // Set the hash based on the description. hashProperty.intValue = Animator.StringToHash(descriptionProperty.stringValue); // Display the toggle for the satisfied bool. EditorGUILayout.PropertyField(satisfiedProperty, GUIContent.none, GUILayout.Width(width + toggleOffset)); // Display a button with a '-' that when clicked removes the target from the ConditionCollection's conditions array. if (GUILayout.Button("-", GUILayout.Width(conditionButtonWidth))) { conditionsProperty.RemoveFromObjectArray(condition); } EditorGUILayout.EndHorizontal(); // Push all changes made on the serializedObject back to the target. serializedObject.ApplyModifiedProperties(); }
protected override void DrawReaction() { // If there's isn't a Condition yet, set it to the first Condition from the AllConditions array. if (_conditionProperty.objectReferenceValue == null) { _conditionProperty.objectReferenceValue = AllConditionsEditor.TryGetConditionAt(0); } // Get the index of the Condition in the AllConditions array. int index = AllConditionsEditor.TryGetConditionIndex((Condition)_conditionProperty.objectReferenceValue); // Use and set that index based on a popup of all the descriptions of the Conditions. index = EditorGUILayout.Popup(index, AllConditionsEditor.AllConditionDescriptions); // Set the Condition based on the new index from the AllConditions array. _conditionProperty.objectReferenceValue = AllConditionsEditor.TryGetConditionAt(index); // Use default toggle GUI for the satisfied field. EditorGUILayout.PropertyField(_satisfiedProperty); }
// This is displayed for each Condition when the AllConditions asset is selected. private void AllConditionsAssetGUI() { EditorGUILayout.BeginHorizontal(GUI.skin.box); EditorGUI.indentLevel++; // Display the Condition. if (!_isInRenamingeState) { // Display the description of the Condition. EditorGUILayout.LabelField(condition.Description); // Display is the Condition satisfied state. condition.IsSatisfied = EditorGUILayout.Toggle(condition.IsSatisfied); if (GUILayout.Button("RENAME", GUILayout.Width(conditionButtonWidth * 3))) { _isInRenamingeState = true; } } else { condition.Description = EditorGUILayout.TextField(condition.Description); if (GUILayout.Button("SAVE", GUILayout.Width(conditionButtonWidth * 3))) { condition.name = condition.Description; AssetDatabase.SaveAssets(); _isInRenamingeState = false; } } // Display a button showing a '-' that if clicked removes this Condition from the AllConditions asset. if (GUILayout.Button("-", GUILayout.Width(conditionButtonWidth))) { AllConditionsEditor.RemoveCondition(condition); } EditorGUI.indentLevel--; EditorGUILayout.EndHorizontal(); }