public static void RecalculateClustersFromInputs(CircuitInput[] inputs) { HashSet <InputInputConnection> IIConnections = new HashSet <InputInputConnection>(); HashSet <InputOutputConnection> IOConnections = new HashSet <InputOutputConnection>(); foreach (CircuitInput input in inputs) // the connections of the inputs of the cluster are the same as all the connections in the cluster { if (input.Cluster != null) { input.Cluster.RemoveInput(input); } // a lot of important stuff happens here! foreach (InputInputConnection connection in input.IIConnections) { connection.Renderer.enabled = true; IIConnections.Add(connection); } foreach (InputOutputConnection connection in input.IOConnections) { IOConnections.Add(connection); } } foreach (InputInputConnection connection in IIConnections) { StuffConnector.LinkInputs(connection); // LinkInputs is used because we already have the physical object, we just need the connection codeside } foreach (InputOutputConnection connection in IOConnections) { StuffConnector.LinkInputOutput(connection); } }
public void TryToConnect() { DestroySnappedConnection(); SnappingPeg OtherSnappyPeg = GetPegToSnapTo(); // I quite like the prefix "snappy" if (OtherSnappyPeg != null && OtherSnappyPeg.GetPegToSnapTo() == this) // make sure the snapping can occur both ways { SnappedConnection SnappyConnection = Instantiate(References.Prefabs.Wire).AddComponent <SnappedConnection>(); SnappyConnection.Input1 = this; SnappyConnection.Input2 = OtherSnappyPeg; SnappyConnection.DrawWire(); SnappyConnection.Initialize(); StuffConnector.LinkInputs(SnappyConnection); if (BehaviorManager.AllowedToUpdate) { SoundPlayer.PlaySoundAt(References.Sounds.ConnectionFinal, transform); } // the check is so it doesn't play on loaded pegs } }