Beispiel #1
0
    void OnKeyEvent(int id)
    {
        if (JavaInterface.getKey(id) == true)
        {
            KeyEventNew[id] = true;
            //检查按键是否被持续按住
            if (hold[id] != 0)
            {
                hold[id] += 1;
                OnKeyHoldTimerEvent(id);
                //if (hold[id] > 10 && hold[id] % 3 == 0) OnKeyHoldEvent(id);
                if (hold[id] > 3)
                {
                    OnKeyHoldEvent(id);
                }
            }
        }
        else
        {
            KeyEventNew[id] = false;
        }
        //按键被按下时触发事件
        if ((KeyEventNew[id] == true) && (KeyEventOld[id] == false))
        {
            //Debug.Log("key " + id + " is click!!!");
            OnKeyDownEvent();
            OnKeyDownEvent(id);
            switch (id)
            {
            case 0: OnKeyDown0Event(); break;

            case 1: OnKeyDown1Event(); break;

            case 2: OnKeyDown2Event(); break;

            case 3: OnKeyDown3Event(); break;

            default: break;
            }
        }
        //按键被释放时触发事件
        if ((KeyEventNew[id] == false) && (KeyEventOld[id] == true))
        {
            OnKeyUpEvent();
            OnKeyUpEvent(id);
            switch (id)
            {
            case 0: OnKeyUp0Event(); break;

            case 1: OnKeyUp1Event(); break;

            case 2: OnKeyUp2Event(); break;

            case 3: OnKeyUp3Event(); break;

            default: break;
            }
        }
        KeyEventOld[id] = KeyEventNew[id];
    }