diff options
author | pryazha <pryadeiniv@mail.ru> | 2025-07-02 08:46:23 -0700 |
---|---|---|
committer | pryazha <pryadeiniv@mail.ru> | 2025-07-02 08:46:23 -0700 |
commit | 8263edd59284aba390aca011d25b79efecef4c48 (patch) | |
tree | 6346e2afaaabd32156601cafaf20d4ee813befaf /Assets/Samples/XR Interaction Toolkit/3.1.2/Hands Interaction Demo/Scripts/HideObjectWhenInteractorBlocked.cs |
Diffstat (limited to 'Assets/Samples/XR Interaction Toolkit/3.1.2/Hands Interaction Demo/Scripts/HideObjectWhenInteractorBlocked.cs')
-rw-r--r-- | Assets/Samples/XR Interaction Toolkit/3.1.2/Hands Interaction Demo/Scripts/HideObjectWhenInteractorBlocked.cs | 49 |
1 files changed, 49 insertions, 0 deletions
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 +{ + /// <summary> + /// Hides the specified GameObject when the associated interactor is blocked by an interaction within its group. + /// </summary> + 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; + + /// <summary> + /// See <see cref="MonoBehaviour"/>. + /// </summary> + 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; + } + } + + /// <summary> + /// See <see cref="MonoBehaviour"/>. + /// </summary> + void Update() + { + if (m_HasCurveDataProvider) + m_ObjectToHide.SetActive(m_CurveInteractionDataProvider.isActive); + else + m_ObjectToHide.SetActive(m_Interactor.isActiveAndEnabled && !m_Interactor.IsBlockedByInteractionWithinGroup()); + } + } +} |