protected override void UpdateModule()
    {
        bool hasPower = !inputPower.voltage.IsZero();

        if (hasPower)
        {
            if (!inputLocalRemote.value)
            {
                receivedSwitchPulseSignal = inputRemoteSwitch.value;
            }
            else
            {
                receivedSwitchPulseSignal = inputLocalSwitch.value;
            }

            float width = switchSignalReader.ReadWidth(receivedSwitchPulseSignal, Time.deltaTime);
            if (width > 0.1f && width < 0.3f)
            {
                isOn = true;
            }
            else if (width >= 0.3f)
            {
                isOn = false;
            }
        }

        ElectricalPort.Transfer(inputPower, outputPower, isOn);
        outputSwitchState.value = isOn;
        if (hasPower)
        {
            outputCloseIndicator.value = isOn;
            outputOpenIndicator.value  = !isOn;
        }
        else
        {
            outputCloseIndicator.value = false;
            outputOpenIndicator.value  = false;
        }

        if (hasPower)
        {
            //Update Meters
            if (meter != null)
            {
                meter.text = ReadingsFormatter.Format(outputPower.current.magnitude);
            }
        }
        else
        {
            //Update Meters
            if (meter != null)
            {
                meter.text = "";
            }
        }
    }
Exemple #2
0
    protected override void UpdateModule()
    {
        switch (powerType)//change power type
        {
        case PowerType.None:
            if (!inputPower.voltage.IsZero())
            {
                StartCoroutine(SwitchToInputPower(0.5f));
            }
            break;

        case PowerType.InputPower:
            if (inputPower.voltage.IsZero())
            {
                StartCoroutine(SwitchToBackupPower());
            }
            break;

        case PowerType.BackupPower:
            if (!inputPower.voltage.IsZero())
            {
                StartCoroutine(SwitchToInputPower(2f));
            }
            break;

        default: break;
        }

        if (powerType == PowerType.InputPower)
        {
            ElectricalPort.Transfer(inputPower, outputPower, !switching);
        }
        else if (powerType == PowerType.BackupPower)
        {
            ElectricalPort.Transfer(inputBackupPower, outputPower, !switching);
        }
    }
    protected override void UpdateModule()
    {
        bool hasPower = !inputPower.voltage.IsZero();

        if (hasPower && !groundClosed)//Process switching only when powered on
        {
            if (!inputLocalRemote.value)
            {
                receivedSwitchPulseSignal = inputRemoteSwitch.value;
            }
            else
            {
                receivedSwitchPulseSignal = inputSwitch.value;
            }


            float width = switchSignalReader.ReadWidth(receivedSwitchPulseSignal, Time.deltaTime);
            if (width > 0.1f && width < 0.3f)
            {
                StartCoroutine("OpenRoutine");
            }
            else if (width >= 0.3f)
            {
                StartCoroutine("CloseRoutine");
            }
            safeScreen.SetActive(true);
        }
        else if (!hasPower)
        {
            safeScreen.SetActive(false);
        }

        ElectricalPort.Transfer(inputPower, outputPower, isOn);
        outputSwitchState.value = isOn;

        if (hasPower)
        {
            outputCloseIndicator.value = isOn;
            outputOpenIndicator.value  = !isOn;

            outputGroundCloseIndicator.value = groundClosed;
            outputGroundOpenIndicator.value  = !groundClosed;
        }
        else
        {
            outputCloseIndicator.value = false;
            outputOpenIndicator.value  = false;

            outputGroundCloseIndicator.value = false;
            outputGroundOpenIndicator.value  = false;
        }

        if (inputVoltageMeter != null)
        {
            float volDisplay = inputPower.voltage.magnitude * phaseToWire;
            if (volDisplay > 1000)
            {
                inputVoltageMeter.text = (volDisplay / 1000f).ToString("f1") + "kV";
            }
            else
            {
                inputVoltageMeter.text = volDisplay.ToString("f0") + "V";
            }
        }

        if (hasPower)
        {
            //Update Meters
            if (triphaseMeter1 != null)
            {
                triphaseMeter1.text = ReadingsFormatter.Format(outputPower.current.magnitude);
            }
            if (triphaseMeter2 != null)
            {
                triphaseMeter2.text = ReadingsFormatter.Format(outputPower.current.magnitude);
            }
            if (triphaseMeter3 != null)
            {
                triphaseMeter3.text = ReadingsFormatter.Format(outputPower.current.magnitude);
            }
        }
        else
        {
            //Update Meters
            if (triphaseMeter1 != null)
            {
                triphaseMeter1.text = "";
            }
            if (triphaseMeter2 != null)
            {
                triphaseMeter2.text = "";
            }
            if (triphaseMeter3 != null)
            {
                triphaseMeter3.text = "";
            }
        }
    }