Ejemplo n.º 1
0
        void OnEnable()
        {
            table                       = (Table)target;
            columns                     = serializedObject.FindProperty("columns");
            rowsColorMode               = serializedObject.FindProperty("rowsColorMode");
            bgColor                     = serializedObject.FindProperty("bgColor");
            altBgColor                  = serializedObject.FindProperty("altBgColor");
            lineColor                   = serializedObject.FindProperty("lineColor");
            hasTitles                   = serializedObject.FindProperty("hasTitles");
            titleBGColor                = serializedObject.FindProperty("titleBGColor");
            titleFontColor              = serializedObject.FindProperty("titleFontColor");
            titleFontSize               = serializedObject.FindProperty("titleFontSize");
            titleFont                   = serializedObject.FindProperty("titleFont");
            titleFontStyle              = serializedObject.FindProperty("titleFontStyle");
            rowHeight                   = serializedObject.FindProperty("rowHeight");
            spacing                     = serializedObject.FindProperty("spacing");
            targetCollection            = serializedObject.FindProperty("targetCollection");
            rowDeleteButtons            = serializedObject.FindProperty("rowDeleteButtons");
            deleteColumnWidth           = serializedObject.FindProperty("deleteColumnWidth");
            deleteCellStyle             = serializedObject.FindProperty("deleteCellStyle");
            rowAddButton                = serializedObject.FindProperty("rowAddButton");
            addCellStyle                = serializedObject.FindProperty("addCellStyle");
            selectableRows              = serializedObject.FindProperty("selectableRows");
            selectedBgColor             = serializedObject.FindProperty("selectedBgColor");
            updateCellStyleAtRuntime    = serializedObject.FindProperty("updateCellStyleAtRuntime");
            updateCellContentAtRuntime  = serializedObject.FindProperty("updateCellContentAtRuntime");
            limitRowsInEditMode         = serializedObject.FindProperty("limitRowsInEditMode");
            nbRowsInEditMode            = serializedObject.FindProperty("nbRowsInEditMode");
            preinstantiateRowsOverLimit = serializedObject.FindProperty("preinstantiateRowsOverLimit");
            horizontal                  = serializedObject.FindProperty("horizontal");

            reorderableList = new ReorderableList(serializedObject, columns);
            reorderableList.drawHeaderCallback = rect =>
            {
                bool changed = GUI.changed;
                columns.isExpanded = reorderableList.draggable = EditorGUI.Foldout(new Rect(rect.x + 10f, rect.y, rect.width, rect.height), columns.isExpanded, string.Format("{0}:", GetOrientedWords(horizontal.boolValue).Columns));
                GUI.changed        = changed;
            };

            reorderableList.drawElementCallback =
                (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                if (!columns.isExpanded)
                {
                    GUI.enabled = false;
                    return;
                }
                SerializedProperty element = reorderableList.serializedProperty.GetArrayElementAtIndex(index);
                EditorGUI.PropertyField(new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight), element, GUIContent.none);
            };
            reorderableList.elementHeightCallback = (index) => (!columns.isExpanded) ? 0 : EditorGUI.GetPropertyHeight(reorderableList.serializedProperty.GetArrayElementAtIndex(index));
            reorderableList.onAddCallback         = (list) =>
            {
                list.serializedProperty.arraySize++;
                InitNewColumnInfo(list.serializedProperty.GetArrayElementAtIndex(list.serializedProperty.arraySize - 1), table);
                EditorUtility.SetDirty(target);
            };
            reorderableList.onReorderCallback = (list) => table.SetDirty();
        }
Ejemplo n.º 2
0
        void StyleGUI()
        {
            Object oldStyle = styleProperty.objectReferenceValue;

            styleProperty.objectReferenceValue = EditorGUILayout.ObjectField(new GUIContent("Style File"), styleProperty.objectReferenceValue, cellPrefab.StyleType, false);
            styleProperty.serializedObject.ApplyModifiedProperties();
            if (styleProperty.objectReferenceValue != oldStyle && table != null)
            {
                table.SetDirty();
            }
            if (styleProperty.objectReferenceValue == null)
            {
                return;
            }
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Settings", EditorStyles.boldLabel);
            EditorGUI.indentLevel++;
            SerializedObject   serializedObject = new SerializedObject(styleProperty.objectReferenceValue);
            SerializedProperty iterator         = serializedObject.GetIterator();

            while (iterator.NextVisible(true))
            {
                if (iterator.name == "m_Script" || iterator.propertyPath.Contains("."))
                {
                    continue;
                }
                if (iterator.name == "interactable" && memberInfo != null && !new PropertyOrFieldInfo(memberInfo).IsSettable)
                {
                    iterator.FindPropertyRelative("value").boolValue = false;
                    GUILayout.BeginHorizontal();
                    GUI.enabled = false;
                    EditorGUILayout.PropertyField(iterator, true);
                    GUI.enabled = true;
                    GUIStyle blueLabelStyle = new GUIStyle();
                    blueLabelStyle.normal.textColor = new Color(0.2f, 0.6f, 1f);
                    EditorGUILayout.LabelField(string.Format("Property {0} has no setter.", memberInfo.Name), blueLabelStyle);
                    GUILayout.EndHorizontal();
                    continue;
                }
                EditorGUILayout.PropertyField(iterator, true);
            }

            serializedObject.ApplyModifiedProperties();
        }