Exemplo n.º 1
0
        private void OnEnable()
        {
            // Load Saved Setting
            if (_searchStringInAssetsSetting != null)
            {
                return;
            }
            var guid = EditorPrefs.GetString(SaveKey, null);

            if (string.IsNullOrEmpty(guid) == false)
            {
#if ENABLE_SEARCH_STRING_IN_ASSETS_LOG
                Debug.Log($"Load Settings GUID: {guid}");
#endif
                guid = string.IsNullOrEmpty(guid) == false ? guid : DefaultSettingGUID;

                var path = AssetDatabase.GUIDToAssetPath(guid);
                var obj  = AssetDatabase.LoadAssetAtPath <SearchStringInAssetsSetting>(path);
                if (obj != null)
                {
                    _searchStringInAssetsSetting = obj;
                }
            }
        }
Exemplo n.º 2
0
        void OnGUI()
        {
            if (_dataPathLength <= 0)
            {
                SetDataPathLength();
            }

            GUI.skin.label.fontSize = 24;
            GUILayout.Label(Title, GUILayout.Height(40f));
            GUI.skin.label.fontSize = 0;

            _searchString = EditorGUILayout.TextField("Search keywords", _searchString);
            if (string.IsNullOrEmpty(_searchString) == false && ValidateInputText(_searchString) == false)
            {
                _searchString = "";
            }

            EditorGUILayout.Space();

            GUILayout.BeginHorizontal();
            {
                _searchStringInAssetsSetting =
                    (SearchStringInAssetsSetting)EditorGUILayout.ObjectField("Search Setting",
                                                                             _searchStringInAssetsSetting, typeof(SearchStringInAssetsSetting), false);

                EditorGUI.BeginDisabledGroup(_searchStringInAssetsSetting == null);
                {
                    if (GUILayout.Button("SAVE", GUILayout.Width(60f), GUILayout.Height(20f)))
                    {
                        SaveSetting();
                    }

                    if (GUILayout.Button("Edit", GUILayout.Width(60f), GUILayout.Height(20f)))
                    {
                        Selection.activeObject = _searchStringInAssetsSetting;
                    }
                }
                EditorGUI.EndDisabledGroup();
            }
            GUILayout.EndHorizontal();


            _isIgnoreSearchPattern = EditorGUILayout.ToggleLeft(
                new GUIContent("Ignore Search Pattern",
                               "If enable, search pattern in search setting is disabled.Use for full text search."),
                _isIgnoreSearchPattern);

            EditorGUILayout.Space();

            if (GUILayout.Button("Search", GUILayout.MaxWidth(100f), GUILayout.Height(24f)))
            {
                _searchResultObjectHashSet.Clear();

                if (string.IsNullOrEmpty(_searchString))
                {
                    return;
                }

                if (_isIgnoreSearchPattern == false)
                {
                    foreach (var pattern in _searchStringInAssetsSetting.searchPatterns)
                    {
                        Search(pattern, _searchResultObjectHashSet);
                    }
                }
                else
                {
                    Search(IgnoredSearchPattern, _searchResultObjectHashSet);
                }
            }

            EditorGUILayout.Space();

            EditorGUILayout.LabelField($"「{_searchString}」Search Results : {_searchResultObjectHashSet.Count}");

            _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos);
            {
                if (_searchResultObjectHashSet.Count > 0)
                {
                    EditorGUI.BeginDisabledGroup(true);
                    {
                        foreach (var asset in _searchResultObjectHashSet)
                        {
                            EditorGUILayout.ObjectField(asset.name, asset, asset.GetType(), false);
                        }
                    }
                    EditorGUI.EndDisabledGroup();
                }
                else
                {
                    EditorGUILayout.Space();
                    EditorGUILayout.LabelField("Not found.");
                    EditorGUILayout.Space();
                }
            }
            EditorGUILayout.EndScrollView();
        }