// ----------------------------------------------------------------------
        // Deletes all dynamic message handler ports that are not connected.
        public void RemoveUnusedPorts(iCS_EditorObject node)
        {
            var ports = node.BuildListOfChildPorts(p => p.IsProposedDataPort || p.IsDynamicDataPort);

            for (int i = 0; i < ports.Length; ++i)
            {
                var p = ports[i];
                if (!IsPortConnected(p))
                {
                    DestroyInstance(p);
                }
            }
        }
예제 #2
0
        // ===================================================================
        /// Adjust the port index of the given node.
        ///
        /// @param node The node that needs to reorganize the port indexes.
        ///
        public static void AdjustPortIndexes(iCS_EditorObject node)
        {
            // -- Assure continuous port index for data ports. --
            if (!node.IsKindOfFunction)
            {
                var dataPorts = node.BuildListOfChildPorts(p => p.IsDataPort && !p.IsTargetOrSelfPort && !p.IsReturnPort);
                Array.Sort(dataPorts,
                           (x, y) => {
                    if (x.PortSpec == PortSpecification.Parameter &&
                        y.PortSpec != PortSpecification.Parameter)
                    {
                        return(-1);
                    }
                    if (x.PortSpec != PortSpecification.Parameter &&
                        y.PortSpec == PortSpecification.Parameter)
                    {
                        return(1);
                    }
                    return(x.PortIndex - y.PortIndex);
                }
                           );
                for (int i = 0; i < dataPorts.Length; ++i)
                {
                    dataPorts[i].PortIndex = i;
                }
            }

            // -- Assure continuous port index for enable ports. --
            var enablePorts = node.BuildListOfChildPorts(p => p.IsEnablePort);

            Array.Sort(enablePorts, (x, y) => x.PortIndex - y.PortIndex);
            for (int i = 0; i < enablePorts.Length; ++i)
            {
                enablePorts[i].PortIndex = i + (int)iCS_PortIndex.EnablesStart;
            }
        }
예제 #3
0
        // ----------------------------------------------------------------------
        public iCS_EditorObject FindPortWithSourceEndPoint(iCS_EditorObject node, iCS_EditorObject srcEP)
        {
            // Get all ports that match request (supports connection loops).
            var matchingPorts = node.BuildListOfChildPorts(p => p.SegmentProducerPort == srcEP);

            if (matchingPorts.Length == 0)
            {
                return(null);
            }
            if (matchingPorts.Length == 1)
            {
                return(matchingPorts[0]);
            }
            foreach (var p in matchingPorts)
            {
                if (p.IsOutputPort)
                {
                    return(p);
                }
            }
            Debug.LogWarning("iCanScript: Invalid circular connection of input ports on: " + node.DisplayName);
            return(matchingPorts[0]);
        }