Esempio n. 1
0
    private void InteractableGUI()
    {
        serializedObject.Update();

        float width = EditorGUIUtility.currentViewWidth / 3f;

        EditorGUILayout.BeginHorizontal();

        int conditionIndex = AllConditionsEditor.TryGetConditionIndex(condition);

        if (conditionIndex == -1)
        {
            conditionIndex = 0;
        }

        conditionIndex = EditorGUILayout.Popup(conditionIndex, AllConditionsEditor.AllConditionDescriptions,
                                               GUILayout.Width(width));
        Condition globalCondition = AllConditionsEditor.TryGetConditionAt(conditionIndex);

        descriptionProperty.stringValue = globalCondition != null ? globalCondition.description : blankDescription;

        hashProperty.intValue = Animator.StringToHash(descriptionProperty.stringValue);

        EditorGUILayout.PropertyField(satisfiedProperty, GUIContent.none, GUILayout.Width(width + toggleOffset));

        if (GUILayout.Button("-", GUILayout.Width(conditionButtonWidth)))
        {
            conditionsProperty.RemoveFromObjectArray(condition);
        }

        EditorGUILayout.EndHorizontal();

        serializedObject.ApplyModifiedProperties();
    }
Esempio n. 2
0
    public static Condition CreateCondition()
    {
        Condition newCondition     = CreateInstance <Condition>();
        string    blankDescription = "No conditions set.";
        Condition globalCondition  = AllConditionsEditor.TryGetConditionAt(0);

        newCondition.description = globalCondition != null ? globalCondition.description : blankDescription;
        SetHash(newCondition);
        return(newCondition);
    }
    protected override void DrawReaction()
    {
        if (conditionProperty.objectReferenceValue == null)
        {
            conditionProperty.objectReferenceValue = AllConditionsEditor.TryGetConditionAt(0);
        }

        int index = AllConditionsEditor.TryGetConditionIndex((Condition)conditionProperty.objectReferenceValue);

        index = EditorGUILayout.Popup(index, AllConditionsEditor.AllConditionDescriptions);
        conditionProperty.objectReferenceValue = AllConditionsEditor.TryGetConditionAt(index);

        EditorGUILayout.PropertyField(satisfiedProperty);
    }
    // Function to Create a NewCondition (Static: it can be Called without an Editor being Instanced)
    public static Condition CreateCondition()
    {
        // Create a new Instance of Condition
        Condition newCondition = CreateInstance <Condition> ();
        // Default Description of Condition
        string blankDescription = "No conditions set.";
        // Set newConditions Description to First in AllConditions Array
        Condition globalCondition = AllConditionsEditor.TryGetConditionAt(0);

        // Set the Description of newCondition (based on if Description exists in Global)
        newCondition.description = globalCondition != null ? globalCondition.description : blackDescription;
        // Set the Hash based on newConditions Description
        SetHash(newCondition);
        // Return the newCondition
        return(newCondition);
    }
    // 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();
    }
    // Display InteractableAsset
    private void InteractableGUI()
    {
        // Update the Serialize Object Properties
        serializedObject.Update();

        //Width of PopUp, Toggle and Remove Button.
        float width = EditorGUIUtility.currentViewWidth / 3f;

        // Begin HorizontalBox for Interactable
        EditorGUILayout.BeginHorizontal();

        // Find Index for Target based on AllConditions Array
        int conditionIndex = AllConditionsEditor.TryGetConditionIndex(condition);

        // if ConditionIndex was not Found
        if (conditionIndex == -1)
        {
            // Set Index to First in Array
            conditionIndex = 0;
        }

        // Set Index based on User Selection of the Condition (by the user)
        conditionIndex = EditorGUILayout.Popup(conditionIndex, AllConditionsEditor.AllConditionDescriptions, GUILayout.Width(width));
        // Find Condition in AllCondition Array
        Condition globalCondition = AllConditionsEditor.TryGetConditionAt(conditionIndex);

        // Set Description based on GlobalConditions Description
        descriptionProperty.stringValue = globalCondition != null ? globalCondition.description : blackDescription;
        // Set Hash based on Description
        hashProperty.intValue = Animator.StringToHash(descriptionProperty.stringValue);
        // Display Toggle Satisfied Bool
        EditorGUILayout.PropertyField(satisfiedProperty, GUIContent.none, GUILayout.Width(width + toggleOffset));

        // Create Button to Remove Condition from ConditionCollections Array
        if (GUILayout.Button("-", GUILayout.Width(conditionButtonWidth)))
        {
            // Remove Condition from ConditionCollection
            conditionsProperty.RemoveFromObjectArray(condition);
        }

        // End Horizontal IntactableBox
        EditorGUILayout.EndHorizontal();
        // Apply Update Properties to SerializedObject
        serializedObject.ApplyModifiedProperties();
    }
    protected override void DrawReaction()
    {
        // If no Condition Found
        if (conditionProperty.objectReferenceValue == null)
        {
            // Set to First Condition of AllConditions Array
            conditionProperty.objectReferenceValue = AllConditionsEditor.TryGetConditionAt(0);
        }

        // Get Index of Condition in AllCondition Array
        int index = AllConditionsEditor.TryGetConditionIndex((Condition)conditionProperty.objectReferenceValue);

        // Use and Set Index based on PopUp of AllConditions Descriptions
        index = EditorGUILayout.Popup(index, AllConditionsEditor.AllConditionDescriptions);
        // Set Condition based on new Index from AllConditions Array
        conditionProperty.objectReferenceValue = AllConditionsEditor.TryGetConditionAt(index);
        // Use default Toggle GUI for Satisfied Field
        EditorGUILayout.PropertyField(satisfiedProperty);
    }
    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);
    }