/// <summary> /// 初始化TestBox控件 TextField /// </summary> /// <param name="paramField_Start"></param> /// <param name="field"></param> /// <param name="isReadonly"></param> /// <returns></returns> private Field IniParamTextBox(string paramField_Start, ParamField field, bool isReadonly) { if (field.Type != ParamFieldType.TextBox) { return(null); } TextFieldBase result = null; if (!field.IsMult) { result = new TextField(); } else { // 多行文本框 result = new TextArea(); } if (!string.IsNullOrWhiteSpace(field.DefaultValue)) { result.Text = field.DefaultValue; } return(result); }
/// <summary> /// The focus at the Unity level could change with tabbing etc. /// It is important to correct this behaviour, because the FocusManager should handle all the focus logic /// This method is being called from StageManager, in each frame, from OnGUI() handler /// </summary> public static void HandleFocus() { /** * If this is the focused component and focus on this component already handled * our work is done, so return * */ if (string.IsNullOrEmpty(NextFocusId) && !_shouldHandleFocus && FocusManager.Instance.FocusedComponent == _previouslyFocusedComponent) { return; } /* Reset the "force" flag */ _shouldHandleFocus = false; _previouslyFocusedComponent = FocusManager.Instance.FocusedComponent; if (!string.IsNullOrEmpty(NextFocusId)) { #if DEBUG if (DebugMode) { Debug.Log("Handling focus DIRECTLY with NextFocusId = " + NextFocusId); } #endif DoFocusTextField(NextFocusId); NextFocusId = null; return; } //Debug.Log("GUIUtility.keyboardControl: " + GUIUtility.keyboardControl); _textField = FocusManager.Instance.FocusedComponent as TextFieldBase; if (null != _textField && _textField.FocusEnabled && _textField.Enabled) { #if DEBUG if (DebugMode) { Debug.Log("Handling focus on " + FocusManager.Instance.FocusedComponent + "(" + FocusManager.Instance.FocusedComponent.Uid + ")"); } #endif // @see http://answers.unity3d.com/questions/17169/select-text-in-gui-textfield.html // 'You must first focus something else (doesn't matter what, so long as it exists, "" or null will not suffice). Bit of an ugly kludge, but seems to work.' // A. Blur //BlurUnityFocus(); // BUG BUG BUG ??? Not needed! // B. Focus if (_textField.Rendered) { DoFocusTextField(); } else { _textField.AddEventListener(FrameworkEvent.FIRST_SHOW, delegate { DoFocusTextField(); }); } } else { BlurUnityFocus(); } FocusManager.Instance.TabbedToFocus = false; }