using System; using UnityEngine; using UnityEngine.Assertions; namespace Rokid.UXR.Interaction { public abstract class PointerInteractable : Interactable, IPointable where TInteractor : Interactor where TInteractable : PointerInteractable { [SerializeField, Interface(typeof(IPointableElement)), Optional] private MonoBehaviour _pointableElement; public IPointableElement PointableElement { get; private set; } public event Action WhenPointerEventRaised = delegate { }; public void PublishPointerEvent(PointerEvent evt) { WhenPointerEventRaised(evt); } protected override void Awake() { base.Awake(); if (_pointableElement != null) { PointableElement = _pointableElement as IPointableElement; } } protected override void Start() { if (_pointableElement != null) { Assert.IsNotNull(PointableElement); } } protected override void OnEnable() { base.OnEnable(); if (PointableElement != null) { WhenPointerEventRaised += PointableElement.ProcessPointerEvent; } } protected override void OnDisable() { if (PointableElement != null) { WhenPointerEventRaised -= PointableElement.ProcessPointerEvent; } base.OnDisable(); } } }