コード例 #1
0
 /// <summary>
 /// Notifies Renderer that a key was released.
 /// </summary>
 /// <param name="key">Key identifier.</param>
 public void KeyUp(Noesis.Key key)
 {
     if (_uiView != null)
     {
         _uiView.KeyUp(key);
     }
 }
 /// <summary>
 /// Notifies Renderer that a key was released.
 /// </summary>
 /// <param name="key">Key identifier.</param>
 public void KeyUp(Noesis.Key key)
 {
     if (_uiRenderer != null)
     {
         _uiRenderer.KeyUp(key);
     }
 }
コード例 #3
0
    /// <summary>
    /// Notifies Renderer that a key was released.
    /// </summary>
    /// <param name="key">Key identifier.</param>
    public bool KeyUp(Noesis.Key key)
    {
        if (_uiView != null)
        {
            return(_uiView.KeyUp(key));
        }

        return(false);
    }
コード例 #4
0
    private void ProcessEvent(UnityEngine.Event ev, bool enableKeyboard, bool enableMouse, bool emulateTouch)
    {
        // Process keyboard modifiers
        if (enableKeyboard)
        {
            EventModifiers delta = ev.modifiers ^ _modifiers;
            if (delta > 0)
            {
                _modifiers = ev.modifiers;

                ProcessModifierKey(ev.modifiers, delta, EventModifiers.Shift, Key.LeftShift);
                ProcessModifierKey(ev.modifiers, delta, EventModifiers.Control, Key.LeftCtrl);
                ProcessModifierKey(ev.modifiers, delta, EventModifiers.Command, Key.LeftCtrl);
                ProcessModifierKey(ev.modifiers, delta, EventModifiers.Alt, Key.LeftAlt);
            }
        }

        switch (ev.type)
        {
        case UnityEngine.EventType.MouseDown:
        {
            if (enableMouse)
            {
                UnityEngine.Vector2 mouse = ProjectPointer(ev.mousePosition.x, UnityEngine.Screen.height - ev.mousePosition.y);

                if (HitTest(mouse.x, mouse.y))
                {
                    ev.Use();
                }

                if (emulateTouch)
                {
                    _uiView.TouchDown((int)mouse.x, (int)mouse.y, 0);
                    _touchEmulated = true;
                }
                else
                {
                    // Ignore events generated by Unity to simulate a mouse down when a touch event occurs
                    bool mouseEmulated = Input.simulateMouseWithTouches && Input.touchCount > 0;
                    if (!mouseEmulated)
                    {
                        if (ev.clickCount == 1)
                        {
                            _uiView.MouseButtonDown((int)mouse.x, (int)mouse.y, (Noesis.MouseButton)ev.button);
                        }
                        else
                        {
                            _uiView.MouseDoubleClick((int)mouse.x, (int)mouse.y, (Noesis.MouseButton)ev.button);
                        }
                    }
                }
            }
            break;
        }

        case UnityEngine.EventType.MouseUp:
        {
            if (enableMouse)
            {
                UnityEngine.Vector2 mouse = ProjectPointer(ev.mousePosition.x, UnityEngine.Screen.height - ev.mousePosition.y);

                if (HitTest(mouse.x, mouse.y))
                {
                    ev.Use();
                }

                if (emulateTouch && _touchEmulated)
                {
                    _uiView.TouchUp((int)mouse.x, (int)mouse.y, 0);
                    _touchEmulated = false;
                }
                else
                {
                    // Ignore events generated by Unity to simulate a mouse up when a touch event occurs
                    bool mouseEmulated = Input.simulateMouseWithTouches && Input.touchCount > 0;
                    if (!mouseEmulated)
                    {
                        _uiView.MouseButtonUp((int)mouse.x, (int)mouse.y, (Noesis.MouseButton)ev.button);
                    }
                }
            }
            break;
        }

        case UnityEngine.EventType.KeyDown:
        {
            if (enableKeyboard)
            {
                // Don't process key when IME composition is being used
                if (ev.keyCode != KeyCode.None && NoesisUnity.IME.compositionString == "")
                {
                    Noesis.Key noesisKeyCode = NoesisKeyCodes.Convert(ev.keyCode);
                    if (noesisKeyCode != Noesis.Key.None)
                    {
#if !UNITY_EDITOR && UNITY_STANDALONE_OSX
                        // In OSX Standalone, CMD + key always sends two KeyDown events for the key.
                        // This seems to be a bug in Unity.
                        if (!ev.command || lastFrame != Time.frameCount || lastKeyDown != noesisKeyCode)
                        {
                            lastFrame   = Time.frameCount;
                            lastKeyDown = noesisKeyCode;
#endif
                        _uiView.KeyDown(noesisKeyCode);
#if !UNITY_EDITOR && UNITY_STANDALONE_OSX
                    }
#endif
                    }
                }

                if (ev.character != 0)
                {
                    // Filter out character events when CTRL is down
                    bool isControl = (_modifiers & EventModifiers.Control) != 0 || (_modifiers & EventModifiers.Command) != 0;
                    bool isAlt     = (_modifiers & EventModifiers.Alt) != 0;
                    bool filter    = isControl && !isAlt;

                    if (!filter)
                    {
#if !UNITY_EDITOR && UNITY_STANDALONE_LINUX
                        // It seems that linux is sending KeySyms instead of Unicode points
                        // https://github.com/substack/node-keysym/blob/master/data/keysyms.txt
                        ev.character = NoesisKeyCodes.KeySymToUnicode(ev.character);
#endif
                        _uiView.Char((uint)ev.character);
                    }
                }
            }
            break;
        }

        case UnityEngine.EventType.KeyUp:
        {
            // Don't process key when IME composition is being used
            if (enableKeyboard)
            {
                if (ev.keyCode != KeyCode.None && NoesisUnity.IME.compositionString == "")
                {
                    Noesis.Key noesisKeyCode = NoesisKeyCodes.Convert(ev.keyCode);
                    if (noesisKeyCode != Noesis.Key.None)
                    {
                        _uiView.KeyUp(noesisKeyCode);
                    }
                }
            }
            break;
        }
        }
    }
コード例 #5
0
 private void ProcessModifierKey(EventModifiers modifiers, EventModifiers delta, EventModifiers flag, Noesis.Key key)
 {
     if ((delta & flag) > 0)
     {
         if ((modifiers & flag) > 0)
         {
             _uiView.KeyDown(key);
         }
         else
         {
             _uiView.KeyUp(key);
         }
     }
 }