From 8263edd59284aba390aca011d25b79efecef4c48 Mon Sep 17 00:00:00 2001 From: pryazha Date: Wed, 2 Jul 2025 08:46:23 -0700 Subject: init --- .../Scripts/HideObjectWhenInteractorBlocked.cs | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Assets/Samples/XR Interaction Toolkit/3.1.2/Hands Interaction Demo/Scripts/HideObjectWhenInteractorBlocked.cs (limited to 'Assets/Samples/XR Interaction Toolkit/3.1.2/Hands Interaction Demo/Scripts/HideObjectWhenInteractorBlocked.cs') diff --git a/Assets/Samples/XR Interaction Toolkit/3.1.2/Hands Interaction Demo/Scripts/HideObjectWhenInteractorBlocked.cs b/Assets/Samples/XR Interaction Toolkit/3.1.2/Hands Interaction Demo/Scripts/HideObjectWhenInteractorBlocked.cs new file mode 100644 index 0000000..912894a --- /dev/null +++ b/Assets/Samples/XR Interaction Toolkit/3.1.2/Hands Interaction Demo/Scripts/HideObjectWhenInteractorBlocked.cs @@ -0,0 +1,49 @@ +using UnityEngine.XR.Interaction.Toolkit.Interactors; +using UnityEngine.XR.Interaction.Toolkit.Interactors.Visuals; + +namespace UnityEngine.XR.Interaction.Toolkit.Samples.Hands +{ + /// + /// Hides the specified GameObject when the associated interactor is blocked by an interaction within its group. + /// + public class HideObjectWhenInteractorBlocked : MonoBehaviour + { + [SerializeField] + [Tooltip("The interactor that this component monitors for blockages.")] + XRBaseInteractor m_Interactor; + + [SerializeField] + [Tooltip("The GameObject to hide when the interactor is blocked.")] + GameObject m_ObjectToHide; + + ICurveInteractionDataProvider m_CurveInteractionDataProvider; + bool m_HasCurveDataProvider; + + /// + /// See . + /// + void OnEnable() + { + if (m_Interactor == null || m_ObjectToHide == null) + enabled = false; + + m_HasCurveDataProvider = false; + if (m_Interactor is ICurveInteractionDataProvider provider) + { + m_CurveInteractionDataProvider = provider; + m_HasCurveDataProvider = true; + } + } + + /// + /// See . + /// + void Update() + { + if (m_HasCurveDataProvider) + m_ObjectToHide.SetActive(m_CurveInteractionDataProvider.isActive); + else + m_ObjectToHide.SetActive(m_Interactor.isActiveAndEnabled && !m_Interactor.IsBlockedByInteractionWithinGroup()); + } + } +} -- cgit v1.2.3-70-g09d2