예제 #1
0
        /// <summary>
        /// Listen for a specific key to be pressed or released
        /// </summary>
        /// <param name="key">KeyCode to listen for</param>
        /// <param name="onKeyDown">(Optional) handler function for key down event</param>
        /// <param name="onKeyUp">(Optional) handler function for key up event</param>
        /// <returns>The InputHandler object. Pass it to RemoveListener to remove the listener.</returns>
        public static InputHandler AddListenerKey(KeyCode key, InputHandlerDelegate onKeyDown, InputHandlerDelegate onKeyUp)
        {
            InputHandlerKey ih = new InputHandlerKey(key, onKeyDown, onKeyUp);

            instance.inputHandler.Add(ih);
            return(ih);
        }
예제 #2
0
        /// <summary>
        /// Run once per frame (this is handled by the InputEvent class)
        /// </summary>
        public override void Update()
        {
            for (int i = inputHandler.Count - 1; i >= 0; i--)
            {
                if (inputHandler[i].status == EventStatus.End)
                {
                    inputHandler.RemoveAt(i);
                }
                else
                {
                    inputHandler[i].Update();
                }
            }

            if (Input.anyKey)
            {
                for (int i = allKeys.Length - 1; i >= 0; i--)
                {
                    if (Input.GetKeyDown(allKeys[i]))
                    {
                        InputHandlerKey ih = new InputHandlerKey(allKeys[i], OnStart, OnEnd);
                        inputHandler.Add(ih);
                    }
                }
            }
        }