Example #1
0
 //See if there is charge in the wire:
 private void CheckState()
 {
     if (currentChargeInWire.suppliers.Length == 0)
     {
         if (supplySource != null)
         {
             //Wire is broken, leave wire discharged and remove the event
             supplySource.OnCircuitChange.RemoveListener(OnCircuitChanged);
             connected    = false;
             supplySource = null;
         }
     }             //else its all good, leave as is
 }
Example #2
0
        //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);
        }