// finds all connections connected to an input or output which is a child of BoardBeingPlaced. If that connection does not have BoardBeingPlaced above it in the heirarchy, destroy it
    public static void DestroyAllWiresConnectedToBoardButNotPartOfIt(GameObject board)
    {
        CircuitInput[]  Inputs  = board.GetComponentsInChildren <CircuitInput>();
        CircuitOutput[] Outputs = board.GetComponentsInChildren <CircuitOutput>();

        // annoying InvalidOperationException protection
        List <InputInputConnection>  IIConnectionsToDestroy = new List <InputInputConnection>();
        List <InputOutputConnection> IOConnectionsToDestroy = new List <InputOutputConnection>();

        foreach (CircuitInput input in Inputs)
        {
            foreach (InputInputConnection connection in input.IIConnections)
            {
                if (!StuffConnector.IsChildOf(connection.transform, board.transform))
                {
                    IIConnectionsToDestroy.Add(connection);
                }
            }

            foreach (InputOutputConnection connection in input.IOConnections)
            {
                if (!StuffConnector.IsChildOf(connection.transform, board.transform))
                {
                    IOConnectionsToDestroy.Add(connection);
                }
            }
        }

        foreach (CircuitOutput output in Outputs)
        {
            foreach (InputOutputConnection connection in output.GetIOConnections())
            {
                if (!StuffConnector.IsChildOf(connection.transform, board.transform))
                {
                    IOConnectionsToDestroy.Add(connection);
                }
            }
        }

        foreach (InputInputConnection connection in IIConnectionsToDestroy)
        {
            StuffDeleter.DestroyIIConnection(connection);
        }
        foreach (InputOutputConnection connection in IOConnectionsToDestroy)
        {
            StuffDeleter.DestroyIOConnection(connection);
        }
    }
Beispiel #2
0
        private void DestroyInvalidWiresOnBoard(GameObject board)
        {
            foreach (var iiCon in board.GetComponents <InputInputConnection>())
            {
                if (!StuffConnecter.CanConnect(iiCon.gameObject))
                {
                    StuffDeleter.DestroyIIConnection(iiCon);
                }
            }

            foreach (var ioCon in board.GetComponents <InputOutputConnection>())
            {
                if (!StuffConnecter.CanConnect(ioCon.gameObject))
                {
                    StuffDeleter.DestroyIOConnection(ioCon);
                }
            }
        }