// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) VRMADA, All rights reserved. // // -------------------------------------------------------------------------------------------------------------------- using UltimateXR.Core.Components; using UltimateXR.UI.UnityInputModule.Controls; using UnityEngine; using UnityEngine.EventSystems; namespace UltimateXR.UI.UnityInputModule.Utils { /// /// Component that, added to a with a component, will destroy /// the GameObject whenever the control is clicked. /// [RequireComponent(typeof(UxrControlInput))] public class UxrControlInputDestroyOnPress : UxrComponent { #region Public Types & Data /// /// Gets the component. /// public UxrControlInput ControlInput => GetCachedComponent(); #endregion #region Unity /// /// Subscribes to events. /// protected override void OnEnable() { base.OnEnable(); ControlInput.Clicked += Control_Clicked; } /// /// Unsubscribes from events. /// protected override void OnDisable() { base.OnDisable(); ControlInput.Clicked -= Control_Clicked; } #endregion #region Event Handling Methods /// /// Called when the object was clicked. /// /// Control that was clicked /// Event data private void Control_Clicked(UxrControlInput controlInput, PointerEventData eventData) { Destroy(gameObject); } #endregion } }