コード例 #1
0
        private void OnGUI()
        {
            int lineToGoTo;
            var validLineNumber = int.TryParse(text, out lineToGoTo) &&
                                  lineToGoTo >= 1 && lineToGoTo <= editor.TextBuffer.lines.Count;

            if (validLineNumber && Event.current.type == EventType.KeyDown && Event.current.character == '\n')
            {
                editor.SetCursorPosition(lineToGoTo - 1, 0);
                Close();
                editor.OwnerWindow.Focus();
                return;
            }
            else if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)
            {
                Close();
                editor.OwnerWindow.Focus();
                return;
            }

            GUILayout.BeginVertical();
            GUILayout.Space(20f);

            GUILayout.BeginHorizontal();
            GUILayout.Space(10f);

            GUI.SetNextControlName("text field");
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_1 && !UNITY_4_2
            EditorGUI.FocusTextInControl("text field");
#endif
            text = EditorGUILayout.TextField(text);
            GUI.FocusControl("text field");

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

            GUI.enabled = int.TryParse(text, out lineToGoTo) &&
                          lineToGoTo >= 1 && lineToGoTo <= editor.TextBuffer.lines.Count;

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("OK"))
            {
                editor.SetCursorPosition(lineToGoTo - 1, 0);
                Close();
                editor.OwnerWindow.Focus();
            }
            GUILayout.Space(6f);

            GUI.enabled = true;

            if (GUILayout.Button("Cancel"))
            {
                Close();
                editor.OwnerWindow.Focus();
            }
            GUILayout.Space(10f);
            GUILayout.EndHorizontal();

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