//----------------------------------------------------------------------- // // // Copyright 2018 Google Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // //----------------------------------------------------------------------- // Modifications copyright © 2020 Unity Technologies ApS #if AR_FOUNDATION_PRESENT || PACKAGE_DOCS_GENERATION using System; using UnityEngine; namespace UnityEngine.XR.Interaction.Toolkit.AR { /// /// Gesture Recognizer for when the user performs a drag motion on the touch screen. /// /// public class DragGestureRecognizer : GestureRecognizer { /// /// Distance in inches a user's touch can drift from the start position /// before the drag gesture is interpreted as started. /// public float slopInches { get; set; } = 0.1f; // Preallocate delegates to avoid GC Alloc that would happen in TryCreateGestures readonly Func m_CreateEnhancedGesture; readonly Action m_ReinitializeEnhancedGesture; #if !XRI_LEGACY_INPUT_DISABLED readonly Func m_CreateGestureFunction; readonly Action m_ReinitializeGestureFunction; #endif /// /// Initializes and returns an instance of . /// public DragGestureRecognizer() { m_CreateEnhancedGesture = CreateEnhancedGesture; m_ReinitializeEnhancedGesture = ReinitializeEnhancedGesture; #if !XRI_LEGACY_INPUT_DISABLED m_CreateGestureFunction = CreateGesture; m_ReinitializeGestureFunction = ReinitializeGesture; #endif } #if !XRI_LEGACY_INPUT_DISABLED /// /// Creates a Drag gesture with the given touch. /// /// The touch that started this gesture. /// Returns the created Drag gesture. DragGesture CreateGesture(Touch touch) { #pragma warning disable CS0618 // Type or member is obsolete -- For backwards compatibility with existing projects return new DragGesture(this, touch); #pragma warning restore CS0618 } static void ReinitializeGesture(DragGesture gesture, Touch touch) { #pragma warning disable CS0618 // Type or member is obsolete -- For backwards compatibility with existing projects gesture.Reinitialize(touch); #pragma warning restore CS0618 } #endif /// /// Creates a Drag gesture with the given touch. /// /// The touch that started this gesture. /// Returns the created Drag gesture. DragGesture CreateEnhancedGesture(InputSystem.EnhancedTouch.Touch touch) { return new DragGesture(this, touch); } static void ReinitializeEnhancedGesture(DragGesture gesture, InputSystem.EnhancedTouch.Touch touch) { gesture.Reinitialize(touch); } /// protected override void TryCreateGestures() { if (GestureTouchesUtility.touchInputSource == GestureTouchesUtility.TouchInputSource.Enhanced) TryCreateOneFingerGestureOnTouchBegan(m_CreateEnhancedGesture, m_ReinitializeEnhancedGesture); #if !XRI_LEGACY_INPUT_DISABLED else #pragma warning disable CS0618 // Type or member is obsolete -- For backwards compatibility with existing projects TryCreateOneFingerGestureOnTouchBegan(m_CreateGestureFunction, m_ReinitializeGestureFunction); #pragma warning restore CS0618 #endif } } } #endif