alelievr / NodeGraphProcessor

Node graph editor framework focused on data processing using Unity UIElements and C# 4.6
https://github.com/alelievr/NodeGraphProcessor/projects/2
MIT License
2.34k stars 387 forks source link

CustomPortBehavior from base class not respected. #216

Open rhys-vdw opened 2 years ago

rhys-vdw commented 2 years ago

e.g.

using System.Collections.Generic;
using System.Reflection;
using GraphProcessor;

public abstract class EventNode<T> : BaseNode {
  [Output("Event values", allowMultiple = true)]
  public IEnumerable<object> outputs = null;

  static PortData[] _outputPortDatas;

  public override void InitializePorts() {
    if (_outputPortDatas == null) {
      var fields = typeof(T).GetFields(BindingFlags.Public | BindingFlags.Instance);
      _outputPortDatas = new PortData[fields.Length];
      for (var i = 0; i < fields.Length; i++) {
        var field = fields[i];
        _outputPortDatas[i] = new PortData {
          displayName = field.Name,
          displayType = field.FieldType,
          identifier = field.Name
        };
      }
    }
    base.InitializePorts();
  }

  [CustomPortBehavior(nameof(outputs))]
  protected IEnumerable<PortData> GetOutputPorts(List<SerializableEdge> _) {
    foreach (var p in _outputPortDatas) {
      yield return p;
    }
  }

  // ...
}
using GraphProcessor;

[System.Serializable, NodeMenuItem("EffortStar/Events/Reload")]
class ReloadEventNode : EventNode<Reload> {
}

This just shows a single output called "Event values".

Problem is here: https://github.com/alelievr/NodeGraphProcessor/blob/644efea869124e70d0ccf29fd98594fd794cccfc/Assets/com.alelievr.NodeGraphProcessor/Runtime/Elements/BaseNode.cs#L535

Requires a BindingFlags.FlattenHierarchy to work.