コード例 #1
0
        public void OnGUI()
        {
            if (TouchScreenKeyboard.isSupported)
            {
                return;
            }

            if (_client == 0)
            {
                return;
            }


            while (!PointerEventConverter.KeyEvent.isEmpty())
            {
                var currentEvent = PointerEventConverter.KeyEvent.Dequeue();
                var oldValue     = _value;

                if (currentEvent != null && currentEvent.type == EventType.KeyDown)
                {
                    var response = TextInput._handleGlobalInputKey(_client,
                                                                   new RawKeyDownEvent(new RawKeyEventData(currentEvent)));

                    if (response.swallow)
                    {
                        if (response.inputAction != null)
                        {
                            Timer.create(TimeSpan.Zero,
                                         () => { TextInput._performAction(_client, response.inputAction.Value); });
                        }

                        if (_validateCharacter(response.input))
                        {
                            _value = _value.insert(new string(response.input, 1));
                        }
                    }
                    else if (currentEvent.keyCode == KeyCode.Backspace)
                    {
                        if (_value.selection.isValid)
                        {
                            _value = _value.deleteSelection(true);
                        }
                    }
                    else if (currentEvent.character != 0)
                    {
                        _value = _value.clearCompose();
                        char ch = currentEvent.character;
                        if (ch == '\r' || ch == 3)
                        {
                            ch = '\n';
                        }

                        if (ch == '\n')
                        {
                            Timer.create(TimeSpan.Zero, () => { TextInput._performAction(_client,
                                                                                         _textInputConfiguration?.inputAction ?? TextInputAction.newline); });
                        }

                        if (_validateCharacter(ch))
                        {
                            _value = _value.insert(new string(ch, 1));
                        }
                    }
                    else if (!string.IsNullOrEmpty(currentEvent.keyCode.ToString()))
                    {
                        isIMEInput = true;
                        _value     = _value.compose(currentEvent.keyCode.ToString());
                    }

                    currentEvent.Use();
                }

                if (_value != oldValue)
                {
                    if (this.isIMEInput)
                    {
                        var isIMEInput = this.isIMEInput;
                        Timer.create(TimeSpan.Zero,
                                     () => { TextInput._updateEditingState(_client, _value, isIMEInput); });
                        this.isIMEInput = false;
                    }
                    else
                    {
                        Timer.create(TimeSpan.Zero, () => { TextInput._updateEditingState(_client, _value, isIMEInput); });
                    }
                }
            }
        }
コード例 #2
0
        public void OnGUI()
        {
            if (TouchScreenKeyboard.isSupported)
            {
                return;
            }

            if (this._client == 0)
            {
                return;
            }


            var currentEvent = Event.current;
            var oldValue     = this._value;

            if (currentEvent != null && currentEvent.type == EventType.KeyDown)
            {
                var response = TextInput._handleGlobalInputKey(this._client,
                                                               new RawKeyDownEvent(new RawKeyEventData(currentEvent)));

                if (response.swallow)
                {
                    if (response.inputAction != null)
                    {
                        Window.instance.run(() => { TextInput._performAction(this._client, response.inputAction.Value); });
                    }

                    if (_validateCharacter(response.input))
                    {
                        this._value = this._value.insert(new string(response.input, 1));
                    }
                }
                else if (currentEvent.keyCode == KeyCode.Backspace)
                {
                    if (this._value.selection.isValid)
                    {
                        this._value = this._value.deleteSelection(true);
                    }
                }
                else if (currentEvent.character != '\0')
                {
                    this._value = this._value.clearCompose();
                    char ch = currentEvent.character;
                    if (ch == '\r' || ch == 3)
                    {
                        ch = '\n';
                    }

                    if (ch == '\n')
                    {
                        Window.instance.run(() => { TextInput._performAction(this._client, TextInputAction.newline); });
                    }

                    if (_validateCharacter(ch))
                    {
                        this._value = this._value.insert(new string(ch, 1));
                    }
                }
                else if (!string.IsNullOrEmpty(Input.compositionString))
                {
                    this.isIMEInput = true;
                    this._value     = this._value.compose(Input.compositionString);
                }

                currentEvent.Use();
            }

            if (this._value != oldValue)
            {
                if (this.isIMEInput)
                {
                    var isIMEInput = this.isIMEInput;
                    Window.instance.run(() => { TextInput._updateEditingState(this._client, this._value, isIMEInput); });
                    this.isIMEInput = false;
                }
                else
                {
                    Window.instance.run(() => { TextInput._updateEditingState(this._client, this._value); });
                }
            }
        }