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); }