예제 #1
0
        private void OnEnable()
        {
            instance = this;

            lookInOption  = (FindReplace_LookIn)EditorPrefs.GetInt("FlipbookGames.ScriptInspector.FindReplace.LookIn", 0);
            lookForOption = (FindReplace_LookFor)EditorPrefs.GetInt("FlipbookGames.ScriptInspector.FindReplace.LookFor", 0);

            matchCase              = EditorPrefs.GetBool("FlipbookGames.ScriptInspector.FindReplace.MatchCase", false);
            matchWholeWord         = EditorPrefs.GetBool("FlipbookGames.ScriptInspector.FindReplace.MatchWholeWord", false);
            listResultsInNewWindow = EditorPrefs.GetBool("FlipbookGames.ScriptInspector.FindReplace.ListResultsInNewWindow", false);

#if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5_0
            title = "Find Text";
#else
            titleContent.text = "Find Text";
#endif
            minSize = new Vector2(fixedWidth, fixedHeightFind);
            maxSize = new Vector2(fixedWidth, fixedHeightFind);
            Repaint();

            for (var i = 0; i < searchHistory.Length; i++)
            {
                searchHistory[i] = EditorPrefs.GetString("FlipbookGames.ScriptInspector.SearchHistory_" + i.ToString());
                if (searchHistory[i] == "")
                {
                    searchHistory[i] = null;
                    break;
                }
            }
        }
예제 #2
0
        public FindResultsWindow ListAllResults()
        {
            string[] allTextAssetGuids;
            var      lookInOption = this.lookInOption;

            if (lookForOption == FindReplace_LookFor.AllAssets ||
                lookForOption == FindReplace_LookFor.Shaders ||
                lookForOption == FindReplace_LookFor.TextAssets)
            {
                if (lookInOption > FindReplace_LookIn.CurrentTabOnly)
                {
                    lookInOption = FindReplace_LookIn.WholeProject;
                }
            }

            if (lookInOption == FindReplace_LookIn.OpenTabsOnly)
            {
                allTextAssetGuids = (from w in FGCodeWindow.CodeWindows select w.TargetAssetGuid).Distinct().ToArray();
            }
            else if (lookInOption == FindReplace_LookIn.CurrentTabOnly)
            {
                allTextAssetGuids = new [] { editor != null ? editor.targetGuid : FGCodeWindow.GetGuidHistory().FirstOrDefault() };
            }
            else if (lookInOption != FindReplace_LookIn.WholeProject &&
                     lookForOption != FindReplace_LookFor.AllAssets &&
                     lookForOption != FindReplace_LookFor.Shaders &&
                     lookForOption != FindReplace_LookFor.TextAssets)
            {
                if (FGFindInFiles.assets != null)
                {
                    FGFindInFiles.assets.Clear();
                }

                if (lookInOption == FindReplace_LookIn.FirstPassGameAssemblies || lookInOption == FindReplace_LookIn.AllGameAssemblies)
                {
                    if (lookForOption == FindReplace_LookFor.CSharpScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
                    {
                        FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.CSharpFirstPass);
                    }
                    if (lookForOption == FindReplace_LookFor.JSScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
                    {
                        FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.UnityScriptFirstPass);
                    }
                    if (lookForOption == FindReplace_LookFor.BooScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
                    {
                        FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.BooFirstPass);
                    }
                }
                if (lookInOption == FindReplace_LookIn.GameAssemblies || lookInOption == FindReplace_LookIn.AllGameAssemblies)
                {
                    if (lookForOption == FindReplace_LookFor.CSharpScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
                    {
                        FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.CSharp);
                    }
                    if (lookForOption == FindReplace_LookFor.JSScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
                    {
                        FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.UnityScript);
                    }
                    if (lookForOption == FindReplace_LookFor.BooScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
                    {
                        FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.Boo);
                    }
                }
                if (lookInOption == FindReplace_LookIn.FirstPassEditorAssemblies || lookInOption == FindReplace_LookIn.AllEditorAssemblies)
                {
                    if (lookForOption == FindReplace_LookFor.CSharpScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
                    {
                        FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.CSharpEditorFirstPass);
                    }
                    if (lookForOption == FindReplace_LookFor.JSScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
                    {
                        FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.UnityScriptEditorFirstPass);
                    }
                    if (lookForOption == FindReplace_LookFor.BooScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
                    {
                        FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.BooEditorFirstPass);
                    }
                }
                if (lookInOption == FindReplace_LookIn.EditorAssemblies || lookInOption == FindReplace_LookIn.AllEditorAssemblies)
                {
                    if (lookForOption == FindReplace_LookFor.CSharpScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
                    {
                        FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.CSharpEditor);
                    }
                    if (lookForOption == FindReplace_LookFor.JSScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
                    {
                        FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.UnityScriptEditor);
                    }
                    if (lookForOption == FindReplace_LookFor.BooScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
                    {
                        FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.BooEditor);
                    }
                }

                allTextAssetGuids = FGFindInFiles.assets.ToArray();
            }
            else
            {
                allTextAssetGuids = FGFindInFiles.FindAllTextAssets().ToArray();

                IEnumerable <string> realTextAssets = null;
                switch (lookForOption)
                {
                case FindReplace_LookFor.AllAssets:
                    realTextAssets =
                        from guid in allTextAssetGuids
                        where !ignoreFileTypes.Contains(Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant()))
                        select guid;
                    break;

                case FindReplace_LookFor.AllScriptTypes:
                    realTextAssets =
                        from guid in allTextAssetGuids
                        where scriptFileTypes.Contains(Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant()))
                        select guid;
                    break;

                case FindReplace_LookFor.CSharpScripts:
                    realTextAssets =
                        from guid in allTextAssetGuids
                        where Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant()) == ".cs"
                        select guid;
                    break;

                case FindReplace_LookFor.JSScripts:
                    realTextAssets =
                        from guid in allTextAssetGuids
                        where Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant()) == ".js"
                        select guid;
                    break;

                case FindReplace_LookFor.BooScripts:
                    realTextAssets =
                        from guid in allTextAssetGuids
                        where Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant()) == ".boo"
                        select guid;
                    break;

                case FindReplace_LookFor.Shaders:
                    realTextAssets =
                        from guid in allTextAssetGuids
                        where shaderFileTypes.Contains(Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant()))
                        select guid;
                    break;

                case FindReplace_LookFor.TextAssets:
                    realTextAssets =
                        from guid in allTextAssetGuids
                        where !nonTextFileTypes.Contains(Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant()))
                        select guid;
                    break;
                }

                allTextAssetGuids = realTextAssets.ToArray();
            }

            if (allTextAssetGuids.Length == 0 || allTextAssetGuids.Length == 1 && allTextAssetGuids[0] == null)
            {
                Debug.LogWarning("No asset matches selected searching scope!");
                return(null);
            }

            var searchOptions = new FindResultsWindow.SearchOptions {
                text      = findText,
                matchCase = matchCase,
                matchWord = matchWholeWord,
            };

            FindResultsWindow resultsWindow = FindResultsWindow.Create(
                "Searching for '" + findText + "'...",
                FGFindInFiles.FindAllInSingleFile,
                allTextAssetGuids,
                searchOptions,
                isReplace ? "<b>Replace</b>" : listResultsInNewWindow ? "" : "Find Results");

            return(resultsWindow);
        }
예제 #3
0
        private void OnGUI()
        {
            if (Event.current.type == EventType.KeyDown)
            {
                if (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter)
                {
                    Event.current.Use();
                    if (findText != "" && (!isReplace || findText != replaceText))
                    {
                        if (isReplace)
                        {
                            ReplaceSelected();
                        }
                        else
                        {
                            FindAll();
                        }
                    }
                    return;
                }
                else if (Event.current.character == '\n')
                {
                    Event.current.Use();
                    return;
                }
                else if (Event.current.keyCode == KeyCode.Escape)
                {
                    Event.current.Use();
                    Close();
                    if (editor != null && editor.OwnerWindow)
                    {
                        editor.OwnerWindow.Focus();
                    }
                    else if (ownerWindow)
                    {
                        ownerWindow.Focus();
                    }
                    return;
                }
                else if (Event.current.keyCode == KeyCode.DownArrow)
                {
                    if (GUI.GetNameOfFocusedControl() == "Find field")
                    {
                        ShowFindHistory();
                    }
                    else if (GUI.GetNameOfFocusedControl() == "Replace field")
                    {
                        ShowReplaceHistory();
                    }
                }
            }

            // Left margin
            GUILayout.BeginHorizontal();
            GUILayout.Space(10f);
            {
                // Top margin
                GUILayout.BeginVertical();
                GUILayout.Space(10f);

                isReplace = 1 == GUILayout.Toolbar(isReplace ? 1 : 0, toolbarTexts);
                GUILayout.Space(10f);

                GUILayout.Label("Find what:");

                GUILayout.BeginHorizontal();

                GUI.SetNextControlName("Find field");
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_1 && !UNITY_4_2
                if (setInitialFocus)
                {
                    EditorGUI.FocusTextInControl("Find field");
                }
#endif
                try { findText = EditorGUILayout.TextField(findText); } catch {}
                if (setInitialFocus)
                {
                    GUI.FocusControl("Find field");
                }
                setInitialFocus = false;

                if (GUILayout.Button(GUIContent.none, EditorStyles.toolbarDropDown, historyLayoutOptions))
                {
                    ShowFindHistory();
                }

                GUILayout.Space(4f);
                GUILayout.EndHorizontal();

                if (isReplace)
                {
                    GUILayout.Space(10f);

                    GUILayout.Label("Replace with:");

                    replaceText = replaceText ?? findText;

                    GUILayout.BeginHorizontal();

                    GUI.SetNextControlName("Replace field");
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_1 && !UNITY_4_2
                    if (setReplaceFocus)
                    {
                        EditorGUI.FocusTextInControl("Replace field");
                    }
#endif
                    try { replaceText = EditorGUILayout.TextField(replaceText); } catch {}
                    if (setReplaceFocus)
                    {
                        GUI.FocusControl("Replace field");
                    }
                    setReplaceFocus = false;

                    if (GUILayout.Button(GUIContent.none, EditorStyles.toolbarDropDown, historyLayoutOptions))
                    {
                        ShowReplaceHistory();
                    }

                    GUILayout.Space(4f);
                    GUILayout.EndHorizontal();
                }

                GUILayout.Space(10f);

                GUI.SetNextControlName("Asset types");
                lookForOption = (FindReplace_LookFor)EditorGUILayout.EnumPopup("Asset types:", lookForOption);
                if (resetFocus)
                {
                    GUI.FocusControl("Asset types");
                }
                resetFocus = false;

#if !UNITY_2017_3_OR_NEWER
                if (lookForOption != FindReplace_LookFor.AllAssets &&
                    lookForOption != FindReplace_LookFor.Shaders && lookForOption != FindReplace_LookFor.TextAssets)
                {
                    lookInOption = (FindReplace_LookIn)EditorGUILayout.Popup("Search scope:", (int)lookInOption, lookInOptionsAll);
                }
                else
#endif
                {
                    var option = (int)lookInOption;
                    if (lookInOption > FindReplace_LookIn.CurrentTabOnly)
                    {
                        option = (int)FindReplace_LookIn.WholeProject;
                    }
                    var newOption = EditorGUILayout.Popup("Search scope:", option, lookInOptionsNoAssemblies);
                    if (newOption != option)
                    {
                        lookInOption = (FindReplace_LookIn)newOption;
                    }
                }

                GUILayout.Space(10f);

#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_1 && !UNITY_4_2
                matchCase      = EditorGUILayout.ToggleLeft(" Match case", matchCase);
                matchWholeWord = EditorGUILayout.ToggleLeft(" Match whole words", matchWholeWord);
                if (!isReplace)
                {
                    listResultsInNewWindow = EditorGUILayout.ToggleLeft(" List results in a new window", listResultsInNewWindow);
                }
#else
                matchCase      = GUILayout.Toggle(matchCase, " Match case");
                matchWholeWord = GUILayout.Toggle(matchWholeWord, " Match whole words");
                if (!isReplace)
                {
                    listResultsInNewWindow = GUILayout.Toggle(listResultsInNewWindow, " List results in new window");
                }
#endif

                GUILayout.Space(10f);

                GUI.enabled = findText != "" && (!isReplace || findText != replaceText);

                GUILayout.BeginHorizontal();
                {
                    GUILayout.FlexibleSpace();
                    if (isReplace)
                    {
                        if (GUILayout.Button("Replace Selected"))
                        {
                            ReplaceSelected();
                        }

                        /* Uncomment this block to enable the "Replace All" button
                         * ("Replace Selected" will still be default)
                         */
                        //GUILayout.Space(6f);
                        //if (GUILayout.Button("Replace All"))
                        //{
                        //	ReplaceAll();
                        //}
                    }
                    else
                    {
                        if (GUILayout.Button("Find All"))
                        {
                            FindAll();
                        }
                    }
                    GUILayout.Space(6f);

                    GUI.enabled = true;

                    if (GUILayout.Button("Cancel"))
                    {
                        Close();
                        if (editor != null && editor.OwnerWindow)
                        {
                            editor.OwnerWindow.Focus();
                        }
                        else if (ownerWindow)
                        {
                            ownerWindow.Focus();
                        }
                    }
                }
                GUILayout.EndHorizontal();

                GUILayout.Space(20f);
                GUILayout.EndVertical();
            }
            GUILayout.Space(10f);
            GUILayout.EndHorizontal();

            if (isReplace)
            {
                if (position.height != fixedHeightReplace)
                {
                    maxSize = new Vector2(fixedWidth, fixedHeightReplace);
                    minSize = new Vector2(fixedWidth, fixedHeightReplace);
                }
            }
            else
            {
                if (position.height != fixedHeightFind)
                {
                    maxSize = new Vector2(fixedWidth, fixedHeightFind);
                    minSize = new Vector2(fixedWidth, fixedHeightFind);
                }
            }
        }
예제 #4
0
        private void OnGUI()
        {
            if (Event.current.type == EventType.KeyDown)
            {
                if (findText != "" && (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter))
                {
                    Event.current.Use();
                    Execute();
                    return;
                }
                else if (Event.current.keyCode == KeyCode.Escape)
                {
                    Event.current.Use();
                    Close();
                    if (editor != null && editor.OwnerWindow)
                    {
                        editor.OwnerWindow.Focus();
                    }
                    return;
                }
                else if (Event.current.keyCode == KeyCode.DownArrow)
                {
                    if (GUI.GetNameOfFocusedControl() == "Find field")
                    {
                        ShowFindHistory();
                    }
                }
            }

            // Left margin
            GUILayout.BeginHorizontal();
            GUILayout.Space(10f);
            {
                // Top margin
                GUILayout.BeginVertical();
                GUILayout.Space(10f);

                isReplace = false;         // 1 == GUILayout.Toolbar(isReplace ? 1 : 0, toolbarTexts);
                //GUILayout.Space(10f);

                GUILayout.Label("Find what:");

                GUILayout.BeginHorizontal();

                GUI.SetNextControlName("Find field");
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_1 && !UNITY_4_2
                if (setInitialFocus)
                {
                    EditorGUI.FocusTextInControl("Find field");
                }
#endif
                try { findText = EditorGUILayout.TextField(findText); } catch {}
                if (setInitialFocus)
                {
                    GUI.FocusControl("Find field");
                }
                setInitialFocus = false;

                if (GUILayout.Button(GUIContent.none, EditorStyles.toolbarDropDown, GUILayout.Height(16f), GUILayout.Width(13f)))
                {
                    ShowFindHistory();
                }

                GUILayout.Space(4f);

                GUILayout.EndHorizontal();

                if (isReplace)
                {
                    GUILayout.Space(10f);

                    GUILayout.Label("Replace with:");

                    replaceText = replaceText ?? findText;
                    try { replaceText = EditorGUILayout.TextField(replaceText); } catch {}
                }

                GUILayout.Space(10f);

                GUI.SetNextControlName("Look for");
                lookForOption = (FindReplace_LookFor)EditorGUILayout.EnumPopup("Look for:", lookForOption);
                if (resetFocus)
                {
                    GUI.FocusControl("Look for");
                }
                resetFocus = false;

                if (lookForOption != FindReplace_LookFor.AllAssets &&
                    lookForOption != FindReplace_LookFor.Shaders && lookForOption != FindReplace_LookFor.TextAssets)
                {
                    lookInOption = (FindReplace_LookIn)EditorGUILayout.EnumPopup("Look in:", lookInOption);
                }
                else
                {
                    GUI.enabled = false;
                    EditorGUILayout.EnumPopup("Look in:", FindReplace_LookIn.AllAssemblies);
                    GUI.enabled = true;
                }

                GUILayout.Space(10f);

#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_1 && !UNITY_4_2
                matchCase              = EditorGUILayout.ToggleLeft(" Match case", matchCase);
                matchWholeWord         = EditorGUILayout.ToggleLeft(" Match whole word", matchWholeWord);
                listResultsInNewWindow = EditorGUILayout.ToggleLeft(" List results in a new window", listResultsInNewWindow);
#else
                matchCase              = GUILayout.Toggle(matchCase, " Match case");
                matchWholeWord         = GUILayout.Toggle(matchWholeWord, " Match whole word");
                listResultsInNewWindow = GUILayout.Toggle(listResultsInNewWindow, " List results in new window");
#endif

                GUILayout.Space(10f);

                GUI.enabled = findText != "";

                GUILayout.BeginHorizontal();
                {
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Button("Find All"))
                    {
                        Execute();
                    }
                    GUILayout.Space(6f);

                    GUI.enabled = true;

                    if (GUILayout.Button("Cancel"))
                    {
                        Close();
                        if (editor != null && editor.OwnerWindow)
                        {
                            editor.OwnerWindow.Focus();
                        }
                    }
                }
                GUILayout.EndHorizontal();

                GUILayout.Space(20f);
                GUILayout.EndVertical();
            }
            GUILayout.Space(10f);
            GUILayout.EndHorizontal();

            if (isReplace)
            {
                if (position.height != fixedHeightReplace)
                {
                    maxSize = new Vector2(fixedWidth, fixedHeightReplace);
                    minSize = new Vector2(fixedWidth, fixedHeightReplace);
                }
            }
            else
            {
                if (position.height != fixedHeightFind)
                {
                    maxSize = new Vector2(fixedWidth, fixedHeightFind);
                    minSize = new Vector2(fixedWidth, fixedHeightFind);
                }
            }
        }
	public FindResultsWindow ListAllResults()
	{
		string[] allTextAssetGuids;
		var lookInOption = this.lookInOption;
		if (lookForOption == FindReplace_LookFor.AllAssets ||
			lookForOption == FindReplace_LookFor.Shaders ||
			lookForOption == FindReplace_LookFor.TextAssets)
		{
			if (lookInOption > FindReplace_LookIn.CurrentTabOnly)
				lookInOption = FindReplace_LookIn.WholeProject;
		}
		
		if (lookInOption == FindReplace_LookIn.OpenTabsOnly)
		{
			allTextAssetGuids = (from w in FGCodeWindow.CodeWindows select w.TargetAssetGuid).Distinct().ToArray();
		}
		else if (lookInOption == FindReplace_LookIn.CurrentTabOnly)
		{
			allTextAssetGuids = new [] { editor != null ? editor.targetGuid : FGCodeWindow.GetGuidHistory().FirstOrDefault() };
		}
		else if (lookInOption != FindReplace_LookIn.WholeProject &&
			lookForOption != FindReplace_LookFor.AllAssets &&
			lookForOption != FindReplace_LookFor.Shaders &&
			lookForOption != FindReplace_LookFor.TextAssets)
		{
			if (FGFindInFiles.assets != null)
				FGFindInFiles.assets.Clear();
			
			if (lookInOption == FindReplace_LookIn.FirstPassGameAssemblies || lookInOption == FindReplace_LookIn.AllGameAssemblies)
			{
				if (lookForOption == FindReplace_LookFor.CSharpScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
					FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.CSharpFirstPass);
				if (lookForOption == FindReplace_LookFor.JSScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
					FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.UnityScriptFirstPass);
				if (lookForOption == FindReplace_LookFor.BooScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
					FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.BooFirstPass);
			}
			if (lookInOption == FindReplace_LookIn.GameAssemblies || lookInOption == FindReplace_LookIn.AllGameAssemblies)
			{
				if (lookForOption == FindReplace_LookFor.CSharpScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
					FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.CSharp);
				if (lookForOption == FindReplace_LookFor.JSScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
					FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.UnityScript);
				if (lookForOption == FindReplace_LookFor.BooScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
					FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.Boo);
			}
			if (lookInOption == FindReplace_LookIn.FirstPassEditorAssemblies || lookInOption == FindReplace_LookIn.AllEditorAssemblies)
			{
				if (lookForOption == FindReplace_LookFor.CSharpScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
					FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.CSharpEditorFirstPass);
				if (lookForOption == FindReplace_LookFor.JSScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
					FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.UnityScriptEditorFirstPass);
				if (lookForOption == FindReplace_LookFor.BooScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
					FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.BooEditorFirstPass);
			}
			if (lookInOption == FindReplace_LookIn.EditorAssemblies || lookInOption == FindReplace_LookIn.AllEditorAssemblies)
			{
				if (lookForOption == FindReplace_LookFor.CSharpScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
					FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.CSharpEditor);
				if (lookForOption == FindReplace_LookFor.JSScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
					FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.UnityScriptEditor);
				if (lookForOption == FindReplace_LookFor.BooScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
					FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.BooEditor);
			}
			
			allTextAssetGuids = FGFindInFiles.assets.ToArray();
		}
		else
		{
			allTextAssetGuids = FGFindInFiles.FindAllTextAssets().ToArray();

			IEnumerable<string> realTextAssets = null;
			switch (lookForOption)
			{
			case FindReplace_LookFor.AllAssets:
				realTextAssets =
					from guid in allTextAssetGuids
					where ! ignoreFileTypes.Contains(Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant()))
					select guid;
				break;
			case FindReplace_LookFor.AllScriptTypes:
				realTextAssets =
					from guid in allTextAssetGuids
					where scriptFileTypes.Contains(Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant()))
					select guid;
				break;
			case FindReplace_LookFor.CSharpScripts:
				realTextAssets =
					from guid in allTextAssetGuids
					where Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant()) == ".cs"
					select guid;
				break;
			case FindReplace_LookFor.JSScripts:
				realTextAssets =
					from guid in allTextAssetGuids
					where Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant()) == ".js"
					select guid;
				break;
			case FindReplace_LookFor.BooScripts:
				realTextAssets =
					from guid in allTextAssetGuids
					where Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant()) == ".boo"
					select guid;
				break;
			case FindReplace_LookFor.Shaders:
				realTextAssets =
					from guid in allTextAssetGuids
					where shaderFileTypes.Contains(Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant()))
					select guid;
				break;
			case FindReplace_LookFor.TextAssets:
				realTextAssets =
					from guid in allTextAssetGuids
					where ! nonTextFileTypes.Contains(Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant()))
					select guid;
				break;
			}
			
			allTextAssetGuids = realTextAssets.ToArray();
		}
		
		if (allTextAssetGuids.Length == 0 || allTextAssetGuids.Length == 1 && allTextAssetGuids[0] == null)
		{
			Debug.LogWarning("No asset matches selected searching scope!");
			return null;
		}
		
		var searchOptions = new FindResultsWindow.SearchOptions {
			text = findText,
			matchCase = matchCase,
			matchWord = matchWholeWord,
		};
		
		FindResultsWindow resultsWindow = FindResultsWindow.Create(
			"Searching for '" + findText + "'...",
			FGFindInFiles.FindAllInSingleFile,
			allTextAssetGuids,
			searchOptions,
			isReplace ? "<b>Replace</b>" : listResultsInNewWindow ? "" : "Find Results");
		return resultsWindow;
	}
	private void OnGUI()
	{
		if (Event.current.type == EventType.KeyDown)
		{
			if (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter)
			{
				Event.current.Use();
				if (findText != "" && (!isReplace || findText != replaceText))
				{
					if (isReplace)
						ReplaceSelected();
					else
						FindAll();
				}
				return;
			}
			else if (Event.current.character == '\n')
			{
				Event.current.Use();
				return;
			}
			else if (Event.current.keyCode == KeyCode.Escape)
			{
				Event.current.Use();
				Close();
				if (editor != null && editor.OwnerWindow)
					editor.OwnerWindow.Focus();
				else if (ownerWindow)
					ownerWindow.Focus();
				return;
			}
			else if (Event.current.keyCode == KeyCode.DownArrow)
			{
				if (GUI.GetNameOfFocusedControl() == "Find field")
				{
					ShowFindHistory();
				}
				else if (GUI.GetNameOfFocusedControl() == "Replace field")
				{
					ShowReplaceHistory();
				}
			}
		}
		
		// Left margin
		GUILayout.BeginHorizontal();
		GUILayout.Space(10f);
		{
			// Top margin
			GUILayout.BeginVertical();
			GUILayout.Space(10f);
			
			isReplace = 1 == GUILayout.Toolbar(isReplace ? 1 : 0, toolbarTexts);
			GUILayout.Space(10f);
			
			GUILayout.Label("Find what:");
			
			GUILayout.BeginHorizontal();
			
			GUI.SetNextControlName("Find field");
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_1 && !UNITY_4_2
			if (setInitialFocus)
				EditorGUI.FocusTextInControl("Find field");
#endif
			try { findText = EditorGUILayout.TextField(findText); } catch {}
			if (setInitialFocus)
				GUI.FocusControl("Find field");
			setInitialFocus = false;
			
			if (GUILayout.Button(GUIContent.none, EditorStyles.toolbarDropDown, historyLayoutOptions))
				ShowFindHistory();
			
			GUILayout.Space(4f);
			GUILayout.EndHorizontal();
			
			if (isReplace)
			{
				GUILayout.Space(10f);
				
				GUILayout.Label("Replace with:");
				
				replaceText = replaceText ?? findText;
				
				GUILayout.BeginHorizontal();
				
				GUI.SetNextControlName("Replace field");
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_1 && !UNITY_4_2
				if (setReplaceFocus)
					EditorGUI.FocusTextInControl("Replace field");
#endif
				try { replaceText = EditorGUILayout.TextField(replaceText); } catch {}
				if (setReplaceFocus)
					GUI.FocusControl("Replace field");
				setReplaceFocus = false;
				
				if (GUILayout.Button(GUIContent.none, EditorStyles.toolbarDropDown, historyLayoutOptions))
					ShowReplaceHistory();
				
				GUILayout.Space(4f);
				GUILayout.EndHorizontal();
			}
			
			GUILayout.Space(10f);
			
			GUI.SetNextControlName("Asset types");
			lookForOption = (FindReplace_LookFor) EditorGUILayout.EnumPopup("Asset types:", lookForOption);
			if (resetFocus)
				GUI.FocusControl("Asset types");
			resetFocus = false;
			
			if (lookForOption != FindReplace_LookFor.AllAssets &&
				lookForOption != FindReplace_LookFor.Shaders && lookForOption != FindReplace_LookFor.TextAssets)
			{
				lookInOption = (FindReplace_LookIn) EditorGUILayout.Popup("Search scope:", (int) lookInOption, lookInOptionsAll);
			}
			else
			{
				var option = (int) lookInOption;
				if (lookInOption > FindReplace_LookIn.CurrentTabOnly)
					option = (int) FindReplace_LookIn.WholeProject;
				var newOption = EditorGUILayout.Popup("Search scope:", option, lookInOptionsNoAssemblies);
				if (newOption != option)
					lookInOption = (FindReplace_LookIn) newOption;
			}
			
			GUILayout.Space(10f);
			
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_1 && !UNITY_4_2
			matchCase = EditorGUILayout.ToggleLeft(" Match case", matchCase);
			matchWholeWord = EditorGUILayout.ToggleLeft(" Match whole words", matchWholeWord);
			if (!isReplace)
				listResultsInNewWindow = EditorGUILayout.ToggleLeft(" List results in a new window", listResultsInNewWindow);
#else
			matchCase = GUILayout.Toggle(matchCase, " Match case");
			matchWholeWord = GUILayout.Toggle(matchWholeWord, " Match whole words");
			if (!isReplace)
				listResultsInNewWindow = GUILayout.Toggle(listResultsInNewWindow, " List results in new window");
#endif
			
			GUILayout.Space(10f);
			
			GUI.enabled = findText != "" && (!isReplace || findText != replaceText);
			
			GUILayout.BeginHorizontal();
			{
				GUILayout.FlexibleSpace();
				if (isReplace)
				{
					if (GUILayout.Button("Replace Selected"))
					{
						ReplaceSelected();
					}
					
					/* Uncomment this block to enable the "Replace All" button
					 * ("Replace Selected" will still be default)
					 */
					//GUILayout.Space(6f);
					//if (GUILayout.Button("Replace All"))
					//{
					//	ReplaceAll();
					//}
				}
				else
				{
					if (GUILayout.Button("Find All"))
					{
						FindAll();
					}
				}
				GUILayout.Space(6f);
				
				GUI.enabled = true;
				
				if (GUILayout.Button("Cancel"))
				{
					Close();
					if (editor != null && editor.OwnerWindow)
						editor.OwnerWindow.Focus();
					else if (ownerWindow)
						ownerWindow.Focus();
				}
			}
			GUILayout.EndHorizontal();
		
			GUILayout.Space(20f);
			GUILayout.EndVertical();
		}
		GUILayout.Space(10f);
		GUILayout.EndHorizontal();
		
		if (isReplace)
		{
			if (position.height != fixedHeightReplace)
			{
				maxSize = new Vector2(fixedWidth, fixedHeightReplace);
				minSize = new Vector2(fixedWidth, fixedHeightReplace);
			}
		}
		else
		{
			if (position.height != fixedHeightFind)
			{
				maxSize = new Vector2(fixedWidth, fixedHeightFind);
				minSize = new Vector2(fixedWidth, fixedHeightFind);
			}
		}
	}
	private void OnEnable()
	{
		instance = this;
		
		lookInOption = (FindReplace_LookIn) EditorPrefs.GetInt("FlipbookGames.ScriptInspector.FindReplace.LookIn", 0);
		lookForOption = (FindReplace_LookFor) EditorPrefs.GetInt("FlipbookGames.ScriptInspector.FindReplace.LookFor", 0);
		
		matchCase = EditorPrefs.GetBool("FlipbookGames.ScriptInspector.FindReplace.MatchCase", false);
		matchWholeWord = EditorPrefs.GetBool("FlipbookGames.ScriptInspector.FindReplace.MatchWholeWord", false);
		listResultsInNewWindow = EditorPrefs.GetBool("FlipbookGames.ScriptInspector.FindReplace.ListResultsInNewWindow", false);
		
#if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_5_0
		title = "Find Text";
#else
		titleContent.text = "Find Text";
#endif
		minSize = new Vector2(fixedWidth, fixedHeightFind);
		maxSize = new Vector2(fixedWidth, fixedHeightFind);
		Repaint();
		
		for (var i = 0; i < searchHistory.Length; i++)
		{
			searchHistory[i] = EditorPrefs.GetString("FlipbookGames.ScriptInspector.SearchHistory_" + i.ToString());
			if (searchHistory[i] == "")
			{
				searchHistory[i] = null;
				break;
			}
		}
		
		for (var i = 0; i < replaceHistory.Length; i++)
		{
			replaceHistory[i] = EditorPrefs.GetString("FlipbookGames.ScriptInspector.ReplaceHistory_" + i.ToString());
			if (replaceHistory[i] == "")
			{
				replaceHistory[i] = null;
				break;
			}
		}
	}