Пример #1
0
        private void OnGUI()
        {
            if (controller == null)
            {
                return;
            }

            if (paused == false)
            {
                // Mouse.
                controller.ProccessMouse(UE.Input.mousePosition.x, UE.Screen.height - UE.Input.mousePosition.y);

                // Keys.
                var currentEvent = UE.Event.current;
                if (currentEvent.keyCode != UE.KeyCode.None)
                {
                    var keyData = UnityKeyTranslator.ToKeyData(currentEvent.modifiers, currentEvent.keyCode);
                    var keyArgs = new KeyEventArgs(keyData);
                    keyArgs.uwfKeyCode   = currentEvent.keyCode;
                    keyArgs.uwfModifiers = currentEvent.modifiers;
                    if ((keyArgs.uwfModifiers & UE.EventModifiers.FunctionKey) != 0)
                    {
                        keyArgs.uwfModifiers &= ~UE.EventModifiers.FunctionKey;
                    }

                    var keyEventType = (Application.KeyEvents)(currentEvent.type - 3);
                    if (keyEventType == Application.KeyEvents.Down || keyEventType == Application.KeyEvents.Up)
                    {
                        controller.ProccessKeys(keyArgs, keyEventType);
                    }
                }
            }

            controller.Redraw();
        }
Пример #2
0
        private void OnGUI()
        {
            if (controller == null)
            {
                return;
            }

            if (paused == false)
            {
                var currentEvent = UE.Event.current;

                var currentButton       = currentEvent.button;
                var currentClicks       = currentEvent.clickCount;
                var currentDelta        = currentEvent.delta.y;
                var currentKeyCode      = currentEvent.keyCode;
                var currentKeyModifiers = currentEvent.modifiers;
                var currentType         = currentEvent.type;

                // Prepare mouse.
                var mouseButton     = MouseButtons.None;
                var mouseEvent      = Application.MouseEvents.None;
                var mouseWheelDelta = 0f;

                switch (currentType)
                {
                case UE.EventType.MouseDown:
                    switch (currentButton)
                    {
                    case 0:
                        mouseButton = MouseButtons.Left;
                        mouseEvent  = Application.MouseEvents.Down;
                        if (currentClicks > 1)
                        {
                            mouseEvent = Application.MouseEvents.DoubleClick;
                        }
                        break;

                    case 1:
                        mouseButton = MouseButtons.Right;
                        mouseEvent  = Application.MouseEvents.Down;
                        break;

                    case 2:
                        mouseButton = MouseButtons.Middle;
                        mouseEvent  = Application.MouseEvents.Down;
                        break;
                    }

                    break;

                case UE.EventType.MouseUp:
                    switch (currentButton)
                    {
                    case 0:
                        mouseButton = MouseButtons.Left;
                        mouseEvent  = Application.MouseEvents.Up;
                        break;

                    case 1:
                        mouseButton = MouseButtons.Right;
                        mouseEvent  = Application.MouseEvents.Up;
                        break;

                    case 2:
                        mouseButton = MouseButtons.Middle;
                        mouseEvent  = Application.MouseEvents.Up;
                        break;
                    }

                    break;

                case UE.EventType.ScrollWheel:
                    mouseEvent      = Application.MouseEvents.Wheel;
                    mouseWheelDelta = currentDelta;
                    break;
                }

                // Mouse.
                var mouseX = UE.Input.mousePosition.x;
                var mouseY = UE.Screen.height - UE.Input.mousePosition.y;

                controller.ProccessMouse(mouseEvent, mouseX, mouseY, mouseButton, currentClicks, (int)mouseWheelDelta);

                // Keys.

                // Manualy set event for 'shift' key.
                if (shiftPressed && currentKeyCode == UE.KeyCode.None)
                {
                    if (shiftWait <= 0)
                    {
                        currentKeyCode = UE.KeyCode.LeftShift;
                        currentType    = UE.EventType.KeyDown;

                        shiftWait = .2f;
                    }
                    else
                    {
                        shiftWait -= swfHelper.GetDeltaTime();
                    }
                }

                // Try release 'shift'.
                // Fix: it's presses additional time when using Shift + any key.

                /*var prevShift = shiftPressed;
                 * shiftPressed = currentEvent.shift;
                 *
                 * if (prevShift && shiftPressed == false && currentKeyCode == UE.KeyCode.LeftShift)
                 *  currentEventType = UE.EventType.KeyUp;*/

                // Proccess.
                if (currentKeyCode != UE.KeyCode.None)
                {
                    var keyData = UnityKeyTranslator.ToKeyData(currentKeyModifiers, currentKeyCode);
                    var keyArgs = new KeyEventArgs(keyData);
                    keyArgs.uwfKeyCode   = currentKeyCode;
                    keyArgs.uwfModifiers = currentKeyModifiers;
                    if ((keyArgs.uwfModifiers & UE.EventModifiers.FunctionKey) != 0)
                    {
                        keyArgs.uwfModifiers &= ~UE.EventModifiers.FunctionKey;
                    }

                    var keyEventType = (Application.KeyEvents)(currentType - 3);
                    if (keyEventType == Application.KeyEvents.Down || keyEventType == Application.KeyEvents.Up)
                    {
                        controller.ProccessKeys(keyArgs, keyEventType);
                    }
                }
            }

            // Scale if needed.
            var scaleX = SWF.Application.ScaleX;
            var scaleY = SWF.Application.ScaleY;

            if (scaleX != 1f || scaleY != 1f)
            {
                UnityEngine.GUI.matrix = UnityEngine.Matrix4x4.TRS(
                    UE.Vector3.zero,
                    UE.Quaternion.AngleAxis(0, UE.Vector3.up),
                    new UE.Vector3(scaleX, scaleY, 1));
            }

            controller.Redraw();
        }
Пример #3
0
        private void UpdateKeys()
        {
            var currentEvent        = UE.Event.current;
            var currentKeyCode      = currentEvent.keyCode;
            var currentKeyModifiers = currentEvent.modifiers;
            var currentType         = currentEvent.type;

            // Shift key is not have a KeyDown and KeyUp events, so we need to update them manually.
            // There is also problem that if any key besides modifier keys were pressed along with Shift one
            // Unity will alternately send KeyDown events with pressed key and Shift key.

            // Update shift press.
            if (shiftPressed)
            {
                if (shiftDownDelayTimer <= 0)
                {
                    if (shiftDownTimer <= 0)
                    {
                        currentKeyModifiers = UE.EventModifiers.Shift;

                        if (currentKeyCode == UE.KeyCode.None)
                        {
                            currentKeyCode = UE.KeyCode.LeftShift;
                            currentType    = UE.EventType.KeyDown;
                        }

                        shiftDownTimer = ShiftDownTime;
                    }
                    else
                    {
                        shiftDownTimer -= swfHelper.GetDeltaTime();
                    }
                }
                else
                {
                    shiftDownDelayTimer -= swfHelper.GetDeltaTime();
                }
            }

            var prevShift = shiftPressed;

            shiftPressed = currentEvent.shift;

            // Start shift key.
            if (!prevShift && shiftPressed)
            {
                currentKeyModifiers = UE.EventModifiers.Shift;
                currentKeyCode      = UE.KeyCode.LeftShift;
                currentType         = UE.EventType.KeyDown;
                shiftDownDelayTimer = ShiftDownDelayTime;
            }

            // Release shift key.
            if (prevShift && !shiftPressed)
            {
                currentKeyModifiers = UE.EventModifiers.Shift;
                currentKeyCode      = UE.KeyCode.LeftShift;
                currentType         = UE.EventType.KeyUp;
                shiftDownTimer      = 0;
            }

            if (currentKeyCode == UE.KeyCode.None)
            {
                return;
            }
            if (currentType != UE.EventType.KeyDown && currentType != UE.EventType.KeyUp)
            {
                return;
            }

            var keyData = UnityKeyTranslator.ToKeyData(currentKeyModifiers, currentKeyCode);
            var keyArgs = new KeyEventArgs(keyData);

            var keyEventType = (Application.KeyEvents)(currentType - 3);

            if (keyEventType == Application.KeyEvents.Down || keyEventType == Application.KeyEvents.Up)
            {
                controller.ProcessKeys(keyArgs, keyEventType);
            }
        }
Пример #4
0
        private void OnGUI()
        {
            if (controller == null)
            {
                return;
            }

            if (paused == false)
            {
                // Mouse.
                controller.ProccessMouse(UE.Input.mousePosition.x, UE.Screen.height - UE.Input.mousePosition.y);

                // Keys.
                var currentEvent        = UE.Event.current;
                var currentEventType    = currentEvent.type;
                var currentKeyCode      = currentEvent.keyCode;
                var currentKeyModifiers = currentEvent.modifiers;

                // Manualy set event for 'shift' key.
                if (shiftPressed && currentKeyCode == UE.KeyCode.None)
                {
                    if (shiftWait <= 0)
                    {
                        currentKeyCode   = UE.KeyCode.LeftShift;
                        currentEventType = UE.EventType.KeyDown;

                        shiftWait = .2f;
                    }
                    else
                    {
                        shiftWait -= swfHelper.GetDeltaTime();
                    }
                }

                // Try release 'shift'.
                // Fix: it's presses additional time when using Shift + any key.

                /*var prevShift = shiftPressed;
                 * shiftPressed = currentEvent.shift;
                 *
                 * if (prevShift && shiftPressed == false && currentKeyCode == UE.KeyCode.LeftShift)
                 *  currentEventType = UE.EventType.KeyUp;*/

                // Proccess.
                if (currentKeyCode != UE.KeyCode.None)
                {
                    var keyData = UnityKeyTranslator.ToKeyData(currentKeyModifiers, currentKeyCode);
                    var keyArgs = new KeyEventArgs(keyData);
                    keyArgs.uwfKeyCode   = currentKeyCode;
                    keyArgs.uwfModifiers = currentKeyModifiers;
                    if ((keyArgs.uwfModifiers & UE.EventModifiers.FunctionKey) != 0)
                    {
                        keyArgs.uwfModifiers &= ~UE.EventModifiers.FunctionKey;
                    }

                    var keyEventType = (Application.KeyEvents)(currentEventType - 3);
                    if (keyEventType == Application.KeyEvents.Down || keyEventType == Application.KeyEvents.Up)
                    {
                        controller.ProccessKeys(keyArgs, keyEventType);
                    }
                }
            }

            controller.Redraw();
        }