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
        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);
                }
            }
        }
        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);
                }
            }
        }
	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;
			}
		}
	}