public void GenerateTestElectricity() { connected = true; Electricity newElec = new Electricity(); ElectricityOutput(currentTick + 1, newElec); }
public void ElectricityOutput(int tick, Electricity electricity) { //Feed electrcity supply into the connected wire if (connectedWire != null) { connectedWire.ElectricityInput(tick, electricity); } }
public void ElectricityInput(int tick, Electricity electricity) { if (tick > currentTick) { currentTick = tick; suppliedElectricity = electricity; //Send event that the supply has updated OnSupplyChange.Invoke(); } //Do not pass on electricty }
public void TurnOffSupply() { supplyElectricity = false; Electricity supply = new Electricity(); supply.voltage = 0f; supply.current = 0f; supply.suppliers = allSuppliers.ToArray(); currentTick++; ElectricityOutput(currentTick, supply); OnCircuitChange.Invoke(); }
//Output electricity to this next wire/object public void ElectricityOutput(int tick, Electricity electricity) { if (currentTick == tick) { //No need to process a tick twice return; } currentTick = tick; for (int i = 0; i < connections.Count; i++) { connections[i].ElectricityInput(tick, electricity); } }
public void ElectricityInput(int tick, Electricity electricity) { if (tick > currentTick) { currentTick = tick; for (int i = 0; i < electricity.suppliers.Length; i++) { //if any of the suppliers is not in the allSuppliers list then add it: if (!allSuppliers.Contains(electricity.suppliers[i])) { allSuppliers.Add(electricity.suppliers[i]); } } } //Do not pass on electricty //TODO allow power generators to supply the charge of this Supplier }
//Feed electricity into this wire: public void ElectricityInput(int tick, Electricity electricity) //TODO A struct that can be passed between connections for Voltage, current etc { currentChargeInWire = electricity; //The supply found at index 0 is the actual source that has combined the resources of the other sources and //sent the actual electrcity struct. So reference that one for supplySource if (supplySource != electricity.suppliers[0]) { supplySource = electricity.suppliers[0]; supplySource.OnCircuitChange.AddListener(OnCircuitChanged); } //For testing (shows the yellow sphere gizmo that shows it is connected) if (electricity.voltage > 1f) { connected = true; } //Pass the charge on: ElectricityOutput(tick, currentChargeInWire); }
void Update() { if (supplyElectricity && connected) { tickCount += Time.deltaTime; if (tickCount > tickRate) { tickCount = 0f; currentTick++; //Supply the electricity Electricity supply = new Electricity(); supply.voltage = Voltage; supply.current = Current; //TODO Make sure the actual power supply that is sending the struct is at index 0 //If there are multiple suppliers on the network then they join together and act as one //with the supplier with the most charge and latest tick rate taking charge supply.suppliers = allSuppliers.ToArray(); ElectricityOutput(currentTick, supply); } } }
public void ElectricityOutput(int tick, Electricity electricity) { }