Esempio n. 1
0
 internal static string DoTextField(EditorGUI.RecycledTextEditor editor, int id, Rect position, string text, GUIStyle style, string allowedletters, out bool changed, bool reset, bool multiline, bool passwordField)
 {
   Event current = Event.current;
   string str1 = text;
   if (text == null)
     text = string.Empty;
   if (EditorGUI.showMixedValue)
     text = string.Empty;
   if (EditorGUI.HasKeyboardFocus(id) && Event.current.type != EventType.Layout)
   {
     if (editor.IsEditingControl(id))
     {
       editor.position = position;
       editor.style = style;
       editor.controlID = id;
       editor.multiline = multiline;
       editor.isPasswordField = passwordField;
       editor.DetectFocusChange();
     }
     else if (EditorGUIUtility.editingTextField)
     {
       editor.BeginEditing(id, text, position, style, multiline, passwordField);
       if ((double) GUI.skin.settings.cursorColor.a > 0.0)
         editor.SelectAll();
     }
   }
   if (editor.controlID == id && GUIUtility.keyboardControl != id)
     editor.controlID = 0;
   bool flag1 = false;
   string text1 = editor.text;
   EventType typeForControl = current.GetTypeForControl(id);
   switch (typeForControl)
   {
     case EventType.MouseDown:
       if (position.Contains(current.mousePosition) && current.button == 0)
       {
         if (editor.IsEditingControl(id))
         {
           if (Event.current.clickCount == 2 && GUI.skin.settings.doubleClickSelectsWord)
           {
             editor.MoveCursorToPosition(Event.current.mousePosition);
             editor.SelectCurrentWord();
             editor.MouseDragSelectsWholeWords(true);
             editor.DblClickSnap(TextEditor.DblClickSnapping.WORDS);
             EditorGUI.s_DragToPosition = false;
           }
           else if (Event.current.clickCount == 3 && GUI.skin.settings.tripleClickSelectsLine)
           {
             editor.MoveCursorToPosition(Event.current.mousePosition);
             editor.SelectCurrentParagraph();
             editor.MouseDragSelectsWholeWords(true);
             editor.DblClickSnap(TextEditor.DblClickSnapping.PARAGRAPHS);
             EditorGUI.s_DragToPosition = false;
           }
           else
           {
             editor.MoveCursorToPosition(Event.current.mousePosition);
             EditorGUI.s_SelectAllOnMouseUp = false;
           }
         }
         else
         {
           GUIUtility.keyboardControl = id;
           editor.BeginEditing(id, text, position, style, multiline, passwordField);
           editor.MoveCursorToPosition(Event.current.mousePosition);
           if ((double) GUI.skin.settings.cursorColor.a > 0.0)
             EditorGUI.s_SelectAllOnMouseUp = true;
         }
         GUIUtility.hotControl = id;
         current.Use();
         break;
       }
       break;
     case EventType.MouseUp:
       if (GUIUtility.hotControl == id)
       {
         if (EditorGUI.s_Dragged && EditorGUI.s_DragToPosition)
         {
           editor.MoveSelectionToAltCursor();
           flag1 = true;
         }
         else if (EditorGUI.s_PostPoneMove)
           editor.MoveCursorToPosition(Event.current.mousePosition);
         else if (EditorGUI.s_SelectAllOnMouseUp)
         {
           if ((double) GUI.skin.settings.cursorColor.a > 0.0)
             editor.SelectAll();
           EditorGUI.s_SelectAllOnMouseUp = false;
         }
         editor.MouseDragSelectsWholeWords(false);
         EditorGUI.s_DragToPosition = true;
         EditorGUI.s_Dragged = false;
         EditorGUI.s_PostPoneMove = false;
         if (current.button == 0)
         {
           GUIUtility.hotControl = 0;
           current.Use();
           break;
         }
         break;
       }
       break;
     case EventType.MouseDrag:
       if (GUIUtility.hotControl == id)
       {
         if (!current.shift && editor.hasSelection && EditorGUI.s_DragToPosition)
         {
           editor.MoveAltCursorToPosition(Event.current.mousePosition);
         }
         else
         {
           if (current.shift)
             editor.MoveCursorToPosition(Event.current.mousePosition);
           else
             editor.SelectToPosition(Event.current.mousePosition);
           EditorGUI.s_DragToPosition = false;
           EditorGUI.s_SelectAllOnMouseUp = !editor.hasSelection;
         }
         EditorGUI.s_Dragged = true;
         current.Use();
         break;
       }
       break;
     case EventType.KeyDown:
       if (GUIUtility.keyboardControl == id)
       {
         char character = current.character;
         if (editor.IsEditingControl(id) && editor.HandleKeyEvent(current))
         {
           current.Use();
           flag1 = true;
           break;
         }
         if (current.keyCode == KeyCode.Escape)
         {
           if (editor.IsEditingControl(id))
           {
             if (style == EditorStyles.toolbarSearchField || style == EditorStyles.searchField)
               EditorGUI.s_OriginalText = string.Empty;
             editor.text = EditorGUI.s_OriginalText;
             editor.EndEditing();
             flag1 = true;
             break;
           }
           break;
         }
         if ((int) character == 10 || (int) character == 3)
         {
           if (!editor.IsEditingControl(id))
           {
             editor.BeginEditing(id, text, position, style, multiline, passwordField);
             editor.SelectAll();
           }
           else if (!multiline || current.alt || (current.shift || current.control))
           {
             editor.EndEditing();
           }
           else
           {
             editor.Insert(character);
             flag1 = true;
             break;
           }
           current.Use();
           break;
         }
         if ((int) character == 9 || current.keyCode == KeyCode.Tab)
         {
           if (multiline && editor.IsEditingControl(id))
           {
             bool flag2 = allowedletters == null || allowedletters.IndexOf(character) != -1;
             if (!current.alt && !current.shift && !current.control && (int) character == 9 && flag2)
             {
               editor.Insert(character);
               flag1 = true;
               break;
             }
             break;
           }
           break;
         }
         if ((int) character != 25 && (int) character != 27 && editor.IsEditingControl(id))
         {
           if ((allowedletters == null || allowedletters.IndexOf(character) != -1) && (int) character != 0)
           {
             editor.Insert(character);
             flag1 = true;
             break;
           }
           if (Input.compositionString != string.Empty)
           {
             editor.ReplaceSelection(string.Empty);
             flag1 = true;
           }
           current.Use();
           break;
         }
         break;
       }
       break;
     case EventType.Repaint:
       string str2 = !editor.IsEditingControl(id) ? (!EditorGUI.showMixedValue ? (!passwordField ? text : string.Empty.PadRight(text.Length, '*')) : EditorGUI.s_MixedValueContent.text) : (!passwordField ? editor.text : string.Empty.PadRight(editor.text.Length, '*'));
       if (!string.IsNullOrEmpty(EditorGUI.s_UnitString) && !passwordField)
         str2 = str2 + " " + EditorGUI.s_UnitString;
       if (GUIUtility.hotControl == 0)
         EditorGUIUtility.AddCursorRect(position, MouseCursor.Text);
       if (!editor.IsEditingControl(id))
       {
         EditorGUI.BeginHandleMixedValueContentColor();
         style.Draw(position, EditorGUIUtility.TempContent(str2), id, false);
         EditorGUI.EndHandleMixedValueContentColor();
         break;
       }
       editor.DrawCursor(str2);
       break;
     default:
       switch (typeForControl - 13)
       {
         case EventType.MouseDown:
           if (GUIUtility.keyboardControl == id)
           {
             string commandName = current.commandName;
             if (commandName != null)
             {
               // ISSUE: reference to a compiler-generated field
               if (EditorGUI.\u003C\u003Ef__switch\u0024map0 == null)
               {
                 // ISSUE: reference to a compiler-generated field
                 EditorGUI.\u003C\u003Ef__switch\u0024map0 = new Dictionary<string, int>(6)
                 {
                   {
                     "Cut",
                     0
                   },
                   {
                     "Copy",
                     0
                   },
                   {
                     "Paste",
                     1
                   },
                   {
                     "SelectAll",
                     2
                   },
                   {
                     "UndoRedoPerformed",
                     3
                   },
                   {
                     "Delete",
                     4
                   }
                 };
               }
               int num;
               // ISSUE: reference to a compiler-generated field
               if (EditorGUI.\u003C\u003Ef__switch\u0024map0.TryGetValue(commandName, out num))
               {
                 switch (num)
                 {
                   case 0:
                     if (editor.hasSelection)
                     {
                       current.Use();
                       break;
                     }
                     break;
                   case 1:
                     if (editor.CanPaste())
                     {
                       current.Use();
                       break;
                     }
                     break;
                   case 2:
                     current.Use();
                     break;
                   case 3:
                     editor.text = text;
                     current.Use();
                     break;
                   case 4:
                     current.Use();
                     break;
                 }
               }
               else
                 break;
             }
             else
               break;
           }
           else
             break;
         case EventType.MouseUp:
           if (GUIUtility.keyboardControl == id)
           {
             string commandName = current.commandName;
             if (commandName != null)
             {
               // ISSUE: reference to a compiler-generated field
               if (EditorGUI.\u003C\u003Ef__switch\u0024map1 == null)
               {
                 // ISSUE: reference to a compiler-generated field
                 EditorGUI.\u003C\u003Ef__switch\u0024map1 = new Dictionary<string, int>(6)
                 {
                   {
                     "OnLostFocus",
                     0
                   },
                   {
                     "Cut",
                     1
                   },
                   {
                     "Copy",
                     2
                   },
                   {
                     "Paste",
                     3
                   },
                   {
                     "SelectAll",
                     4
                   },
                   {
                     "Delete",
                     5
                   }
                 };
               }
               int num;
               // ISSUE: reference to a compiler-generated field
               if (EditorGUI.\u003C\u003Ef__switch\u0024map1.TryGetValue(commandName, out num))
               {
                 switch (num)
                 {
                   case 0:
                     if (EditorGUI.activeEditor != null)
                       EditorGUI.activeEditor.EndEditing();
                     current.Use();
                     break;
                   case 1:
                     editor.BeginEditing(id, text, position, style, multiline, passwordField);
                     editor.Cut();
                     flag1 = true;
                     break;
                   case 2:
                     editor.Copy();
                     current.Use();
                     break;
                   case 3:
                     editor.BeginEditing(id, text, position, style, multiline, passwordField);
                     editor.Paste();
                     flag1 = true;
                     break;
                   case 4:
                     editor.SelectAll();
                     current.Use();
                     break;
                   case 5:
                     editor.BeginEditing(id, text, position, style, multiline, passwordField);
                     if (Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.OSXWebPlayer || (Application.platform == RuntimePlatform.OSXDashboardPlayer || Application.platform == RuntimePlatform.OSXEditor) || Application.platform == RuntimePlatform.WebGLPlayer && SystemInfo.operatingSystem.StartsWith("Mac"))
                       editor.Delete();
                     else
                       editor.Cut();
                     flag1 = true;
                     current.Use();
                     break;
                 }
               }
               else
                 break;
             }
             else
               break;
           }
           else
             break;
         case EventType.MouseDrag:
           if (position.Contains(current.mousePosition))
           {
             if (!editor.IsEditingControl(id))
             {
               GUIUtility.keyboardControl = id;
               editor.BeginEditing(id, text, position, style, multiline, passwordField);
               editor.MoveCursorToPosition(Event.current.mousePosition);
             }
             EditorGUI.ShowTextEditorPopupMenu();
             Event.current.Use();
             break;
           }
           break;
       }
   }
   if (GUIUtility.keyboardControl == id)
     GUIUtility.textFieldInput = true;
   editor.UpdateScrollOffsetIfNeeded();
   changed = false;
   if (flag1)
   {
     changed = text1 != editor.text;
     current.Use();
   }
   if (changed)
   {
     GUI.changed = true;
     return editor.text;
   }
   EditorGUI.RecycledTextEditor.s_AllowContextCutOrPaste = true;
   return str1;
 }