FillBar.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. public class FillBar : MonoBehaviour
  4. {
  5. [SerializeField] Image FillRequired;
  6. [SerializeField] Image FillCurrent;
  7. [SerializeField] private float requiredValue = 0.0f;
  8. [SerializeField] private float currentValue = 0.0f;
  9. [SerializeField] private bool isRequired = false;
  10. public float RequiredValue
  11. {
  12. get
  13. {
  14. return requiredValue;
  15. }
  16. set
  17. {
  18. requiredValue = value > 1.0f ? 1.0f : value < 0.0f ? 0.0f : value;
  19. FillRequired.fillAmount = requiredValue;
  20. }
  21. }
  22. public float CurrentValue
  23. {
  24. get
  25. {
  26. return currentValue;
  27. }
  28. set
  29. {
  30. currentValue = value > 1.0f ? 1.0f : value < 0.0f ? 0.0f : value;
  31. FillCurrent.fillAmount = currentValue;
  32. }
  33. }
  34. public bool ShowRequired
  35. {
  36. get
  37. {
  38. return isRequired;
  39. }
  40. set
  41. {
  42. isRequired = value;
  43. FillRequired.gameObject.SetActive(isRequired);
  44. }
  45. }
  46. }