Example #1
0
        /// <summary>
        /// キー設定に基づくイベント処理
        /// </summary>
        void ProcessKeyEvent()
        {
            KeyEventData eventData;
            KeyData      keyData;
            float        unscaledTime = Time.unscaledTime;

            for (int i = 1; i < _keyMap.Count; i++)
            {
                if (!_keyMap.TryGetKeyDataAtIndex(i, out keyData))
                {
                    continue;
                }

                if (!keyData.use)
                {
                    continue;
                }

                _keyState.TryGetEventData(keyData.id, out eventData);
                eventData.inputState = CheckKeyState(keyData.code);

                // 押下
                if (eventData.PressedThisFrame())
                {
                    eventData.holding   = false;
                    eventData.pressTime = unscaledTime;

                    ExecuteEvents.Execute <IKeyDownHandler>(
                        base.eventSystem.currentSelectedGameObject, eventData,
                        ExecuteFunctions.KeyDownHandler);

                    eventData.useHoldThreshold = true;
                }

                // 離上
                if (eventData.ReleasedThisFrame())
                {
                    if (eventData.holding)
                    {
                        ExecuteEvents.Execute <IKeyEndHoldHandler>(
                            base.eventSystem.currentSelectedGameObject, eventData,
                            ExecuteFunctions.KeyEndHoldHandler);

                        eventData.holding  = false;
                        eventData.holdTime = 0;
                    }

                    eventData.useHoldThreshold = false;

                    ExecuteEvents.Execute <IKeyUpHandler>(
                        base.eventSystem.currentSelectedGameObject, eventData,
                        ExecuteFunctions.KeyUpHandler);
                }

                // 押下中
                if (eventData.holding)
                {
                    eventData.holdTime = unscaledTime - eventData.pressTime;

                    // 押下中イベント発行(移行後)
                    ExecuteEvents.Execute <IKeyHoldHandler>(
                        base.eventSystem.currentSelectedGameObject, eventData,
                        ExecuteFunctions.KeyHoldHandler);
                }
                // 押下中に移行する前
                else if (eventData.useHoldThreshold)
                {
                    float delta = unscaledTime - eventData.pressTime;
                    if (delta > _holdDelay)
                    {
                        // 押下中イベント発行(移行する直前)
                        ExecuteEvents.Execute <IKeyBeginHoldHandler>(
                            base.eventSystem.currentSelectedGameObject, eventData,
                            ExecuteFunctions.KeyBeginHoldHandler);

                        eventData.holding          = true;
                        eventData.useHoldThreshold = false;
                        eventData.holdTime         = 0;
                    }
                }
            }
        }