Ejemplo n.º 1
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();
    }
Ejemplo n.º 2
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();
    }