public State ReadState() { var state = new State { version = 4 }; state.staticLocations.metaPanel = SerializeTransform(metaPanel.transform); state.staticLocations.shipThrottle = SerializeTransform(shipThrottle.transform); state.staticLocations.srvThrottle = SerializeTransform(srvThrottle.transform); state.staticLocations.shipJoystick = SerializeTransform(shipJoystick.transform); state.staticLocations.srvJoystick = SerializeTransform(srvJoystick.transform); state.staticLocations.shipPowerDeliveryPanel = SerializeTransform(shipPowerDeliveryPanel.transform); state.staticLocations.srvPowerDeliveryPanel = SerializeTransform(srvPowerDeliveryPanel.transform); state.staticLocations.sixDofController = SerializeTransform(sixDofController.transform); state.staticLocations.mapPlaneController = SerializeTransform(mapPlaneController.transform); state.controlButtons = ReadControlButtons(root.GetComponentsInChildren <ControlButton>(true)).ToArray(); var savedSettings = new ReadableSettings(); var settings = cockpitSettings.GetSettings(); savedSettings.SetBool("joystick.enabled", settings.joystickEnabled); savedSettings.SetBool("throttle.enabled", settings.throttleEnabled); savedSettings.SetBool("sixDofController.enabled", settings.sixDofControllerEnabled); savedSettings.SetBool("powerDistributionPanel.enabled", settings.powerDistributionPanelEnabled); state = savedSettings.Write(state); return(state); }
/** * Read the settings from state */ public static ReadableSettings Read(State state) { var settings = new ReadableSettings(); if (state.booleanSettings != null) { foreach (var boolSetting in state.booleanSettings) { settings.boolSettings[boolSetting.name] = boolSetting.value; } } return(settings); }
public void ApplyState(State state) { ApplyTransform(metaPanel.transform, state.staticLocations.metaPanel); ApplyTransform(shipThrottle.transform, state.staticLocations.shipThrottle); ApplyTransform(srvThrottle.transform, state.staticLocations.srvThrottle); ApplyTransform(shipJoystick.transform, state.staticLocations.shipJoystick); ApplyTransform(srvJoystick.transform, state.staticLocations.srvJoystick); if (state.version >= 1) { ApplyTransform(sixDofController.transform, state.staticLocations.sixDofController); } if (state.version >= 2) { ApplyTransform(mapPlaneController.transform, state.staticLocations.mapPlaneController); } if (state.version >= 3) { ApplyTransform(shipPowerDeliveryPanel.transform, state.staticLocations.shipPowerDeliveryPanel); ApplyTransform(srvPowerDeliveryPanel.transform, state.staticLocations.srvPowerDeliveryPanel); } foreach (var controlButton in state.controlButtons) { AddControlButton(controlButton); } var savedSettings = ReadableSettings.Read(state); cockpitSettings.ChangeSettings(settings => { settings.joystickEnabled = savedSettings.GetBool("joystick.enabled").GetValueOrDefault(settings.joystickEnabled); settings.throttleEnabled = savedSettings.GetBool("throttle.enabled").GetValueOrDefault(settings.throttleEnabled); settings.sixDofControllerEnabled = savedSettings.GetBool("sixDofController.enabled").GetValueOrDefault(settings.sixDofControllerEnabled); settings.powerDistributionPanelEnabled = savedSettings.GetBool("powerDistributionPanel.enabled").GetValueOrDefault(settings.powerDistributionPanelEnabled); }); }