using System;
using UnityEngine.XR.Management;
using UnityEngine.XR.InteractionSubsystems;
namespace UnityEngine.XR.MagicLeap
{
[DisallowMultipleComponent]
public sealed class GestureSubsystemComponent : MonoBehaviour
{
public GestureSubsystem gestureSubsystem { get; private set; }
public event Action<GestureSubsystem.Extensions.TouchpadGestureEvent> onTouchpadGestureChanged;
public event Action<ActivateGestureEvent> onActivate;
[SerializeField]
bool m_ControllerGesturesEnabled;
public bool controllerGesturesEnabled
{
get => m_ControllerGesturesEnabled;
}
void OnEnable()
{
gestureSubsystem = XRGeneralSettings.Instance?.Manager?.activeLoader?.GetLoadedSubsystem<XRGestureSubsystem>() as GestureSubsystem;
}
void OnDisable()
{
gestureSubsystem = null;
}
void Update()
{
if (gestureSubsystem == null || !gestureSubsystem.running)
return;
gestureSubsystem.Update();
if (onTouchpadGestureChanged != null)
{
foreach (var touchpadGestureEvent in gestureSubsystem.touchpadGestureEvents)
onTouchpadGestureChanged(touchpadGestureEvent);
}
if (onActivate != null)
{
foreach (var activateGestureEvent in gestureSubsystem.activateGestureEvents)
onActivate(activateGestureEvent);
}
}
}
}