CustomPortDataNode.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using GraphProcessor;
  5. using System.Linq;
  6. [System.Serializable, NodeMenuItem("Custom/PortData")]
  7. public class CustomPortData : BaseNode
  8. {
  9. [Input(name = "In Values", allowMultiple = true)]
  10. public IEnumerable< object > inputs = null;
  11. static PortData[] portDatas = new PortData[] {
  12. new PortData{displayName = "0", displayType = typeof(float), identifier = "0"},
  13. new PortData{displayName = "1", displayType = typeof(int), identifier = "1"},
  14. new PortData{displayName = "2", displayType = typeof(GameObject), identifier = "2"},
  15. new PortData{displayName = "3", displayType = typeof(Texture2D), identifier = "3"},
  16. };
  17. [Output]
  18. public float output;
  19. public override string name => "Port Data";
  20. protected override void Process()
  21. {
  22. output = 0;
  23. if (inputs == null)
  24. return ;
  25. foreach (float input in inputs)
  26. output += input;
  27. }
  28. [CustomPortBehavior(nameof(inputs))]
  29. IEnumerable< PortData > GetPortsForInputs(List< SerializableEdge > edges)
  30. {
  31. PortData pd = new PortData();
  32. foreach (var portData in portDatas)
  33. {
  34. yield return portData;
  35. }
  36. }
  37. [CustomPortInput(nameof(inputs), typeof(float), allowCast = true)]
  38. public void GetInputs(List< SerializableEdge > edges)
  39. {
  40. // inputs = edges.Select(e => (float)e.passThroughBuffer);
  41. }
  42. }