Пример #1
0
        /// <summary>
        /// Listen for touch events (finger down -> move -> release)
        /// </summary>
        /// <param name="fingerId">Zero based index for which finger id to bind to</param>
        /// <param name="onTouchStart">(Optional) handler function for touch begin event</param>
        /// <param name="onTouchMove">(Optional) handler function for touch move event</param>
        /// <param name="onTouchEnd">(Optional) handler function for touch end event</param>
        /// <param name="pointHistoryLength">The number of seconds history that should be kept</param>
        /// <returns>The InputHandler object. Pass it to RemoveListener to remove the listener.</returns>
        public static InputHandler AddListenerTouch(int fingerId, InputHandlerDelegate onTouchStart, InputHandlerDelegate onTouchMove, InputHandlerDelegate onTouchEnd, float pointHistoryLength = 5.0f)
        {
            InputHandlerTouch ih = new InputHandlerTouch(fingerId, onTouchStart, onTouchMove, onTouchEnd, pointHistoryLength);

            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.touchCount == 0 || !Input.simulateMouseWithTouches)
            {
                for (int i = 0; i < 3; i++)
                {
                    if (Input.GetMouseButtonDown(i))
                    {
                        InputHandlerMouseDrag ih = new InputHandlerMouseDrag(i, OnStart, OnChange, OnEnd, pointHistoryLength);
                        inputHandler.Add(ih);
                    }
                }
            }

            if (Input.touchCount > 0)
            {
                for (int i = 0; i < Input.touchCount; i++)
                {
                    if (Input.touches[i].phase == TouchPhase.Began)
                    {
                        InputHandlerTouch ih = new InputHandlerTouch(Input.touches[i].fingerId, OnStart, OnChange, OnEnd, pointHistoryLength);
                        inputHandler.Add(ih);
                    }
                }
            }
        }