/// <summary> /// Listen for mouse drag events (mouse down -> move -> release) /// </summary> /// <param name="mouseButton">Which mouse button are we binding to</param> /// <param name="onMouseDown">(Optional) handler for mouse down event</param> /// <param name="onMouseMove">(Optional) handler for mouse move event</param> /// <param name="onMouseUp">(Optional) handler for mouse up 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 AddListenerMouseDrag(int mouseButton, InputHandlerDelegate onMouseDown, InputHandlerDelegate onMouseMove, InputHandlerDelegate onMouseUp, float pointHistoryLength = 5.0f) { InputHandlerMouseDrag ih = new InputHandlerMouseDrag(mouseButton, onMouseDown, onMouseMove, onMouseUp, pointHistoryLength); instance.inputHandler.Add(ih); return(ih); }
/// <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); } } } }