public void AddPort(BasePort port) { if (ports.ContainsKey(port.name)) { throw new ArgumentException($"Already contains port:{port.name}"); } ports[port.name] = port; port.Enable(this); onPortAdded?.Invoke(port); }
//断开连接 public void Disconnect(BasePort port) { if (port.Owner == null || !nodes.ContainsKey(port.Owner.GUID)) { return; } foreach (var connection in port.Connections.ToArray()) { Disconnect(connection); } }
public void RemovePort(BasePort port) { if (port.Owner != this) { return; } if (!ports.ContainsKey(port.name)) { throw new ArgumentException($"Not contains port:{port.name}"); } Owner.Disconnect(port); ports.Remove(port.name); onPortRemoved?.Invoke(port); }
private void InitPort() { //属性端口 foreach (FieldInfo item in ReflectionHelper.GetFieldInfos(GetType())) { if (AttributeHelper.TryGetFieldAttribute(item, out NodeValueAttribute nodeValueAttribute)) { continue; } BasePort port = null; if (AttributeHelper.TryGetFieldAttribute(item, out InputPortAttribute inputAttr)) { port = new BasePort(inputAttr.name, inputAttr.orientation, inputAttr.direction, inputAttr.capacity, item.FieldType); } if (AttributeHelper.TryGetFieldAttribute(item, out OutputPortAttribute outputAttr)) { port = new BasePort(outputAttr.name, outputAttr.orientation, outputAttr.direction, outputAttr.capacity, item.FieldType); } if (port != null) { AddPort(port); } } }
public AddPortCommand(BaseNode node, string name, BasePort.Orientation orientation, BasePort.Direction direction, BasePort.Capacity capacity, Type type = null) { this.node = node; port = new BasePort(name, orientation, direction, capacity, type); }
public RemovePortCommand(BaseNode node, BasePort port) { this.node = node; this.port = port; }