ShowSliderValue.cs 861 B

12345678910111213141516171819202122232425262728293031323334
  1. //
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. // Licensed under the MIT License. See LICENSE in the project root for license information.
  4. //
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using UnityEngine;
  8. using TMPro;
  9. using SC.XR.Unity;
  10. public class ShowSliderValue : MonoBehaviour {
  11. [SerializeField]
  12. private SCSlider3D sCSlider3D;
  13. [SerializeField]
  14. private TextMeshPro textMesh = null;
  15. void Awake() {
  16. sCSlider3D?.onValueChanged.AddListener(OnSliderUpdated);
  17. }
  18. void OnDestroy() {
  19. sCSlider3D?.onValueChanged.RemoveListener(OnSliderUpdated);
  20. }
  21. public void OnSliderUpdated(float value) {
  22. if(textMesh == null) {
  23. textMesh = GetComponent<TextMeshPro>();
  24. }
  25. if(textMesh != null) {
  26. textMesh.text = $"{value:F2}";
  27. }
  28. }
  29. }