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

TargetPropertyGUIContext.cs 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEditor.UIElements;
  4. using UnityEngine.UIElements;
  5. using UnityEditor.Graphing.Util;
  6. using UnityEditor.ShaderGraph.Drawing;
  7. namespace UnityEditor.ShaderGraph
  8. {
  9. [GenerationAPI]
  10. internal class TargetPropertyGUIContext : VisualElement
  11. {
  12. const int kIndentWidthInPixel = 15;
  13. public int globalIndentLevel { get; set; } = 0;
  14. public readonly Action graphValidation;
  15. public TargetPropertyGUIContext(Action graphValidationCallback)
  16. {
  17. graphValidation = graphValidationCallback;
  18. }
  19. public void AddProperty<T>(string label, BaseField<T> field, bool condition, EventCallback<ChangeEvent<T>> evt)
  20. {
  21. if (condition == true)
  22. {
  23. AddProperty<T>(label, field, evt);
  24. }
  25. }
  26. public void AddProperty<T>(string label, int indentLevel, BaseField<T> field, bool condition, EventCallback<ChangeEvent<T>> evt)
  27. {
  28. if (condition == true)
  29. {
  30. AddProperty<T>(label, indentLevel, field, evt);
  31. }
  32. }
  33. public void AddProperty<T>(string label, BaseField<T> field, EventCallback<ChangeEvent<T>> evt)
  34. {
  35. AddProperty<T>(label, 0, field, evt);
  36. }
  37. public void AddProperty<T>(string label, int indentLevel, BaseField<T> field, EventCallback<ChangeEvent<T>> evt)
  38. {
  39. AddProperty<T>(label, string.Empty, indentLevel, field, evt);
  40. }
  41. public void AddProperty<T>(string label, string tooltip, int indentLevel, BaseField<T> field, EventCallback<ChangeEvent<T>> evt)
  42. {
  43. if (field is INotifyValueChanged<T> notifyValueChanged)
  44. {
  45. notifyValueChanged.RegisterValueChangedCallback(evt);
  46. }
  47. var propertyLabel = new Label(label);
  48. propertyLabel.tooltip = tooltip;
  49. var propertyRow = new PropertyRow(propertyLabel);
  50. ApplyPadding(propertyRow, indentLevel);
  51. propertyRow.Add(field);
  52. this.hierarchy.Add(propertyRow);
  53. }
  54. public void AddLabel(string label, int indentLevel)
  55. {
  56. var propertyRow = new PropertyRow(new Label(label));
  57. ApplyPadding(propertyRow, indentLevel);
  58. this.hierarchy.Add(propertyRow);
  59. }
  60. public void AddHelpBox(MessageType messageType, string messageText)
  61. {
  62. var helpBox = new HelpBoxRow(messageType);
  63. helpBox.Add(new Label(messageText));
  64. this.hierarchy.Add(helpBox);
  65. }
  66. void ApplyPadding(PropertyRow row, int indentLevel)
  67. {
  68. row.Q(className: "unity-label").style.marginLeft = (globalIndentLevel + indentLevel) * kIndentWidthInPixel;
  69. }
  70. }
  71. }