private IEnumerator WizardCoroutine() { context.diagnostics.TakeSnapshot("Start Wizard"); context.embody.activeJSON.val = false; yield return(0); SuperController.singleton.worldScale = 1f; context.embody.presetsJSON.val = "Improved Possession"; var steps = BuildSteps(); var error = false; for (var i = 0; i < steps.Count; i++) { _step = steps[i]; if (error) { statusJSON.val = $"ERROR: {_step.lastError ?? "[No error message]"} / {steps.Count}\n\n{_step.helpText}"; error = false; _step.lastError = null; } else { statusJSON.val = $"Step {i + 1} / {steps.Count}\n\n{_step.helpText}"; } // NOTE: Not strictly necessary, but allows physics to settle and ensures final leave will be invoked yield return(new WaitForSecondsRealtime(0.2f)); try { context.diagnostics.Log($"Wizard: Enter {_step}"); _step.Enter(); } catch (Exception exc) { SuperController.LogError($"Embody: Wizard {_step}.Enter failed: {exc}"); StopWizard("An error prevented the wizard from finishing"); yield break; } while (!AreAnyStartRecordKeysDown()) { ReopenIfClosed(); if (_skip) { break; } yield return(0); try { _step.Update(); } catch (Exception exc) { SuperController.LogError($"Embody: Wizard {_step}.Update failed: {exc}"); StopWizard("An error prevented the wizard from finishing"); yield break; } } ReopenIfClosed(); try { if (_skip) { _skip = false; } else { if (!_step.Apply()) { i--; error = true; } } } catch (Exception exc) { SuperController.LogError($"Embody: Wizard {_step}.Apply failed: {exc}"); StopWizard("An error prevented the wizard from finishing"); yield break; } finally { try { _step?.Leave(false); } catch (Exception exc) { SuperController.LogError($"Embody: Wizard {_step}.Leave failed: {exc}"); StopWizard("An error prevented the wizard from finishing"); } } } StopWizard("<b>All done!</b>\n\nYou can now activate Embody.\n\nYou can tweak your settings manually by pressing Back, or start this wizard again if you prefer.\n\nYou can save tweaks in your default profile in the <i>Import, Export & Default Settings</i> screen. Default settings will automatically apply whenever you load this plugin on an atom.\n\nNow, have fun living in the future!"); }