暫無描述
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.

TilePaletteBrushesLabel.cs 2.7KB

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