LoadProgressImages.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using UnityEngine;
  3. using System.Collections;
  4. using UnityEngine.UI;
  5. namespace Devdog.SciFiDesign.UI
  6. {
  7. public class LoadProgressImages : MonoBehaviour
  8. {
  9. public Color inactiveColor = Color.gray;
  10. public Color activeColor = Color.white;
  11. public Image[] images = new Image[0];
  12. protected virtual void Start()
  13. {
  14. Reset();
  15. }
  16. protected virtual void Reset()
  17. {
  18. StartCoroutine(_Reset());
  19. }
  20. private IEnumerator _Reset()
  21. {
  22. yield return new WaitForSeconds(0.5f);
  23. float timer = 0f;
  24. while (timer < 0.5f)
  25. {
  26. timer += Time.deltaTime;
  27. foreach (var image in images)
  28. {
  29. image.color = Color.Lerp(activeColor, inactiveColor, timer * 2f);
  30. }
  31. yield return null;
  32. }
  33. }
  34. protected virtual void OnProgress(float progress)
  35. {
  36. int index = Mathf.CeilToInt(progress * images.Length);
  37. for (int i = 0; i < index; i++)
  38. {
  39. images[i].color = activeColor;
  40. }
  41. }
  42. }
  43. }