Esempio n. 1
0
        protected virtual bool HandleEvent(CEvent evt)
        {
            if (evt.isMouse)
            {
                if (IsMouseEventsEnabled && ContainsPoint(evt.mousePosition.x, evt.mousePosition.y))
                {
                    Vector2 oldPos = evt.mousePosition;
                    evt.mousePosition = new Vector2(oldPos.x - X, oldPos.y - Y);
                    bool result = HandleMouseEvent(evt);
                    evt.mousePosition = oldPos;

                    return(result);
                }

                return(false);
            }

            if (evt.isKey && IsFocused && IsKeyEventsEnabled)
            {
                if (HandleKeyEvent(evt))
                {
                    evt.Use();
                    return(true); // don't let other controls use it
                }

                return(false);
            }

            return(false);
        }
Esempio n. 2
0
        private static void HandleOnSceneFunc(SceneView sceneView)
        {
            try
            {
                CEvent evt = CEvent.current;
                if (evt != null && evt.isKey)
                {
                    int keyIndex = (int)evt.keyCode;
                    if (keyIndex < 0 || keyIndex >= s_pressedKeyCodeFlags.Length)
                    {
                        return;
                    }

                    if (evt.type == EventType.KeyDown)
                    {
                        if (!s_pressedKeyCodeFlags[keyIndex])
                        {
                            s_pressedKeyCodeFlags[keyIndex] = true;
                            if (keyDownHandler != null && keyDownHandler(evt.keyCode, GetModifiers(evt)))
                            {
                                evt.Use();
                            }
                        }
                    }
                    else if (evt.type == EventType.KeyUp)
                    {
                        if (s_pressedKeyCodeFlags[keyIndex])
                        {
                            s_pressedKeyCodeFlags[keyIndex] = false;
                            if (keyUpHandler != null && keyUpHandler(evt.keyCode, GetModifiers(evt)))
                            {
                                evt.Use();
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogError("Exception while handling scene keys: " + e.Message);
            }
        }