HistoryProgressSpinner.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using UnityEngine;
  2. #if UNITY_2019_1_OR_NEWER
  3. using UnityEngine.UIElements;
  4. #else
  5. using UnityEngine.Experimental.UIElements;
  6. #endif
  7. namespace UnityEditor.Collaboration
  8. {
  9. internal class HistoryProgressSpinner : Image
  10. {
  11. private readonly Texture2D[] m_StatusWheelTextures;
  12. private bool m_ProgressEnabled;
  13. private IVisualElementScheduledItem m_Animation;
  14. public bool ProgressEnabled
  15. {
  16. set
  17. {
  18. if (m_ProgressEnabled == value)
  19. return;
  20. m_ProgressEnabled = value;
  21. visible = value;
  22. if (value)
  23. {
  24. if (m_Animation == null)
  25. {
  26. m_Animation = this.schedule.Execute(AnimateProgress).Every(33);
  27. }
  28. else
  29. {
  30. m_Animation.Resume();
  31. }
  32. }
  33. else
  34. {
  35. if (m_Animation != null)
  36. {
  37. m_Animation.Pause();
  38. }
  39. }
  40. }
  41. }
  42. public HistoryProgressSpinner()
  43. {
  44. m_StatusWheelTextures = new Texture2D[12];
  45. for (int i = 0; i < 12; i++)
  46. {
  47. m_StatusWheelTextures[i] = EditorGUIUtility.LoadIcon("WaitSpin" + i.ToString("00"));
  48. }
  49. image = m_StatusWheelTextures[0];
  50. style.width = m_StatusWheelTextures[0].width;
  51. style.height = m_StatusWheelTextures[0].height;
  52. visible = false;
  53. }
  54. private void AnimateProgress(TimerState obj)
  55. {
  56. int frame = (int)Mathf.Repeat(Time.realtimeSinceStartup * 10, 11.99f);
  57. image = m_StatusWheelTextures[frame];
  58. MarkDirtyRepaint();
  59. }
  60. }
  61. }