ProgressView.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using JetBrains.Annotations;
  3. using Unity.Cloud.Collaborate.Assets;
  4. using Unity.Cloud.Collaborate.UserInterface;
  5. using UnityEditor;
  6. using UnityEditor.UIElements;
  7. using UnityEngine;
  8. using UnityEngine.UIElements;
  9. namespace Unity.Cloud.Collaborate.Components
  10. {
  11. [UsedImplicitly]
  12. internal class ProgressView : VisualElement
  13. {
  14. public const string UssClassName = "progress-view";
  15. public const string LabelUssClassName = UssClassName + "__label";
  16. public const string ProgressBarUssClassName = UssClassName + "__progress-bar";
  17. public const string ButtonUssClassName = UssClassName + "__button";
  18. static readonly string k_LayoutPath = $"{CollaborateWindow.LayoutPath}/{nameof(ProgressView)}.uxml";
  19. static readonly string k_StylePath = $"{CollaborateWindow.StylePath}/{nameof(ProgressView)}.uss";
  20. readonly Label m_Label;
  21. readonly ProgressBar m_ProgressBar;
  22. readonly Button m_Button;
  23. public ProgressView()
  24. {
  25. AddToClassList(UssClassName);
  26. AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(k_LayoutPath).CloneTree(this);
  27. styleSheets.Add(AssetDatabase.LoadAssetAtPath<StyleSheet>(k_StylePath));
  28. m_Label = this.Q<Label>(className: LabelUssClassName);
  29. m_Label.text = string.Empty;
  30. m_ProgressBar = this.Q<ProgressBar>(className: ProgressBarUssClassName);
  31. m_Button = this.Q<Button>(className: ButtonUssClassName);
  32. m_Button.text = StringAssets.cancel;
  33. }
  34. public void SetText(string text, string progressText)
  35. {
  36. m_Label.text = text;
  37. m_ProgressBar.title = progressText;
  38. }
  39. public void SetPercentComplete(int percent)
  40. {
  41. m_ProgressBar.value = percent;
  42. }
  43. public void SetCancelCallback(Action callback)
  44. {
  45. m_Button.clickable.clicked += callback;
  46. }
  47. public void SetCancelButtonActive(bool active)
  48. {
  49. m_Button.SetEnabled(active);
  50. }
  51. [UsedImplicitly]
  52. public new class UxmlFactory : UxmlFactory<ProgressView> { }
  53. }
  54. }