HorizontalProgressBar.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*===============================================================================
  2. Copyright (C) 2022 Immersal - Part of Hexagon. All Rights Reserved.
  3. This file is part of the Immersal SDK.
  4. The Immersal SDK cannot be copied, distributed, or made available to
  5. third-parties for commercial purposes without written permission of Immersal Ltd.
  6. Contact sdk@immersal.com for licensing requests.
  7. ===============================================================================*/
  8. using UnityEngine;
  9. using UnityEngine.UI;
  10. using TMPro;
  11. namespace Immersal.Samples.Util
  12. {
  13. public class HorizontalProgressBar : MonoBehaviour
  14. {
  15. [SerializeField]
  16. private Image m_ForegroundImage = null;
  17. [SerializeField]
  18. private TextMeshProUGUI m_LabelText = null;
  19. private int m_CurrentValue = 0;
  20. public int minValue = 0;
  21. public int maxValue = 100;
  22. public int currentValue
  23. {
  24. get => m_CurrentValue;
  25. set
  26. {
  27. m_CurrentValue = value;
  28. m_ForegroundImage.fillAmount = (float)value / (float)maxValue;
  29. //m_LabelText.text = string.Format("{0}/{1}", value, maxValue);
  30. m_LabelText.text = string.Format("{0}%", value);
  31. }
  32. }
  33. void Start()
  34. {
  35. Reset();
  36. }
  37. public void Reset()
  38. {
  39. currentValue = 0;
  40. }
  41. }
  42. }