BuildStatusButton.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using UnityEditor;
  3. using UnityEditor.Collaboration;
  4. using UnityEngine;
  5. #if UNITY_2019_1_OR_NEWER
  6. using UnityEngine.UIElements;
  7. #else
  8. using UnityEngine.Experimental.UIElements;
  9. #endif
  10. namespace UnityEditor.Collaboration
  11. {
  12. internal class BuildStatusButton : Button
  13. {
  14. private readonly string iconPrefix = "Icons/Collab.Build";
  15. private readonly string iconSuffix = ".png";
  16. Label labelElement = new Label();
  17. Image iconElement = new Image() {name = "BuildIcon"};
  18. public BuildStatusButton(Action clickEvent) : base(clickEvent)
  19. {
  20. iconElement.image = EditorGUIUtility.Load(iconPrefix + iconSuffix) as Texture;
  21. labelElement.text = "Build Now";
  22. Add(iconElement);
  23. Add(labelElement);
  24. }
  25. public BuildStatusButton(Action clickEvent, BuildState state, int failures) : base(clickEvent)
  26. {
  27. switch (state)
  28. {
  29. case BuildState.InProgress:
  30. iconElement.image = EditorGUIUtility.Load(iconPrefix + iconSuffix) as Texture;
  31. labelElement.text = "In progress";
  32. break;
  33. case BuildState.Failed:
  34. iconElement.image = EditorGUIUtility.Load(iconPrefix + "Failed" + iconSuffix) as Texture;
  35. labelElement.text = failures + ((failures == 1) ? " failure" : " failures");
  36. break;
  37. case BuildState.Success:
  38. iconElement.image = EditorGUIUtility.Load(iconPrefix + "Succeeded" + iconSuffix) as Texture;
  39. labelElement.text = "success";
  40. break;
  41. }
  42. Add(iconElement);
  43. Add(labelElement);
  44. }
  45. }
  46. }