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/Starter Assets/DemoSceneAssets/Scripts |
Diffstat (limited to 'Assets/Samples/XR Interaction Toolkit/3.1.2/Starter Assets/DemoSceneAssets/Scripts')
4 files changed, 231 insertions, 0 deletions
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 +{ + /// <summary> + /// Add this component to a GameObject and call the <see cref="IncrementText"/> method + /// in response to a Unity Event to update a text display to count up with each event. + /// </summary> + public class IncrementUIText : MonoBehaviour + { + [SerializeField] + [Tooltip("The Text component this behavior uses to display the incremented value.")] + Text m_Text; + + /// <summary> + /// The Text component this behavior uses to display the incremented value. + /// </summary> + public Text text + { + get => m_Text; + set => m_Text = value; + } + + int m_Count; + + /// <summary> + /// See <see cref="MonoBehaviour"/>. + /// </summary> + 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); + } + + /// <summary> + /// Increment the string message of the Text component. + /// </summary> + 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 +{ + /// <summary> + /// A custom reticle for a <see cref="TeleportationMultiAnchorVolume"/> that displays its progress towards evaluating + /// a destination anchor and an indicator pointing in the direction of the destination anchor. + /// </summary> + public class MultiAnchorTeleportReticle : MonoBehaviour, IXRInteractableCustomReticle + { + [SerializeField] + [Tooltip("Filled image that displays the progress towards evaluating a destination anchor.")] + Image m_TimerProgressFilledImage; + + /// <summary> + /// <see cref="Image.Type.Filled"/> image that displays the progress towards evaluating a destination anchor. + /// </summary> + 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; + + /// <summary> + /// Object that is rotated about its Z axis to point at the destination anchor. + /// </summary> + 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; + + /// <summary> + /// Object that is rotated about its Z axis to point at the potential destination while still evaluating. + /// </summary> + 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; + + /// <summary> + /// The amount of time, in seconds, between updates to the indicator pointing at the potential destination. + /// </summary> + public float potentialIndicatorUpdateFrequency + { + get => m_PotentialIndicatorUpdateFrequency; + set => m_PotentialIndicatorUpdateFrequency = value; + } + + TeleportationMultiAnchorVolume m_AnchorVolume; + float m_LastPotentialIndicatorUpdateTime; + + /// <inheritdoc/> + 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; + } + + /// <inheritdoc/> + public void OnReticleDetaching() + { + if (m_AnchorVolume == null) + return; + + m_AnchorVolume.destinationAnchorChanged -= OnDestinationAnchorChanged; + m_AnchorVolume = null; + } + + /// <summary> + /// See <see cref="MonoBehaviour"/>. + /// </summary> + 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: |