OK, I figured it out. What I did was creating an implementation of IGestureDelegate and set this on the IGestureManager instance as the GlobaleGestureDelegate. This allows to get notified just before a Gesture begins in ShouldBegin(Gesture gesture). In this method I store the reference to the first exclusive gesture, and return false if this reference is not null.
To this implementation I added a NotifyGestureEnded(Gesture gesture) method, and ensured this method is called when an exclusive gesture completes/fails or otherwise ends. If the gesture passed is the set exclusive gesture the stored reference is set to null, so other exclusive gesture can begin again.
- Code: Select all
using System;
using TouchScript;
using TouchScript.Gestures;
using UnityEngine;
public class ExclusiveGestureDelegate : MonoBehaviour, IGestureDelegate
{
#region Private Fields
private Gesture currentExclusiveGesture;
#endregion
#region Unity Methods
private void OnEnable()
{
GestureManager.Instance.GlobalGestureDelegate = this;
}
private void OnDisable()
{
if (GestureManager.Instance != null)
{
GestureManager.Instance.GlobalGestureDelegate = null;
}
}
#endregion
/// <summary>
///
/// </summary>
/// <param name="gesture"></param>
public void NotifyGestureEnded(Gesture gesture)
{
if (currentExclusiveGesture == gesture)
{
currentExclusiveGesture = null;
}
}
#region IGestureDelegate
/// <inheritdoc />
public bool ShouldBegin(Gesture gesture)
{
if (!currentExclusiveGesture)
{
currentExclusiveGesture = gesture;
return true;
}
return false;
}
/// <inheritdoc />
public bool ShouldReceiveTouch(Gesture gesture, TouchPoint touch)
{
return true;
}
/// <inheritdoc />
public bool ShouldRecognizeSimultaneously(Gesture first, Gesture second)
{
return true;
}
#endregion
}