//-----------------------------------------------------------------------
//
//
// 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 two finger drag motion on the touch screen.
///
///
public class TwoFingerDragGestureRecognizer : GestureRecognizer
{
///
/// Distance in inches a user's touches can drift from the start position
/// before the drag gesture is interpreted as started.
///
public float slopInches { get; set; } = 0.1f;
///
/// Maximum angle of the divergence between the paths of both fingers
/// for a two-finger drag gesture to be interpreted as started.
///
public float angleThresholdRadians { get; set; } = Mathf.PI / 6;
// Preallocate delegates to avoid GC Alloc that would happen in TryCreateGestures
readonly Func m_CreateEnhancedGesture;
readonly Func m_CreateGestureFunction;
readonly Action m_ReinitializeEnhancedGesture;
readonly Action m_ReinitializeGestureFunction;
///
/// Initializes and returns an instance of .
///
public TwoFingerDragGestureRecognizer()
{
m_CreateEnhancedGesture = CreateEnhancedGesture;
m_CreateGestureFunction = CreateGesture;
m_ReinitializeEnhancedGesture = ReinitializeEnhancedGesture;
m_ReinitializeGestureFunction = ReinitializeGesture;
}
///
/// Creates a two finger drag gesture with the given touches.
///
/// The first touch that started this gesture.
/// The second touch that started this gesture.
/// The created Two Finger Drag gesture.
TwoFingerDragGesture CreateGesture(Touch touch1, Touch touch2)
{
return new TwoFingerDragGesture(this, touch1, touch2);
}
static void ReinitializeGesture(TwoFingerDragGesture gesture, Touch touch1, Touch touch2)
{
gesture.Reinitialize(touch1, touch2);
}
///
/// Creates a two finger drag gesture with the given touches.
///
/// The first touch that started this gesture.
/// The second touch that started this gesture.
/// The created Two Finger Drag gesture.
TwoFingerDragGesture CreateEnhancedGesture(InputSystem.EnhancedTouch.Touch touch1, InputSystem.EnhancedTouch.Touch touch2)
{
return new TwoFingerDragGesture(this, touch1, touch2);
}
static void ReinitializeEnhancedGesture(TwoFingerDragGesture gesture, InputSystem.EnhancedTouch.Touch touch1, InputSystem.EnhancedTouch.Touch touch2)
{
gesture.Reinitialize(touch1, touch2);
}
///
protected override void TryCreateGestures()
{
if (GestureTouchesUtility.touchInputSource == GestureTouchesUtility.TouchInputSource.Enhanced)
TryCreateTwoFingerGestureOnTouchBegan(m_CreateEnhancedGesture, m_ReinitializeEnhancedGesture);
else
TryCreateTwoFingerGestureOnTouchBegan(m_CreateGestureFunction, m_ReinitializeGestureFunction);
}
}
}
#endif