Пример #1
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();
    }