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

HelpBoxRow.cs 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System;
  2. using System.Linq;
  3. using UnityEngine;
  4. using UnityEngine.UIElements;
  5. namespace UnityEditor.ShaderGraph.Drawing
  6. {
  7. // Similar in function to the old EditorGUILayout.HelpBox
  8. class HelpBoxRow : VisualElement
  9. {
  10. VisualElement m_ContentContainer;
  11. VisualElement m_LabelContainer;
  12. public override VisualElement contentContainer
  13. {
  14. get { return m_ContentContainer; }
  15. }
  16. public HelpBoxRow(MessageType type)
  17. {
  18. styleSheets.Add(Resources.Load<StyleSheet>("Styles/HelpBoxRow"));
  19. VisualElement container = new VisualElement { name = "container" };
  20. m_ContentContainer = new VisualElement { name = "content" };
  21. m_LabelContainer = new VisualElement { name = "label" };
  22. switch (type)
  23. {
  24. case MessageType.None:
  25. container.AddToClassList("help-box-row-style-info");
  26. break;
  27. case MessageType.Info:
  28. container.AddToClassList("help-box-row-style-info");
  29. break;
  30. case MessageType.Warning:
  31. container.AddToClassList("help-box-row-style-warning");
  32. break;
  33. case MessageType.Error:
  34. container.AddToClassList("help-box-row-style-error");
  35. break;
  36. default:
  37. break;
  38. }
  39. container.Add(m_LabelContainer);
  40. container.Add(m_ContentContainer);
  41. hierarchy.Add(container);
  42. }
  43. public static VisualElement CreateVariantLimitHelpBox(int currentVariantCount, int maxVariantCount)
  44. {
  45. var messageType = MessageType.Error;
  46. HelpBoxRow help = new HelpBoxRow(messageType);
  47. var label = new Label("Variant limit exceeded: Hover for more info")
  48. {
  49. tooltip = ShaderKeyword.kVariantLimitWarning,
  50. name = "message-" + (messageType == MessageType.Warning ? "warn" : "info")
  51. };
  52. help.Add(label);
  53. return help;
  54. }
  55. public static VisualElement TryGetDeprecatedHelpBoxRow(string deprecatedTypeName, Action upgradeAction, Action dismissAction, string deprecationText = null, string buttonText = null, string labelText = null, MessageType messageType = MessageType.Warning)
  56. {
  57. if (deprecationText == null)
  58. {
  59. deprecationText = $"The {deprecatedTypeName} has new updates. This version maintains the old behavior. " +
  60. $"If you update a {deprecatedTypeName}, you can use Undo to change it back. See the {deprecatedTypeName} " +
  61. $"documentation for more information.";
  62. }
  63. if (buttonText == null)
  64. {
  65. buttonText = "Update";
  66. }
  67. if (labelText == null)
  68. {
  69. labelText = $"The {deprecatedTypeName} has new updates. This version maintains the old behavior. " +
  70. $"If you update a {deprecatedTypeName}, you can use Undo to change it back. See the {deprecatedTypeName} " +
  71. $"documentation for more information.";
  72. }
  73. Button upgradeButton = new Button(upgradeAction) { text = buttonText, tooltip = deprecationText };
  74. Button dismissButton = null;
  75. if (dismissAction != null)
  76. dismissButton = new Button(dismissAction) { text = "Dismiss" };
  77. if (dismissAction != null)
  78. {
  79. HelpBoxRow help = new HelpBoxRow(messageType);
  80. var label = new Label(labelText)
  81. {
  82. tooltip = labelText,
  83. name = "message-" + (messageType == MessageType.Warning ? "warn" : "info")
  84. };
  85. help.Add(label);
  86. help.contentContainer.Add(upgradeButton);
  87. if (dismissButton != null)
  88. help.contentContainer.Add(dismissButton);
  89. return help;
  90. }
  91. else
  92. {
  93. var box = new VisualElement();
  94. box.Add(upgradeButton);
  95. if (dismissButton != null)
  96. box.Add(dismissButton);
  97. return box;
  98. }
  99. }
  100. }
  101. }