暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

TilePaletteBrushesLabel.cs 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UIElements;
  4. namespace UnityEditor.Tilemaps
  5. {
  6. internal class TilePaletteBrushesLabel : TextElement
  7. {
  8. public static string kNullBrushName = L10n.Tr("No Valid Brush");
  9. public static string kLabelTooltip =
  10. L10n.Tr("Specifies the currently active Brush used for painting in the Scene View.");
  11. private bool m_AppendSettings;
  12. public bool appendSettings
  13. {
  14. get { return m_AppendSettings; }
  15. set
  16. {
  17. m_AppendSettings = value;
  18. style.unityFontStyleAndWeight = m_AppendSettings ? FontStyle.Bold : FontStyle.Normal;
  19. }
  20. }
  21. public class
  22. TilePaletteBrushesLabelFactory : UxmlFactory<TilePaletteBrushesLabel, TilePaletteBrushesLabelUxmlTraits>
  23. {
  24. }
  25. public class TilePaletteBrushesLabelUxmlTraits : UxmlTraits
  26. {
  27. }
  28. /// <summary>
  29. /// USS class name of elements of this type.
  30. /// </summary>
  31. public new static readonly string ussClassName = "unity-tilepalette-brushes-label";
  32. /// <summary>
  33. /// Initializes and returns an instance of TilePaletteBrushesLabel.
  34. /// </summary>
  35. public TilePaletteBrushesLabel()
  36. {
  37. AddToClassList(ussClassName);
  38. TilePaletteOverlayUtility.SetStyleSheet(this);
  39. tooltip = kLabelTooltip;
  40. RegisterCallback<AttachToPanelEvent>(OnAttachedToPanel);
  41. RegisterCallback<DetachFromPanelEvent>(OnDetachFromPanel);
  42. }
  43. private void OnAttachedToPanel(AttachToPanelEvent evt)
  44. {
  45. GridPaintingState.brushChanged += OnBrushChanged;
  46. UpdateBrush();
  47. }
  48. private void OnBrushChanged(GridBrushBase obj)
  49. {
  50. UpdateBrush();
  51. }
  52. private void OnDetachFromPanel(DetachFromPanelEvent evt)
  53. {
  54. GridPaintingState.brushChanged -= OnBrushChanged;
  55. }
  56. private string FormatBrushName(GridBrushBase brush)
  57. {
  58. if (brush != null)
  59. {
  60. if (appendSettings)
  61. return String.Format("{0} Settings", brush.name);
  62. return brush.name;
  63. }
  64. return kNullBrushName;
  65. }
  66. private void UpdateBrush()
  67. {
  68. text = FormatBrushName(GridPaintingState.gridBrush);
  69. }
  70. }
  71. }