No Description
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.

UnitPortDescription.cs 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. namespace Unity.VisualScripting
  3. {
  4. public sealed class UnitPortDescription : IDescription
  5. {
  6. private string _label;
  7. private bool _isLabelVisible = true;
  8. internal IUnitPort portType;
  9. public EditorTexture icon
  10. {
  11. get
  12. {
  13. if (_icon == null || !_icon.IsValid())
  14. {
  15. _icon = GetIcon(portType);
  16. }
  17. return _icon;
  18. }
  19. set => _icon = value;
  20. }
  21. private EditorTexture _icon;
  22. public string fallbackLabel { get; set; }
  23. public string label
  24. {
  25. get => _label ?? fallbackLabel;
  26. set => _label = value;
  27. }
  28. public bool showLabel
  29. {
  30. get => !BoltFlow.Configuration.hidePortLabels || _isLabelVisible;
  31. set => _isLabelVisible = value;
  32. }
  33. string IDescription.title => label;
  34. public string summary { get; set; }
  35. public Func<Metadata, Metadata> getMetadata { get; set; }
  36. public void CopyFrom(UnitPortDescription other)
  37. {
  38. _label = other._label;
  39. _isLabelVisible = other._isLabelVisible;
  40. summary = other.summary;
  41. portType = other.portType ?? portType;
  42. getMetadata = other.getMetadata ?? getMetadata;
  43. }
  44. private static EditorTexture GetIcon(IUnitPort portType)
  45. {
  46. if (portType is IUnitControlPort)
  47. {
  48. return typeof(Flow).Icon();
  49. }
  50. else if (portType is IUnitValuePort)
  51. {
  52. return Icons.Type(((IUnitValuePort)portType).type);
  53. }
  54. else if (portType is IUnitInvalidPort)
  55. {
  56. return BoltCore.Resources.icons.errorState;
  57. }
  58. else
  59. {
  60. // throw new NotSupportedException();
  61. return null;
  62. }
  63. }
  64. }
  65. }