Пример #1
0
 public SocketType GetSocketType(NodeSocket socket)
 {
     if (InputSockets.Contains(socket))
     {
         return(SocketType.Input);
     }
     return(OutputSockets.Contains(socket) ? SocketType.Output : SocketType.Unknown);
 }
Пример #2
0
 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);
            }
        }
Пример #4
0
 public bool InputChainContains(Node otherNode)
 {
     return(InputSockets
            .Select(x => x.GetTargetNodes())
            .Where(x => null != x)
            .Any(nodes =>
     {
         var ns = nodes.ToArray();
         return ns.Contains(otherNode) || ns.Any(x => x.InputChainContains(otherNode));
     }));
 }
Пример #5
0
 public bool HasConnectedInputs()
 {
     return(InputSockets.Any(x => x.IsConnected));
 }
Пример #6
0
 public NodeSocket GetNearestFreeInputSocket(Point point, Type type = null)
 {
     return(InputSockets.GetNearestItem(point, x => IsSocketFree(x) && IsCompatible(x, type)));
 }
Пример #7
0
 public NodeSocket GetFreeInputSocket(Type type = null)
 {
     return(InputSockets.FirstOrDefault(x => IsSocketFree(x) && IsCompatible(x, type)));
 }
Пример #8
0
 public bool HasFreeInputSocket()
 {
     return(InputSockets.Any(IsSocketFree));
 }