public SocketType GetSocketType(NodeSocket socket) { if (InputSockets.Contains(socket)) { return(SocketType.Input); } return(OutputSockets.Contains(socket) ? SocketType.Output : SocketType.Unknown); }
private void Connect(NodeSocket from, IConnectable to) { if (!InputSockets.Contains(from) && !OutputSockets.Contains(from)) { return; } from.Connect(to); }
/// <summary> Adds a socket to this node </summary> /// <param name="socketName"> The name of the socket (if null or empty, it will be auto-generated) </param> /// <param name="direction"> The socket direction (Input/Output) </param> /// <param name="connectionMode"> The socket connection mode (Multiple/Override) </param> /// <param name="connectionPoints"> The socket connection points locations (if null or empty, it will automatically add two connection points to the left of and the right of the socket) </param> /// <param name="valueType"> The serialized class that holds additional socket values </param> /// <param name="canBeDeleted"> Determines if this socket is a special socket that cannot be deleted </param> /// <param name="canBeReordered"> Determines if this socket is a special socket that cannot be reordered </param> private Socket AddSocket(string socketName, SocketDirection direction, ConnectionMode connectionMode, List <Vector2> connectionPoints, Type valueType, bool canBeDeleted, bool canBeReordered = true) { if (connectionPoints == null) { connectionPoints = new List <Vector2>(GetLeftAndRightConnectionPoints()); } if (connectionPoints.Count == 0) { connectionPoints.AddRange(GetLeftAndRightConnectionPoints()); } var socketNames = new List <string>(); int counter; switch (direction) { case SocketDirection.Input: foreach (Socket socket in InputSockets) { socketNames.Add(socket.SocketName); } counter = 0; if (string.IsNullOrEmpty(socketName)) { socketName = Socket.DEFAULT_INPUT_SOCKET_NAME_PREFIX + counter; } while (socketNames.Contains(socketName)) { socketName = Socket.DEFAULT_INPUT_SOCKET_NAME_PREFIX + counter++; } var inputSocket = new Socket(this, socketName, direction, connectionMode, connectionPoints, valueType, canBeDeleted, canBeReordered); InputSockets.Add(inputSocket); return(inputSocket); case SocketDirection.Output: foreach (Socket socket in OutputSockets) { socketNames.Add(socket.SocketName); } counter = 0; if (string.IsNullOrEmpty(socketName)) { socketName = Socket.DEFAULT_OUTPUT_SOCKET_NAME_PREFIX + counter; } while (socketNames.Contains(socketName)) { socketName = Socket.DEFAULT_OUTPUT_SOCKET_NAME_PREFIX + counter++; } var outputSocket = new Socket(this, socketName, direction, connectionMode, connectionPoints, valueType, canBeDeleted, canBeReordered); OutputSockets.Add(outputSocket); return(outputSocket); default: throw new ArgumentOutOfRangeException("direction", direction, null); } }
public bool OutputChainContains(Node otherNode) { return(OutputSockets .Select(x => x.GetTargetNodes()) .Where(x => null != x) .Any(nodes => { var ns = nodes.ToArray(); return ns.Contains(otherNode) || ns.Any(x => x.OutputChainContains(otherNode)); })); }
private void AddOutputSocket() { if (!CanAutoAddOutputs || GetFreeOutputSocket() != null) { return; } var socket = new NodeSocket(); if (null != contentNode && contentNode.Outputs != null) { SetValidType(socket, contentNode.Outputs.LastOrDefault()); } SubscribeOutputSocket(socket); OutputSockets.Add(socket); }
private void OnDeleteNode() { foreach (var node in InputSockets.ToArray()) { node.Disconnect(this); } foreach (var node in OutputSockets.ToArray()) { node.Disconnect(this); } InputSockets.Clear(); OutputSockets.Clear(); if (null != root) { root.RemoveNode(this); } }
protected override void OnContentChanged(object oldContent, object newContent) { base.OnContentChanged(oldContent, newContent); contentNode = newContent as INode; if (null == contentNode) { return; } foreach (var connectedOutput in GetConnectedOutputs().Select(x => x.contentNode).Where(x => null != x)) { contentNode.OnOutputConnected(connectedOutput); } foreach (var connectedInput in GetConnectedInputs().Select(x => x.contentNode).Where(x => null != x)) { contentNode.OnOutputConnected(connectedInput); } InputSockets.Clear(); OutputSockets.Clear(); if (null != contentNode.Inputs) { InputSockets.AddRange(contentNode.Inputs .Select(x => { var socket = GetSocket(x); SubscribeInputSocket(socket); return(socket); })); } if (null != contentNode.Outputs) { OutputSockets.AddRange(contentNode.Outputs .Select(x => { var socket = GetSocket(x); SubscribeOutputSocket(socket); return(socket); })); } contentNode.PropertyChanged += ContentNodeOnPropertyChanged; CanAutoAddInputs = contentNode.AutoAddInputs; CanAutoAddOutputs = contentNode.AutoAddOutputs; AddInputSocket(); AddOutputSocket(); }
private void OutputSocketOnDisconnected(object sender, ConnectedEventArgs connectedEventArgs) { var socket = sender as NodeSocket; if (null == socket) { return; } var targets = socket.GetTargetNodes().Concat(new[] { connectedEventArgs.Other as Node }); foreach (var target in targets.Where(x => null != x && null != x.contentNode)) { contentNode.OnOutputDisconnected(target.contentNode); } if (!socket.IsConnected && CanAutoAddOutputs) { OutputSockets.Remove(socket); } AddOutputSocket(); }
public bool HasConnectedOutputs() { return(OutputSockets.Any(x => x.IsConnected)); }
public NodeSocket GetNearestFreeOutputSocket(Point point, Type type = null) { return(OutputSockets.GetNearestItem(point, x => IsCompatible(x, type))); }
public NodeSocket GetFreeOutputSocket(Type type = null) { return(OutputSockets.FirstOrDefault(x => IsCompatible(x, type))); }
public bool HasFreeOutputSocket() { return(OutputSockets.Any(IsSocketFree)); }