/// <summary> /// Helper function called by server to change the lightState. /// It simply calls the SyncVar hook on the server, which changes /// the variable, which in turn causes the SyncVar hook on the /// client to be called. /// </summary> private void SyncLightState(BatteryLightState newState) { if (newState != lightState) { SyncLightState(lightState, newState); } }
/// <summary> /// Turns on lights based on the lightState variable. /// This is a SyncVar hook function. It is *automatically* called on the /// client when the lightState variable is changed on the server. /// This is the only place that lightState should be set directly. /// </summary> private void SyncLightState(BatteryLightState oldState, BatteryLightState newState) { lightState = newState; switch (lightState) { case BatteryLightState.NO_BATTERY: TurnOffLights(); break; case BatteryLightState.RED_FLASHING: redLight.MakeLightBlink(); break; case BatteryLightState.ORANGE_FLASHING: redLight.MakeLightStayOn(); orangeLight.MakeLightBlink(); break; case BatteryLightState.YELLOW_FLASHING: redLight.MakeLightStayOn(); orangeLight.MakeLightStayOn(); yellowLight.MakeLightBlink(); break; case BatteryLightState.GREEN_FLASHING: redLight.MakeLightStayOn(); orangeLight.MakeLightStayOn(); yellowLight.MakeLightStayOn(); greenLight.MakeLightBlink(); break; case BatteryLightState.BATTERY_FULL: redLight.MakeLightStayOn(); orangeLight.MakeLightStayOn(); yellowLight.MakeLightStayOn(); greenLight.MakeLightStayOn(); break; } }