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

BoltFlowResources.cs 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System.Collections.Generic;
  2. using UnityEditor;
  3. namespace Unity.VisualScripting
  4. {
  5. [Plugin(BoltFlow.ID)]
  6. public sealed class BoltFlowResources : PluginResources
  7. {
  8. private BoltFlowResources(BoltFlow plugin) : base(plugin)
  9. {
  10. icons = new Icons(this);
  11. }
  12. public Icons icons { get; private set; }
  13. public override void LateInitialize()
  14. {
  15. base.LateInitialize();
  16. icons.Load();
  17. }
  18. public class Icons
  19. {
  20. public Icons(BoltFlowResources resources)
  21. {
  22. this.resources = resources;
  23. }
  24. private readonly Dictionary<UnitCategory, EditorTexture> unitCategoryIcons = new Dictionary<UnitCategory, EditorTexture>();
  25. private readonly BoltFlowResources resources;
  26. public EditorTexture graph { get; private set; }
  27. public EditorTexture unit { get; private set; }
  28. public EditorTexture flowMacro { get; private set; }
  29. public EditorTexture unitCategory { get; private set; }
  30. public EditorTexture controlPortConnected { get; private set; }
  31. public EditorTexture controlPortUnconnected { get; private set; }
  32. public EditorTexture valuePortConnected { get; private set; }
  33. public EditorTexture valuePortUnconnected { get; private set; }
  34. public EditorTexture invalidPortConnected { get; private set; }
  35. public EditorTexture invalidPortUnconnected { get; private set; }
  36. public EditorTexture coroutine { get; private set; }
  37. public void Load()
  38. {
  39. graph = typeof(FlowGraph).Icon();
  40. unit = typeof(IUnit).Icon();
  41. flowMacro = resources.LoadIcon("FlowMacro.png");
  42. unitCategory = resources.LoadIcon("UnitCategory.png");
  43. var portResolutions = new[] { new TextureResolution(9, 12), new TextureResolution(12, 24) };
  44. var portOptions = CreateTextureOptions.PixelPerfect;
  45. controlPortConnected = resources.LoadTexture("ControlPortConnected.png", portResolutions, portOptions);
  46. controlPortUnconnected = resources.LoadTexture("ControlPortUnconnected.png", portResolutions, portOptions);
  47. valuePortConnected = resources.LoadTexture("ValuePortConnected.png", portResolutions, portOptions);
  48. valuePortUnconnected = resources.LoadTexture("ValuePortUnconnected.png", portResolutions, portOptions);
  49. invalidPortConnected = resources.LoadTexture("InvalidPortConnected.png", portResolutions, portOptions);
  50. invalidPortUnconnected = resources.LoadTexture("InvalidPortUnconnected.png", portResolutions, portOptions);
  51. coroutine = resources.LoadIcon("Coroutine.png");
  52. }
  53. public EditorTexture UnitCategory(UnitCategory category)
  54. {
  55. if (category == null)
  56. {
  57. return unitCategory;
  58. }
  59. if (!unitCategoryIcons.ContainsKey(category))
  60. {
  61. var path = $"{category.name}.png";
  62. EditorTexture editorTexture = LoadSharedIcon(path, false);
  63. if (editorTexture == null)
  64. {
  65. editorTexture = unitCategory;
  66. }
  67. unitCategoryIcons.Add(category, editorTexture);
  68. }
  69. return unitCategoryIcons[category];
  70. }
  71. }
  72. }
  73. }