예제 #1
0
        // 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);
        }
예제 #2
0
        // This is displayed for each Condition when the AllConditions asset is selected.
        private void AllConditionsAssetGUI()
        {
            EditorGUILayout.BeginHorizontal(GUI.skin.box);
            EditorGUI.indentLevel++;

            // Display the description of the Condition.
            EditorGUILayout.LabelField(condition.Description);

            // 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();
        }
예제 #3
0
        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();
        }