Exemplo n.º 1
0
        private void ChangeState(KeyboardState state, float?pos = null)
        {
            if (CurrentState == state)
            {
                return;
            }

            NormalKeys.SetPage(0, NextSpecialPage);

            Vector3 fromPosition = Vector3.zero;
            Vector3 toPosition   = Vector3.zero;
            Action  callback     = null;

            _isEnabled = false;

            bool inverted = ((int)CameraRef.transform.rotation.eulerAngles.z) == 180;

            switch (state)
            {
            case KeyboardState.Closed:
            default:
                fromPosition = transform.position;
                toPosition   = transform.position + transform.up * -5;
                callback     = () =>
                {
                    _isEnabled = true;
                    if (Display.isActiveAndEnabled)
                    {
                        Display.ResetDisplayPosition();
                        Text = "";
                    }
                };
                break;

            case KeyboardState.Open:
                Show();
                fromPosition = CameraRef.ViewportToWorldPoint(new Vector3(0.5f, inverted ? 1 : 0, 7.5f)) + transform.up * -5;
                toPosition   = CameraRef.ViewportToWorldPoint(new Vector3(0.5f, inverted ? 1 : 0, 7.5f));
                if (Display.isActiveAndEnabled)
                {
                    Display.ReturnText();
                }
                callback = () => { _isEnabled = true; };
                break;

            case KeyboardState.Text:
                Show();
                fromPosition = transform.position;
                toPosition   = CameraRef.ViewportToWorldPoint(new Vector3(0.5f, inverted ? 1.29f : -0.29f, 7.5f));
                if (Display.isActiveAndEnabled)
                {
                    Display.CenterText();
                }
                break;

            case KeyboardState.Custom:
                Show();
                if (Display.isActiveAndEnabled)
                {
                    Display.ReturnText();
                }
                callback = () => { _isEnabled = true; };
                if (CurrentState == KeyboardState.Open)
                {
                    fromPosition = transform.position;
                    toPosition   = transform.position;
                    toPosition.x = pos.GetValueOrDefault();
                }
                else
                {
                    fromPosition   = CameraRef.ViewportToWorldPoint(new Vector3(0.5f, inverted ? 1 : 0, 7.5f)) + transform.up * -5;
                    fromPosition.x = pos.GetValueOrDefault();
                    toPosition     = CameraRef.ViewportToWorldPoint(new Vector3(0.5f, inverted ? 1 : 0, 7.5f));
                    toPosition.x   = pos.GetValueOrDefault();
                }
                state = KeyboardState.Open;
                break;
            }

            CurrentState = state;

            _tween.Stop();
            _tween.SetPosition(fromPosition, toPosition);
            _tween.Play(callback);

            EnableButtons();
        }