설명 없음
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LoadingSpinner.cs 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using UnityEngine;
  2. using UnityEditor;
  3. using UnityEngine.UIElements;
  4. namespace Unity.PlasticSCM.Editor.UI.UIElements
  5. {
  6. internal class LoadingSpinner : VisualElement
  7. {
  8. internal LoadingSpinner()
  9. {
  10. mStarted = false;
  11. // add child elements to set up centered spinner rotation
  12. mSpinner = new VisualElement();
  13. Add(mSpinner);
  14. mSpinner.style.backgroundImage = Images.GetImage(Images.Name.Loading);
  15. mSpinner.style.position = Position.Absolute;
  16. mSpinner.style.width = 16;
  17. mSpinner.style.height = 16;
  18. mSpinner.style.left = -8;
  19. mSpinner.style.top = -8;
  20. style.position = Position.Relative;
  21. style.width = 16;
  22. style.height = 16;
  23. style.left = 8;
  24. style.top = 8;
  25. }
  26. internal void Dispose()
  27. {
  28. if (mStarted)
  29. EditorApplication.update -= UpdateProgress;
  30. }
  31. internal void Start()
  32. {
  33. if (mStarted)
  34. return;
  35. mRotation = 0;
  36. mLastRotationTime = EditorApplication.timeSinceStartup;
  37. EditorApplication.update += UpdateProgress;
  38. mStarted = true;
  39. }
  40. internal void Stop()
  41. {
  42. if (!mStarted)
  43. return;
  44. EditorApplication.update -= UpdateProgress;
  45. mStarted = false;
  46. }
  47. void UpdateProgress()
  48. {
  49. double currentTime = EditorApplication.timeSinceStartup;
  50. double deltaTime = currentTime - mLastRotationTime;
  51. #if UNITY_2021_2_OR_NEWER
  52. mSpinner.transform.rotation = Quaternion.Euler(0, 0, mRotation);
  53. #else
  54. transform.rotation = Quaternion.Euler(0, 0, mRotation);
  55. #endif
  56. mRotation += (int)(ROTATION_SPEED * deltaTime);
  57. mRotation = mRotation % 360;
  58. if (mRotation < 0) mRotation += 360;
  59. mLastRotationTime = currentTime;
  60. }
  61. int mRotation;
  62. double mLastRotationTime;
  63. bool mStarted;
  64. VisualElement mSpinner;
  65. const int ROTATION_SPEED = 360; // Euler degrees per second
  66. }
  67. }