/// <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);
            }
        }
Example #2
0
        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);
        }