using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; using UnityEngine.XR.Interaction.Toolkit; public class ManualInteractionEvents : MonoBehaviour { [SerializeField] private XRSocketInteractor interactor; [SerializeField] private HoverEnterEvent onHoverEnter; [SerializeField] private HoverExitEvent onHoverExit; [SerializeField] private SelectEnterEvent onSelectEnter; [SerializeField] private SelectExitEvent onSelectExit; public void AddListeners() { if (interactor == null) return; Debug.Log($"Adding listeners to {interactor.name}"); if (onHoverEnter.GetPersistentEventCount() > 0) { interactor.hoverEntered.AddListener(onHoverEnter.Invoke); } if (onHoverExit.GetPersistentEventCount() > 0) { interactor.hoverExited.AddListener(onHoverExit.Invoke); } if (onSelectEnter.GetPersistentEventCount() > 0) { interactor.selectEntered.AddListener(onSelectEnter.Invoke); } if (onSelectExit.GetPersistentEventCount() > 0) { interactor.selectExited.AddListener(onSelectExit.Invoke); } } public void RemoveListeners() { if (interactor == null) return; Debug.Log($"Removing listeners from {interactor.name}"); if (onHoverEnter != null && onHoverEnter.GetPersistentEventCount() > 0) { interactor.hoverEntered.RemoveListener(onHoverEnter.Invoke); } if (onHoverExit != null && onHoverExit.GetPersistentEventCount() > 0) { interactor.hoverExited.RemoveListener(onHoverExit.Invoke); } if (onSelectEnter != null && onSelectEnter.GetPersistentEventCount() > 0) { interactor.selectEntered.RemoveListener(onSelectEnter.Invoke); } if (onSelectExit != null && onSelectExit.GetPersistentEventCount() > 0) { interactor.selectExited.RemoveListener(onSelectExit.Invoke); } } }