Beispiel #1
0
        void OnGUI()
        {
            if (GUILayout.Button("Search"))
            {
                if (filter != null)
                {
                    List <GameObject> results = GetAllGameObjects();
                    filter.Filter(results);
                    ResultsWindow.DisplayResult(results, filter, dockOutputWindow);
                }
            }
#if UNITY_2019_OR_NEWER
            dockOutputWindow = EditorGUILayout.ToggleLeft("Dock results window", dockOutputWindow);
#else
            GUI.enabled      = false;
            dockOutputWindow = EditorGUILayout.ToggleLeft("Dock results window (available in 2019 or newer)", dockOutputWindow);
            GUI.enabled      = true;
#endif
            using (var scope = new EditorGUILayout.HorizontalScope())
            {
                EditorGUILayout.LabelField("Filter");
                filter = (SearchFilter)EditorGUILayout.ObjectField(filter, typeof(SearchFilter), true);
                if (filter != null)
                {
                    SearchFilterGroup filterGroup = (filter as SearchFilterGroup);
                    if (filterGroup == null)
                    {
                        filterGroup = CreateInstance <SearchFilterGroup>();
                        filterGroup.AddSearchFilter(filter);
                        filter = filterGroup;
                    }
                }
                else
                {
                    filter = CreateInstance <SearchFilterGroup>();
                }
            }
            if (filter != null)
            {
                using (var scrollScope = new GUILayout.ScrollViewScope(scrollPos))
                {
                    scrollPos    = scrollScope.scrollPosition;
                    filterEditor = Editor.CreateEditor(filter);
                    filterEditor.OnInspectorGUI();
                }
            }
        }
Beispiel #2
0
 public override void OnInspectorGUI()
 {
     using (var vertScope = new EditorGUILayout.VerticalScope())
     {
         EditorGUI.indentLevel++;
         serializedObject.Update();
         SearchFilterGroup group   = (serializedObject.targetObject as SearchFilterGroup);
         SearchFilter[]    filters = group.searchFilters.ToArray();
         SearchFilterGroup groupTest;
         bool missing = false;
         for (int i = 0; i < filters.Length; i++)
         {
             missing = false;
             using (var filterScope = new EditorGUILayout.VerticalScope("Box"))
             {
                 if (filters[i] != null)
                 {
                     groupTest = filters[i] as SearchFilterGroup;
                     if (groupTest != null)
                     {
                         editor = CreateEditor(groupTest);
                     }
                     else
                     {
                         editor = CreateEditor(filters[i]);
                     }
                 }
                 else
                 {
                     editor  = CreateEditor(nullSearchFilter);
                     missing = true;
                 }
                 editor.OnInspectorGUI();
                 if (missing)
                 {
                     Color col  = GUI.contentColor;
                     Color bCol = GUI.backgroundColor;
                     GUI.backgroundColor = Color.red;
                     GUI.contentColor    = Color.red;
                     if (GUILayout.Button("Missing reference to filter click to remove"))
                     {
                         group.Remove(filters[i]);
                     }
                     GUI.contentColor    = col;
                     GUI.backgroundColor = bCol;
                 }
                 else
                 {
                     if (GUILayout.Button("Remove"))
                     {
                         group.Remove(filters[i]);
                     }
                 }
             }
             GUILayout.Space(10);
         }
         using (var horScope = new EditorGUILayout.HorizontalScope("Box"))
         {
             bool hit = GUILayout.Button("Add filter");
             addSearchFilter = (SearchFilter)EditorGUILayout.ObjectField(addSearchFilter, typeof(SearchFilter), true);
             if (addSearchFilter != null && hit)
             {
                 group.AddSearchFilter(addSearchFilter);
                 addSearchFilter = null;
                 EditorUtility.SetDirty(this);
             }
         }
     }
     serializedObject.ApplyModifiedProperties();
     EditorUtility.SetDirty(serializedObject.targetObject);
 }