private void OnEnable()
    {
        playerPrefGroup = target as PlayerPrefGroup;

        filterList = new OnionReorderableList(new SerializedObject(playerPrefGroup).FindProperty("regexFilter"))
        {
            title     = "Regex Filters",
            titleIcon = OnionDataEditor.GetIconTexture("Filter"),
        };

        customGUIList = new OnionReorderableList(new SerializedObject(playerPrefGroup).FindProperty("customGUI"))
        {
            title     = "Custom GUI Type",
            titleIcon = OnionDataEditor.GetIconTexture("Filter"),
            customGUI = CustomItemGUI,
        };


        void CustomItemGUI(Rect r, SerializedProperty sp, int index)
        {
            var rs = r.HorizontalSplit(2, 4);

            EditorGUI.PropertyField(rs[0], sp.FindPropertyRelative("regexFilter"), GUIContent.none);
            EditorGUI.PropertyField(rs[1], sp.FindPropertyRelative("guiType"), GUIContent.none);
        }
    }
    private void OnEnable()
    {
        const float leftPadding = 14;
        const float space       = 3;

        if (iconList == null)
        {
            iconList = new OnionReorderableList(new SerializedObject(target).FindProperty("data"))
            {
                title         = "Icons",
                customGUI     = OnItemInspector,
                customHeadGUI = OnHeadInspector,
            };
        }

        void OnHeadInspector(Rect r)
        {
            using (var ch = new EditorGUI.ChangeCheckScope())
            {
                var rects = r.ExtendLeft(-leftPadding).HorizontalSplit(3, space);

                EditorGUI.LabelField(rects[0], new GUIContent("ID"));

                EditorGUI.LabelField(rects[1], new GUIContent("Default"));

                EditorGUI.LabelField(rects[2], new GUIContent("DarkMode"));
            }
        };

        void OnItemInspector(Rect r, SerializedProperty sp, int i)
        {
            using (var ch = new EditorGUI.ChangeCheckScope())
            {
                var rects = r.HorizontalSplit(3, space);

                EditorGUI.PropertyField(rects[0], sp.FindPropertyRelative("id"), GUIContent.none);

                EditorGUI.PropertyField(rects[1], sp.FindPropertyRelative("defaultIcon"), GUIContent.none);

                EditorGUI.PropertyField(rects[2], sp.FindPropertyRelative("darkModeIcon"), GUIContent.none);

                if (ch.changed)
                {
                    sp.serializedObject.ApplyModifiedProperties();
                    EditorUtility.SetDirty(target);
                }
            }
        };
    }
Exemplo n.º 3
0
    private void OnEnable()
    {
        assetFilterGroup = target as AssetFilterGroup;

        filterList = new OnionReorderableList(new SerializedObject(assetFilterGroup).FindProperty("filters"))
        {
            title         = "Filters",
            emptyListHint = "No filter",
            customGUI     = itemGUI,
            titleIcon     = OnionDataEditor.GetIconTexture("Filter"),
        };

        searchFolderList = new OnionReorderableList(new SerializedObject(assetFilterGroup).FindProperty("searchFolders"))
        {
            title         = "Search Folders",
            emptyListHint = "Search all folders",
            titleIcon     = OnionDataEditor.GetIconTexture("Folder"),
        };


        void itemGUI(Rect r, SerializedProperty sp, int inx)
        {
            if (string.IsNullOrEmpty(assetFilterGroup.filters[inx].value))
            {
                //IS NULL
                GUI.color = new Color(1F, 0.8F, 0.8F);
            }

            const float objWidth   = 150;
            const float spaceWidth = 10;

            Rect objRect = r;

            objRect.width = objWidth;

            Rect pathRect = r;

            pathRect.x     += objWidth + spaceWidth;
            pathRect.width -= objWidth + spaceWidth;

            using (var ch = new EditorGUI.ChangeCheckScope())
            {
                var o = EditorGUI.EnumPopup(objRect, assetFilterGroup.filters[inx].type);
                if (ch.changed)
                {
                    assetFilterGroup.filters[inx].type = (AssetFilterGroup.FilterType)o;
                }
            }

            using (var ch = new EditorGUI.ChangeCheckScope())
            {
                var p = GUI.TextField(pathRect, assetFilterGroup.filters[inx].value);
                if (ch.changed)
                {
                    assetFilterGroup.filters[inx].value = p;
                }
            }


            GUI.color = Color.white;
        }
    }