// 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);
        }
    }
Esempio n. 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);
                }
            }
        }
Esempio n. 3
0
        protected override void CircuitLogicUpdate()
        {
            var ChildInputs = GetComponentsInChildren <CircuitInput>();

            if (!this.Inputs[2].On && IIC != null)
            {
                StuffDeleter.DestroyIIConnection(IIC);
                IIC = null;
            }

            if (GetComponentsInChildren <Wire>().Length < 1 && this.Inputs[2].On)
            {
                InputInputConnection inputInputConnection = Instantiate(Prefabs.Wire, base.transform).AddComponent <InputInputConnection>();
                inputInputConnection.Input1 = ChildInputs[0];
                inputInputConnection.Input2 = ChildInputs[1];
                inputInputConnection.DrawWire();
                inputInputConnection.unbreakable = true;
                StuffConnector.LinkConnection(inputInputConnection);
                IIC = inputInputConnection;
            }
        }