void TryCreateOneFingerGestureOnTouchBegan(Func <CommonTouch, T> createGestureFunction) { foreach (var touch in GestureTouchesUtility.touches) { if (touch.isPhaseBegan && !GestureTouchesUtility.IsFingerIdRetained(touch.fingerId) && !GestureTouchesUtility.IsTouchOffScreenEdge(touch)) { var gesture = createGestureFunction(touch); AddGesture(gesture); } } }
/// <summary> /// Helper function for creating one finger gestures when a touch begins. /// </summary> /// <param name="createGestureFunction">Function to be executed to create the gesture.</param> protected internal void TryCreateOneFingerGestureOnTouchBegan( Func <Touch, T> createGestureFunction) { for (int i = 0; i < GestureTouchesUtility.Touches.Length; i++) { Touch touch = GestureTouchesUtility.Touches[i]; if (touch.phase == TouchPhase.Began && !GestureTouchesUtility.IsFingerIdRetained(touch.fingerId) && !GestureTouchesUtility.IsTouchOffScreenEdge(touch)) { T gesture = createGestureFunction(touch); gesture.onStart += OnStart; gesture.onFinished += OnFinished; m_Gestures.Add(gesture); } } }
void TryCreateGestureTwoFingerGestureOnTouchBeganForTouchIndex( int touchIndex, Func <Touch, Touch, T> createGestureFunction) { if (GestureTouchesUtility.Touches[touchIndex].phase != TouchPhase.Began) { return; } var touch = GestureTouchesUtility.Touches[touchIndex]; if (GestureTouchesUtility.IsFingerIdRetained(touch.fingerId) || GestureTouchesUtility.IsTouchOffScreenEdge(touch)) { return; } for (var i = 0; i < GestureTouchesUtility.Touches.Length; i++) { if (i == touchIndex) { continue; } // Prevents the same two touches from creating two gestures if both touches began on // the same frame. if (i < touchIndex && GestureTouchesUtility.Touches[i].phase == TouchPhase.Began) { continue; } var otherTouch = GestureTouchesUtility.Touches[i]; if (GestureTouchesUtility.IsFingerIdRetained(otherTouch.fingerId) || GestureTouchesUtility.IsTouchOffScreenEdge(otherTouch)) { continue; } var gesture = createGestureFunction(touch, otherTouch); gesture.onStart += OnStart; gesture.onFinished += OnFinished; m_Gestures.Add(gesture); } }
void TryCreateGestureTwoFingerGestureOnTouchBeganForTouchIndex( int touchIndex, IReadOnlyList <CommonTouch> touches, Func <CommonTouch, CommonTouch, T> createGestureFunction) { var touch = touches[touchIndex]; if (!touch.isPhaseBegan || GestureTouchesUtility.IsFingerIdRetained(touch.fingerId) || GestureTouchesUtility.IsTouchOffScreenEdge(touch)) { return; } for (var i = 0; i < touches.Count; i++) { if (i == touchIndex) { continue; } var otherTouch = touches[i]; // Prevents the same two touches from creating two gestures if both touches began on // the same frame. if (i < touchIndex && otherTouch.isPhaseBegan) { continue; } if (GestureTouchesUtility.IsFingerIdRetained(otherTouch.fingerId) || GestureTouchesUtility.IsTouchOffScreenEdge(otherTouch)) { continue; } var gesture = createGestureFunction(touch, otherTouch); AddGesture(gesture); } }