예제 #1
0
        protected virtual void Handle(nvEvent.RegisterInputType gameEvent)
        {
            InputType.KeyState onKeyState = InputType.KeyState.None;
            if (gameEvent.onPress)
            {
                onKeyState |= InputType.KeyState.OnPress;
            }
            if (gameEvent.onHold)
            {
                onKeyState |= InputType.KeyState.OnHold;
            }
            if (gameEvent.onRelease)
            {
                onKeyState |= InputType.KeyState.OnRelease;
            }

            if (onKeyState == InputType.KeyState.None)
            {
                return;
            }

            InputType.TouchableObject touchable = null;
            if (gameEvent.touchableObject != null)
            {
                touchable = new InputType.TouchableObject(gameEvent.touchableObject, gameEvent.touchableObjectCamera);
            }

            if (gameEvent.gameAction)
            {
                Register(gameInputActions, gameEvent.key, gameEvent.action, onKeyState, touchable);
            }
            if (gameEvent.systemAction)
            {
                Register(systemInputActions, gameEvent.key, gameEvent.action, onKeyState, touchable);
            }
            if (gameEvent.debugAction)
            {
                Register(debugInputActions, gameEvent.key, gameEvent.action, onKeyState, touchable);
            }
        }
예제 #2
0
        /// <summary>
        /// Register a key to a callback. Example:
        /// GameInput.Register( KeyCode.Mouse0, TryPick );
        /// </summary>
        public virtual void Register(List <InputType> inputActions, KeyCode key, UnityAction action, InputType.KeyState keystate = InputType.KeyState.OnPress, InputType.TouchableObject optionalTouchable = null)
        {
            //unregister first to prevent double-adding of event handlers

            Unregister(inputActions, key, action, keystate);
            for (int i = 0; i < inputActions.Count; ++i)
            {
                if (inputActions[i].key == key)
                {
                    foreach (var pair in inputActions[i].keyEvents)
                    {
                        if ((pair.onKeyState & keystate) != InputType.KeyState.None)
                        {
                            pair.events.RemoveListener(action);
                            pair.events.AddListener(action);
                            return;
                        }
                    }

                    //if we reach this point, the pair doesn't exist
                    InputType.KeyEvent newPair = new InputType.KeyEvent();
                    newPair.onKeyState = keystate;
                    newPair.events.AddListener(action);
                    inputActions[i].keyEvents.Add(newPair);
                    break;
                }
            }

            //if we reach this point, the action doesn't exist
            InputType newAction = new InputType();

            InputType.KeyEvent newPairForNewAction = new InputType.KeyEvent();
            newPairForNewAction.onKeyState = keystate;
            newPairForNewAction.events     = new UnityEvent();
            newPairForNewAction.events.AddListener(action);
            newAction.keyEvents.Add(newPairForNewAction);
            newAction.key = key;
            newAction.optionalTouchable = optionalTouchable;
            inputActions.Add(newAction);
        }