From 8263edd59284aba390aca011d25b79efecef4c48 Mon Sep 17 00:00:00 2001 From: pryazha Date: Wed, 2 Jul 2025 08:46:23 -0700 Subject: init --- .../DemoSceneAssets/Scripts/IncrementUIText.cs | 45 ++++++ .../Scripts/IncrementUIText.cs.meta | 11 ++ .../Scripts/MultiAnchorTeleportReticle.cs | 164 +++++++++++++++++++++ .../Scripts/MultiAnchorTeleportReticle.cs.meta | 11 ++ 4 files changed, 231 insertions(+) create mode 100644 Assets/Samples/XR Interaction Toolkit/3.1.2/Starter Assets/DemoSceneAssets/Scripts/IncrementUIText.cs create mode 100644 Assets/Samples/XR Interaction Toolkit/3.1.2/Starter Assets/DemoSceneAssets/Scripts/IncrementUIText.cs.meta create mode 100644 Assets/Samples/XR Interaction Toolkit/3.1.2/Starter Assets/DemoSceneAssets/Scripts/MultiAnchorTeleportReticle.cs create mode 100644 Assets/Samples/XR Interaction Toolkit/3.1.2/Starter Assets/DemoSceneAssets/Scripts/MultiAnchorTeleportReticle.cs.meta (limited to 'Assets/Samples/XR Interaction Toolkit/3.1.2/Starter Assets/DemoSceneAssets/Scripts') diff --git a/Assets/Samples/XR Interaction Toolkit/3.1.2/Starter Assets/DemoSceneAssets/Scripts/IncrementUIText.cs b/Assets/Samples/XR Interaction Toolkit/3.1.2/Starter Assets/DemoSceneAssets/Scripts/IncrementUIText.cs new file mode 100644 index 0000000..9f72261 --- /dev/null +++ b/Assets/Samples/XR Interaction Toolkit/3.1.2/Starter Assets/DemoSceneAssets/Scripts/IncrementUIText.cs @@ -0,0 +1,45 @@ +using UnityEngine.UI; + +namespace UnityEngine.XR.Interaction.Toolkit.Samples.StarterAssets +{ + /// + /// Add this component to a GameObject and call the method + /// in response to a Unity Event to update a text display to count up with each event. + /// + public class IncrementUIText : MonoBehaviour + { + [SerializeField] + [Tooltip("The Text component this behavior uses to display the incremented value.")] + Text m_Text; + + /// + /// The Text component this behavior uses to display the incremented value. + /// + public Text text + { + get => m_Text; + set => m_Text = value; + } + + int m_Count; + + /// + /// See . + /// + protected void Awake() + { + if (m_Text == null) + Debug.LogWarning("Missing required Text component reference. Use the Inspector window to assign which Text component to increment.", this); + } + + /// + /// Increment the string message of the Text component. + /// + public void IncrementText() + { + m_Count += 1; + if (m_Text != null) + m_Text.text = m_Count.ToString(); + } + } +} diff --git a/Assets/Samples/XR Interaction Toolkit/3.1.2/Starter Assets/DemoSceneAssets/Scripts/IncrementUIText.cs.meta b/Assets/Samples/XR Interaction Toolkit/3.1.2/Starter Assets/DemoSceneAssets/Scripts/IncrementUIText.cs.meta new file mode 100644 index 0000000..ad45603 --- /dev/null +++ b/Assets/Samples/XR Interaction Toolkit/3.1.2/Starter Assets/DemoSceneAssets/Scripts/IncrementUIText.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ba6ff5e7c92519444bc2a7ca46558963 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Samples/XR Interaction Toolkit/3.1.2/Starter Assets/DemoSceneAssets/Scripts/MultiAnchorTeleportReticle.cs b/Assets/Samples/XR Interaction Toolkit/3.1.2/Starter Assets/DemoSceneAssets/Scripts/MultiAnchorTeleportReticle.cs new file mode 100644 index 0000000..86643c7 --- /dev/null +++ b/Assets/Samples/XR Interaction Toolkit/3.1.2/Starter Assets/DemoSceneAssets/Scripts/MultiAnchorTeleportReticle.cs @@ -0,0 +1,164 @@ +using UnityEngine.UI; +using UnityEngine.XR.Interaction.Toolkit.Interactables; +using UnityEngine.XR.Interaction.Toolkit.Interactables.Visuals; +using UnityEngine.XR.Interaction.Toolkit.Interactors.Visuals; +using UnityEngine.XR.Interaction.Toolkit.Locomotion.Teleportation; + +namespace UnityEngine.XR.Interaction.Toolkit.Samples.StarterAssets +{ + /// + /// A custom reticle for a that displays its progress towards evaluating + /// a destination anchor and an indicator pointing in the direction of the destination anchor. + /// + public class MultiAnchorTeleportReticle : MonoBehaviour, IXRInteractableCustomReticle + { + [SerializeField] + [Tooltip("Filled image that displays the progress towards evaluating a destination anchor.")] + Image m_TimerProgressFilledImage; + + /// + /// image that displays the progress towards evaluating a destination anchor. + /// + public Image timerProgressFilledImage + { + get => m_TimerProgressFilledImage; + set => m_TimerProgressFilledImage = value; + } + + [SerializeField] + [Tooltip("Object that is rotated about its Z axis to point at the destination anchor.")] + GameObject m_DestinationIndicator; + + /// + /// Object that is rotated about its Z axis to point at the destination anchor. + /// + public GameObject destinationIndicator + { + get => m_DestinationIndicator; + set => m_DestinationIndicator = value; + } + + [SerializeField] + [Tooltip("Object that is rotated about its Z axis to point at the potential destination while still evaluating.")] + GameObject m_PotentialDestinationIndicator; + + /// + /// Object that is rotated about its Z axis to point at the potential destination while still evaluating. + /// + public GameObject potentialDestinationIndicator + { + get => m_PotentialDestinationIndicator; + set => m_PotentialDestinationIndicator = value; + } + + [SerializeField] + [Tooltip("The amount of time, in seconds, between updates to the indicator pointing at the potential destination.")] + float m_PotentialIndicatorUpdateFrequency = 0.1f; + + /// + /// The amount of time, in seconds, between updates to the indicator pointing at the potential destination. + /// + public float potentialIndicatorUpdateFrequency + { + get => m_PotentialIndicatorUpdateFrequency; + set => m_PotentialIndicatorUpdateFrequency = value; + } + + TeleportationMultiAnchorVolume m_AnchorVolume; + float m_LastPotentialIndicatorUpdateTime; + + /// + public void OnReticleAttached(XRBaseInteractable interactable, IXRCustomReticleProvider reticleProvider) + { + m_AnchorVolume = interactable as TeleportationMultiAnchorVolume; + m_PotentialDestinationIndicator.SetActive(false); + m_DestinationIndicator.SetActive(false); + m_TimerProgressFilledImage.type = Image.Type.Filled; + m_TimerProgressFilledImage.fillAmount = 0f; + if (m_AnchorVolume == null) + return; + + m_AnchorVolume.destinationAnchorChanged += OnDestinationAnchorChanged; + } + + /// + public void OnReticleDetaching() + { + if (m_AnchorVolume == null) + return; + + m_AnchorVolume.destinationAnchorChanged -= OnDestinationAnchorChanged; + m_AnchorVolume = null; + } + + /// + /// See . + /// + protected void Update() + { + if (m_AnchorVolume == null) + return; + + var destinationAnchor = m_AnchorVolume.destinationAnchor; + if (destinationAnchor != null) + { + PointAtTarget(m_DestinationIndicator.transform, destinationAnchor.position); + return; + } + + m_TimerProgressFilledImage.fillAmount = m_AnchorVolume.destinationEvaluationProgress; + if (Time.time - m_LastPotentialIndicatorUpdateTime >= m_PotentialIndicatorUpdateFrequency) + UpdatePotentialDestinationIndicator(); + } + + void UpdatePotentialDestinationIndicator() + { + m_LastPotentialIndicatorUpdateTime = Time.time; + if (!m_AnchorVolume.destinationEvaluationSettings.Value.pollForDestinationChange) + { + m_PotentialDestinationIndicator.SetActive(false); + return; + } + + var potentialDestinationIndex = m_AnchorVolume.destinationEvaluationFilter.GetDestinationAnchorIndex(m_AnchorVolume); + var anchors = m_AnchorVolume.anchorTransforms; + if (potentialDestinationIndex < 0 || potentialDestinationIndex >= anchors.Count) + { + m_PotentialDestinationIndicator.SetActive(false); + return; + } + + var potentialDestination = anchors[potentialDestinationIndex]; + if (potentialDestination == null) + { + m_PotentialDestinationIndicator.SetActive(false); + return; + } + + m_PotentialDestinationIndicator.SetActive(true); + PointAtTarget(m_PotentialDestinationIndicator.transform, potentialDestination.position); + } + + void OnDestinationAnchorChanged(TeleportationMultiAnchorVolume anchorVolume) + { + var destinationAnchor = anchorVolume.destinationAnchor; + if (destinationAnchor != null) + { + m_TimerProgressFilledImage.fillAmount = 1f; + m_PotentialDestinationIndicator.SetActive(false); + m_DestinationIndicator.SetActive(true); + PointAtTarget(m_DestinationIndicator.transform, destinationAnchor.position); + } + else + { + m_TimerProgressFilledImage.fillAmount = 0f; + m_DestinationIndicator.SetActive(false); + } + } + + static void PointAtTarget(Transform indicatorTransform, Vector3 targetPosition) + { + indicatorTransform.rotation = Quaternion.LookRotation(indicatorTransform.forward, targetPosition - indicatorTransform.position); + } + } +} diff --git a/Assets/Samples/XR Interaction Toolkit/3.1.2/Starter Assets/DemoSceneAssets/Scripts/MultiAnchorTeleportReticle.cs.meta b/Assets/Samples/XR Interaction Toolkit/3.1.2/Starter Assets/DemoSceneAssets/Scripts/MultiAnchorTeleportReticle.cs.meta new file mode 100644 index 0000000..2967af1 --- /dev/null +++ b/Assets/Samples/XR Interaction Toolkit/3.1.2/Starter Assets/DemoSceneAssets/Scripts/MultiAnchorTeleportReticle.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e001d3dc91354f8f8c590b4e1d1d3da9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: -- cgit v1.2.3-70-g09d2