private void DrawElement(Rect rect, int index, bool isActive, bool isFocused)
        {
            rect.height = EditorGUIUtility.singleLineHeight;
            SerializedProperty element = inputs.GetArrayElementAtIndex(index);
            SerializedProperty type    = element.FindPropertyRelative("type");

            EditorGUI.PropertyField(rect, element.FindPropertyRelative("buttonName"), new GUIContent("Name"));
            rect.y += FieldHeight;
            EditorGUI.PropertyField(rect, type, new GUIContent("Type"));
            rect.y += FieldHeight;
            if (type.enumValueIndex != 2)
            {
                EditorGUI.PropertyField(rect, element.FindPropertyRelative("inputName"), new GUIContent("Input Name"));
            }
            else
            {
                GoldPlayerUIHelper.DrawCustomVector2Field(rect,
                                                          element.FindPropertyRelative("inputName"),
                                                          element.FindPropertyRelative("inputNameSecondary"),
                                                          10, new GUIContent("Vector2 Input Name"), false,
                                                          new GUIContent("X", "The input action that will serve the X axis."),
                                                          new GUIContent("Y", "The input action that will serve the Y axis."));
            }

            rect.y += FieldHeight;

            if (type.enumValueIndex == 0 && useKeyCodes.boolValue)
            {
                EditorGUI.PropertyField(rect, element.FindPropertyRelative("key"));
            }
        }
示例#2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            // Set 'doGUI' to true as we want to bae it of the GUI.
            doGUI = true;
            // Begin the property GUI.
            EditorGUI.BeginProperty(position, label, property);
            // Set the full rect to the provided position.
            fullRect = position;
            // Set the full rect height to the line height.
            fullRect.height = lineHeight;
            // Set the field rect to the provided position.
            fieldRect = position;
            // Set the field rect height to the line height.
            fieldRect.height = lineHeight;
            // The property foldout.
            EditorGUI.PropertyField(fieldRect, property, label, false);
            // Only draw the rest if the property is expanded.
            if (property.isExpanded)
            {
                //Indent the GUI one step.
                EditorGUI.indentLevel++;
                // Add to the rect.
                AddToRect();
                // The 'Enabled' field.
                EditorGUI.PropertyField(fieldRect, property.FindPropertyRelative("enabled"));

                GoldPlayerUIHelper.DrawElementsConditional(property.FindPropertyRelative("enabled"), () =>
                {
                    // Add to the rect.
                    AddToRect();
                    // The 'Random Pitch' field.
                    EditorGUI.PropertyField(fieldRect, property.FindPropertyRelative("randomPitch"));
                    // Add to the rect.
                    AddToRect();
                    // If random pitch is enabled, draw min max fields.
                    // Else just draw one field.
                    if (property.FindPropertyRelative("randomPitch").boolValue)
                    {
                        GoldPlayerUIHelper.DrawCustomVector2Field(fieldRect,
                                                                  property.FindPropertyRelative("minPitch"),
                                                                  property.FindPropertyRelative("maxPitch"),
                                                                  30, new GUIContent("Pitch"), true, new GUIContent("Min"), new GUIContent("Max"));
                    }
                    else
                    {
                        // The 'Pitch' field.
                        EditorGUI.PropertyField(fieldRect, property.FindPropertyRelative("pitch"));
                    }
                    // Add to the rect.
                    AddToRect();
                    // The 'Change Volume' field.
                    EditorGUI.PropertyField(fieldRect, property.FindPropertyRelative("changeVolume"));
                    // If change volume is true, draw the volume field.
                    GoldPlayerUIHelper.DrawElementsConditional(property.FindPropertyRelative("changeVolume"), () =>
                    {
                        // Add to the rect.
                        AddToRect();
                        // The volume slider field.
                        EditorGUI.PropertyField(fieldRect, property.FindPropertyRelative("volume"));
                    });
                    // Add to the rect.
                    AddToRect();
                    // The audio clips array.
                    EditorGUI.PropertyField(fieldRect, property.FindPropertyRelative("audioClips"), true);
                    // If the audio clips array is expanded, add to the rect to make sure everything is shown.
                    if (property.FindPropertyRelative("audioClips").isExpanded)
                    {
                        // Add a rect for the size field.
                        AddToRect();
                        // For every clip, add a size for every field.
                        for (int i = 0; i < property.FindPropertyRelative("audioClips").arraySize; i++)
                        {
                            AddToRect();
                        }
                    }
                });

                // Remove the indent.
                EditorGUI.indentLevel--;
            }
            // End the property GUI.
            EditorGUI.EndProperty();
        }