public override void Init() { try { activeJSON = new JSONStorableBool("Active", false) { isStorable = false }; var isPerson = containingAtom.type == "Person"; _scaleChangeReceiver = gameObject.AddComponent <EmbodyScaleChangeReceiver>(); _modules = new GameObject(); _modules.transform.SetParent(transform, false); _modules.SetActive(false); _context = new EmbodyContext(this, this); var diagnosticsModule = CreateModule <DiagnosticsModule>(_context); var automationModule = CreateModule <AutomationModule>(_context); var worldScaleModule = isPerson ? CreateModule <WorldScaleModule>(_context) : null; var hideGeometryModule = isPerson ? CreateModule <HideGeometryModule>(_context) : null; var offsetCameraModule = isPerson ? CreateModule <OffsetCameraModule>(_context) : null; var passengerModule = CreateModule <PassengerModule>(_context); var trackersModule = isPerson ? CreateModule <TrackersModule>(_context) : null; var snugModule = isPerson ? CreateModule <SnugModule>(_context) : null; var eyeTargetModule = isPerson ? CreateModule <EyeTargetModule>(_context) : null; var wizardModule = isPerson ? CreateModule <WizardModule>(_context) : null; _context.diagnostics = diagnosticsModule; _context.automation = automationModule; _context.worldScale = worldScaleModule; _context.hideGeometry = hideGeometryModule; _context.offsetCamera = offsetCameraModule; _context.passenger = passengerModule; _context.trackers = trackersModule; _context.snug = snugModule; _context.eyeTarget = eyeTargetModule; _context.wizard = wizardModule; if (_scaleChangeReceiver != null) { _context.scaleChangeReceiver = _scaleChangeReceiver; _scaleChangeReceiver.context = _context; containingAtom.RegisterDynamicScaleChangeReceiver(_scaleChangeReceiver); } _modules.SetActive(true); presetsJSON = InitPresets(); RegisterStringChooser(presetsJSON); _context.automation.enabledJSON.val = true; _screensManager = new ScreensManager(); var modules = _modules.GetComponents <IEmbodyModule>(); _screensManager.Add(MainScreen.ScreenName, new MainScreen(_context, modules)); if (isPerson) { _screensManager.Add(TrackersSettingsScreen.ScreenName, new TrackersSettingsScreen(_context, trackersModule)); _screensManager.Add(PassengerSettingsScreen.ScreenName, new PassengerSettingsScreen(_context, passengerModule)); _screensManager.Add(SnugSettingsScreen.ScreenName, new SnugSettingsScreen(_context, snugModule)); _screensManager.Add(HideGeometrySettingsScreen.ScreenName, new HideGeometrySettingsScreen(_context, hideGeometryModule)); _screensManager.Add(OffsetCameraSettingsScreen.ScreenName, new OffsetCameraSettingsScreen(_context, offsetCameraModule)); _screensManager.Add(WorldScaleSettingsScreen.ScreenName, new WorldScaleSettingsScreen(_context, worldScaleModule)); _screensManager.Add(EyeTargetSettingsScreen.ScreenName, new EyeTargetSettingsScreen(_context, eyeTargetModule)); _screensManager.Add(WizardScreen.ScreenName, new WizardScreen(_context, wizardModule)); _screensManager.Add(ImportExportScreen.ScreenName, new ImportExportScreen(_context)); _screensManager.Add(MoreScreen.ScreenName, new MoreScreen(_context)); _screensManager.Add(DiagnosticsScreen.ScreenName, new DiagnosticsScreen(_context, diagnosticsModule)); } else { _screensManager.Add(PassengerSettingsScreen.ScreenName, new PassengerSettingsScreen(_context, passengerModule)); } activeJSON.setCallbackFunction = val => { if (val) { Activate(); } else { Deactivate(true); } }; RegisterBool(activeJSON); activeToggle = CreateToggle(activeJSON, false); activeToggle.label = "Active"; activeToggle.backgroundColor = Color.cyan; activeToggle.labelText.fontStyle = FontStyle.Bold; var launchWizardJSON = new JSONStorableAction("LaunchWizard", () => StartCoroutine(LaunchWizard())); RegisterAction(launchWizardJSON); RegisterAction(new JSONStorableAction("ToggleActive", () => activeJSON.val = !activeJSON.val)); RegisterAction(new JSONStorableAction("Activate_Possession", () => ActivatePreset("Improved Possession"))); RegisterAction(new JSONStorableAction("Activate_LeapMotion", () => ActivatePreset("Improved Possession w/ Leap"))); RegisterAction(new JSONStorableAction("Activate_Passenger", () => ActivatePreset("Passenger"))); LoadFromDefaults(); SuperController.singleton.StartCoroutine(DeferredInit()); } catch (Exception) { enabledJSON.val = false; if (_modules != null) { Destroy(_modules); } throw; } }
public override void Init() { try { if (containingAtom.type == "SessionPluginManager" || containingAtom.type == "CoreControl") { SuperController.LogError("Embody: Cannot run as a session or scene plugin"); CreateTextField(new JSONStorableString("Error", "Embody cannot run as a session or scene plugin. Please add it to a Person atom, or an Empty.")); enabled = false; return; } activeJSON = new JSONStorableBool("Active", false) { isStorable = false }; activateOnLoadJSON = new JSONStorableBool("ActivateOnLoad", false) { isStorable = true }; RegisterBool(activateOnLoadJSON); returnToSpawnPoint = new JSONStorableStringChooser("ReturnToSpawnPoint", new List <string>(), "", "Return To Spawn Point") { popupOpenCallback = SyncSpawnPointAtoms }; SyncSpawnPointAtoms(); RegisterStringChooser(returnToSpawnPoint); var isPerson = containingAtom.type == "Person"; _scaleChangeReceiver = gameObject.AddComponent <EmbodyScaleChangeReceiver>(); _modules = new GameObject(); _modules.transform.SetParent(transform, false); _modules.SetActive(false); _context = new EmbodyContext(this, this); var diagnosticsModule = CreateModule <DiagnosticsModule>(_context); var automationModule = CreateModule <AutomationModule>(_context); var worldScaleModule = CreateModule <WorldScaleModule>(_context); var hideGeometryModule = isPerson ? CreateModule <HideGeometryModule>(_context) : null; var offsetCameraModule = isPerson ? CreateModule <OffsetCameraModule>(_context) : null; var passengerModule = CreateModule <PassengerModule>(_context); var trackersModule = isPerson ? CreateModule <TrackersModule>(_context) : null; var snugModule = isPerson ? CreateModule <SnugModule>(_context) : null; var eyeTargetModule = isPerson ? CreateModule <EyeTargetModule>(_context) : null; var wizardModule = isPerson ? CreateModule <WizardModule>(_context) : null; _context.diagnostics = diagnosticsModule; _context.automation = automationModule; _context.worldScale = worldScaleModule; _context.hideGeometry = hideGeometryModule; _context.offsetCamera = offsetCameraModule; _context.passenger = passengerModule; _context.trackers = trackersModule; _context.snug = snugModule; _context.eyeTarget = eyeTargetModule; _context.wizard = wizardModule; if (_scaleChangeReceiver != null) { _context.scaleChangeReceiver = _scaleChangeReceiver; _scaleChangeReceiver.context = _context; containingAtom.RegisterDynamicScaleChangeReceiver(_scaleChangeReceiver); } _modules.SetActive(true); presetsJSON = InitPresets(); RegisterStringChooser(presetsJSON); _context.automation.enabledJSON.val = true; _screensManager = new ScreensManager(); _screensManager.Add(MainScreen.ScreenName, new MainScreen(_context, _modulesList)); if (isPerson) { _screensManager.Add(TrackersSettingsScreen.ScreenName, new TrackersSettingsScreen(_context, trackersModule)); _screensManager.Add(PassengerSettingsScreen.ScreenName, new PassengerSettingsScreen(_context, passengerModule)); _screensManager.Add(SnugSettingsScreen.ScreenName, new SnugSettingsScreen(_context, snugModule)); _screensManager.Add(HideGeometrySettingsScreen.ScreenName, new HideGeometrySettingsScreen(_context, hideGeometryModule)); _screensManager.Add(OffsetCameraSettingsScreen.ScreenName, new OffsetCameraSettingsScreen(_context, offsetCameraModule)); _screensManager.Add(WorldScaleSettingsScreen.ScreenName, new WorldScaleSettingsScreen(_context, worldScaleModule)); _screensManager.Add(EyeTargetSettingsScreen.ScreenName, new EyeTargetSettingsScreen(_context, eyeTargetModule)); _screensManager.Add(WizardScreen.ScreenName, new WizardScreen(_context, wizardModule)); _screensManager.Add(ProfilesScreen.ScreenName, new ProfilesScreen(_context)); _screensManager.Add(MoreScreen.ScreenName, new MoreScreen(_context)); _screensManager.Add(DiagnosticsScreen.ScreenName, new DiagnosticsScreen(_context, diagnosticsModule)); } else { _screensManager.Add(PassengerSettingsScreen.ScreenName, new PassengerSettingsScreen(_context, passengerModule)); _screensManager.Add(WorldScaleSettingsScreen.ScreenName, new WorldScaleSettingsScreen(_context, worldScaleModule)); _screensManager.Add(MoreScreen.ScreenName, new MoreScreen(_context)); } activeJSON.setCallbackFunction = val => { if (val) { Activate(false); } else { Deactivate(); } }; RegisterBool(activeJSON); activeToggle = CreateToggle(activeJSON, false); activeToggle.label = "Active"; activeToggle.backgroundColor = Color.cyan; activeToggle.labelText.fontStyle = FontStyle.Bold; activeToggle.toggle.onValueChanged.AddListener(v => { if (!v) { return; } _activatedManually = true; }); _loadProfileWithPathUrlJSON = new JSONStorableUrl("ProfilePathUrl", string.Empty, url => { _loadProfileWithPathUrlJSON.valNoCallback = null; new Storage(_context).LoadProfile(url); }, SaveFormat.SaveExt, SaveFormat.SaveFolder, true) { allowFullComputerBrowse = false, allowBrowseAboveSuggestedPath = true, hideExtension = false, showDirs = true, isRestorable = false, isStorable = false, beginBrowseWithObjectCallback = jsurl => { FileManagerSecure.CreateDirectory(SaveFormat.SaveFolder); jsurl.shortCuts = FileManagerSecure.GetShortCutsForDirectory(SaveFormat.SaveFolder, false, false, true, true); } }; RegisterUrl(_loadProfileWithPathUrlJSON); _loadProfileWithPathJSON = new JSONStorableActionPresetFilePath("LoadProfileWithPath", url => { _loadProfileWithPathUrlJSON.SetFilePath(url); }, _loadProfileWithPathUrlJSON); RegisterPresetFilePathAction(_loadProfileWithPathJSON); var launchWizardJSON = new JSONStorableAction("LaunchWizard", () => StartCoroutine(LaunchWizard())); RegisterAction(launchWizardJSON); RegisterAction(new JSONStorableAction("ToggleActive", () => activeJSON.val = !activeJSON.val)); RegisterAction(new JSONStorableAction("ReinitializeIfActive", () => StartCoroutine(ReinitializeIfActiveCo()))); RegisterAction(new JSONStorableAction("Activate_Possession", () => ActivatePreset("Improved Possession"))); RegisterAction(new JSONStorableAction("Activate_LeapMotion", () => ActivatePreset("Improved Possession w/ Leap"))); RegisterAction(new JSONStorableAction("Activate_Passenger", () => ActivatePreset("Passenger"))); LoadFromDefaults(); if (containingAtom.on) { TryInitializeModuleReferences(); } SuperController.singleton.StartCoroutine(DeferredInit()); } catch (Exception) { enabledJSON.val = false; if (_modules != null) { Destroy(_modules); } throw; } }