MiniLabelProvider.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using UnityEngine;
  3. namespace EnhancedHierarchy {
  4. public abstract class MiniLabelProvider {
  5. private readonly GUIContent content = new GUIContent();
  6. public static readonly Type[] MiniLabelsTypes = new [] {
  7. null,
  8. typeof(TagMiniLabel),
  9. typeof(LayerMiniLabel),
  10. typeof(SortingLayerMiniLabel)
  11. };
  12. public abstract void FillContent(GUIContent content);
  13. public abstract bool Faded();
  14. public abstract void OnClick();
  15. public void Init() {
  16. FillContent(content);
  17. }
  18. public bool HasValue() {
  19. return content.text.Length > 0;
  20. }
  21. public virtual bool Draw(Rect rect, GUIContent content, GUIStyle style) {
  22. return GUI.Button(rect, content, style);
  23. }
  24. public float Measure() {
  25. var calculated = Styles.miniLabelStyle.CalcSize(content);
  26. return calculated.x;
  27. }
  28. public void Draw(ref Rect rect) {
  29. if (!HasValue())
  30. return;
  31. var color = EnhancedHierarchy.CurrentColor;
  32. var alpha = Faded() ? Styles.backgroundColorDisabled.a : Styles.backgroundColorEnabled.a;
  33. var finalColor = color * new Color(1f, 1f, 1f, alpha);
  34. using(ProfilerSample.Get())
  35. using(new GUIContentColor(finalColor)) {
  36. Styles.miniLabelStyle.fontSize = Preferences.SmallerMiniLabel ? 8 : 9;
  37. rect.xMin -= Measure();
  38. if (Draw(rect, content, Styles.miniLabelStyle))
  39. OnClick();
  40. }
  41. }
  42. }
  43. }