private Vector2Int OnGUIFraction(Rect position, SerializedProperty property)
    {
        SerializedProperty numerator   = property.FindPropertyRelative("n");
        SerializedProperty denominator = property.FindPropertyRelative("d");
        Vector2Int         inputs      = new Vector2Int();

        GUIStyle slashStyle = new GUIStyle(EditorStyles.boldLabel);

        slashStyle.alignment = TextAnchor.MiddleCenter;
        slashStyle.fontStyle = FontStyle.Bold;

        Layout.Builder builder = new Layout.Builder();
        builder.PushChild(new LayoutChild(LayoutSize.RatioOfRemainder(0.5f)));
        builder.PushChild(new LayoutChild(LayoutSize.Exact(CENTER_BUFFER)));
        builder.PushChild(new LayoutChild(LayoutSize.RatioOfRemainder(0.5f)));
        Layout layout = builder.Compile(position);

        // Reset to no indent
        int oldIndent = EditorGUI.indentLevel;

        EditorGUI.indentLevel = 0;

        // Put the numerator, slash, denominator
        inputs.x = EditorGUI.DelayedIntField(layout.Next(), numerator.intValue);
        EditorGUI.LabelField(layout.Next(), new GUIContent("/"), slashStyle);
        inputs.y = EditorGUI.DelayedIntField(layout.Next(), denominator.intValue);

        // Restore old indent
        EditorGUI.indentLevel = oldIndent;

        return(inputs);
    }
Example #2
0
    private void OnGUIMatrix(Layout verticalLayout, SerializedProperty property)
    {
        SerializedProperty data = property.FindPropertyRelative("data");
        int rows = property.FindPropertyRelative("_rows").intValue;

        // The style for a label of the row, column
        GUIStyle labelStyle = new GUIStyle(EditorStyles.boldLabel)
        {
            alignment = TextAnchor.MiddleCenter
        };

        for (int i = -1; i < rows; i++)
        {
            // Build the horizontal layout that will be in the current part of the vertical layout
            Layout.Builder builder = new Layout.Builder();
            builder.PushChild(new LayoutChild(LayoutSize.Exact(ITEM_LABEL_WIDTH)));
            for (int j = 0; j < cols; j++)
            {
                builder.PushChild(new LayoutChild(LayoutSize.RatioOfRemainder(1f / cols), LayoutMargin.Right(HORIZONTAL_ITEM_SPACE)));
            }
            Layout horizontalLayout = builder.Compile(EditorGUI.IndentedRect(verticalLayout.Next()));

            // No indent because it is accounted for when the builder built the rect in the indented rect
            EditorGUIExt.PushIndent(0);

            for (int j = -1; j < cols; j++)
            {
                // Code inside is for the row with the labels
                if (i == -1)
                {
                    // If we're at the top corner, put "[X, Y]"
                    if (j == -1)
                    {
                        EditorGUI.LabelField(horizontalLayout.Next(), new GUIContent("[X, Y]"), labelStyle);
                    }
                    // If we're in the top row, put down the column numbers
                    else
                    {
                        EditorGUI.LabelField(horizontalLayout.Next(), new GUIContent(j.ToString()), labelStyle);
                    }
                }
                // Code inside is for the column with the labels
                else if (j == -1)
                {
                    EditorGUI.LabelField(horizontalLayout.Next(), new GUIContent(i.ToString()), labelStyle);
                }
                // Code in here displays the property
                else
                {
                    EditorGUI.PropertyField(horizontalLayout.Next(), data.GetArrayElementAtIndex(MyMath.Index2Dto1D(i, j, cols)), GUIContent.none);
                }
            }
        }

        EditorGUIExt.PopIndent();
    }
Example #3
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        // Store min-max sub-properties for ease of use
        SerializedProperty min = property.FindPropertyRelative("_min");
        SerializedProperty max = property.FindPropertyRelative("_max");

        // Put in the prefix label
        position = EditorGUI.PrefixLabel(position, label);

        // Store the old indent
        int oldIndent = EditorGUI.indentLevel;

        EditorGUI.indentLevel = 0;

        // Build a single-line layout where the float editors stretch and the labels stay at the same width
        Layout.Builder builder = new Layout.Builder();
        builder.PushChild(LayoutChild.Width(LayoutSize.Exact(35f)));
        builder.PushChild(LayoutChild.Width(LayoutSize.RatioOfRemainder(0.5f), LayoutMargin.Right(5f)));
        builder.PushChild(LayoutChild.Width(LayoutSize.Exact(35f)));
        builder.PushChild(LayoutChild.Width(LayoutSize.RatioOfRemainder(0.5f)));
        Layout layout = builder.Compile(position);

        // Create the min label
        EditorGUI.LabelField(layout.Next(), new GUIContent("Min:"));

        // Create the min editor
        EditorGUI.BeginChangeCheck();
        min.floatValue = EditorGUI.DelayedFloatField(layout.Next(), min.floatValue);

        // If the max was modified, ensure that the max is not smaller than the new min
        if (EditorGUI.EndChangeCheck())
        {
            max.floatValue = Mathf.Max(min.floatValue, max.floatValue);
        }

        // Create the max label
        EditorGUI.LabelField(layout.Next(), new GUIContent("Max:"));

        // Create the max editor
        EditorGUI.BeginChangeCheck();
        max.floatValue = EditorGUI.DelayedFloatField(layout.Next(), max.floatValue);

        // If the max was modified, ensure that the min is not bigger than the new max
        if (EditorGUI.EndChangeCheck())
        {
            min.floatValue = Mathf.Min(min.floatValue, max.floatValue);
        }

        // Restore indent level
        EditorGUI.indentLevel = oldIndent;
    }
Example #4
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        int rows = property.FindPropertyRelative("_rows").intValue;

        SetCols(property);

        Layout.Builder builder = new Layout.Builder();
        builder.Orientation(LayoutOrientation.Vertical);
        builder.PushChild(new LayoutChild(LayoutMargin.Bottom()));
        builder.PushChild(new LayoutChild(LayoutMargin.Bottom()));
        for (int i = -1; i < rows; i++)
        {
            builder.PushChild(new LayoutChild(LayoutMargin.Bottom()));
        }
        Layout layout = builder.Compile(position);

        property.isExpanded = EditorGUI.Foldout(layout.Next(), property.isExpanded, label);

        if (property.isExpanded)
        {
            EditorGUI.indentLevel++;

            // Check for change, and add GUI for adjusting rows and cols
            EditorGUI.BeginChangeCheck();
            OnGUIRowsAndCols(layout, property);

            // If rows or columns change, adjust the property's data array
            if (EditorGUI.EndChangeCheck())
            {
                AdjustPropertyArray(property);
            }

            // If the matrix has some rows and columns, render it
            if (rows > 0 && cols > 0)
            {
                OnGUIMatrix(layout, property);
            }

            EditorGUI.indentLevel--;
        }

        EditorGUIExt.EndLayout();
    }
Example #5
0
    private void OnGUIRowsAndCols(Layout verticalLayout, SerializedProperty property)
    {
        SerializedProperty rows = property.FindPropertyRelative("_rows");

        Layout.Builder builder = new Layout.Builder();
        builder.PushChild(new LayoutChild(LayoutSize.Exact(ROWS_LABEL_WIDTH)));
        builder.PushChild(new LayoutChild(LayoutSize.RatioOfRemainder(0.5f), LayoutMargin.Right(DIMENSION_CENTER_BUFFER)));
        builder.PushChild(new LayoutChild(LayoutSize.Exact(COLS_LABEL_WIDTH)));
        builder.PushChild(new LayoutChild(LayoutSize.RatioOfRemainder(0.5f)));
        Layout layout = builder.Compile(EditorGUI.IndentedRect(verticalLayout.Next()));

        EditorGUIExt.PushIndent(0);

        // Add label and int for row
        EditorGUI.LabelField(layout.Next(), new GUIContent("Rows:"));
        rows.intValue = EditorGUI.DelayedIntField(layout.Next(), rows.intValue);

        // Add label and int for columns
        EditorGUI.LabelField(layout.Next(), new GUIContent("Cols:"));
        cols = EditorGUI.DelayedIntField(layout.Next(), cols);

        EditorGUIExt.PopIndent();
    }
Example #6
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        position = EditorGUI.PrefixLabel(position, label);

        Layout.Builder builder = new Layout.Builder();
        // The layout child for the enum dropdown
        builder.PushChild(LayoutChild.Width(LayoutSize.Exact(70f), LayoutMargin.Right(10f)))
        // The layout child for the float or float range
        .PushChild(LayoutChild.Width(LayoutSize.RatioOfRemainder(1f)));

        // Compile the layout
        Layout layout = builder.Compile(EditorGUI.IndentedRect(position));

        // Set the indent down to zero
        int oldIndent = EditorGUI.indentLevel;

        EditorGUI.indentLevel = 0;

        SerializedProperty option = property.FindPropertyRelative("option");

        EditorGUI.PropertyField(layout.Next(), option, GUIContent.none);

        // If the enum is the first value, only let the value be edited
        if (option.enumValueIndex == 0)
        {
            EditorGUI.PropertyField(layout.Next(), property.FindPropertyRelative("value"), GUIContent.none);
        }
        // If the enum is the second value, only let the value range be edited
        else
        {
            EditorGUI.PropertyField(layout.Next(), property.FindPropertyRelative("valueRange"), GUIContent.none);
        }

        // Restore original indent
        EditorGUI.indentLevel = oldIndent;
    }