Exemple #1
0
        public static void Stop()
        {
            if (state == SandboxState.Inactive)
            {
                return;
            }
            stateChange = true;

            ContentRef <Scene> activeScene = Scene.Current;

            // Leave the current Scene
            Scene.SwitchTo(null, true);

            // Force later Scene reload by disposing it
            if (!activeScene.IsRuntimeResource)
            {
                activeScene.Res.Dispose();
            }

            // Stop all audio that might not have been taken care of manually by the user
            DualityApp.Sound.StopAll();

            Time.TimeScale = 1.0f;             // Reset time scale
            Time.Resume(true);                 // Reset any previously (user-)generated time freeze events
            state = SandboxState.Inactive;
            DualityApp.SwitchExecutionContext(DualityApp.ExecutionContext.Editor);

            // Check if the Scene we started the sandbox with is still valid, and switch back to it.
            if (startScene.IsAvailable)
            {
                Scene.SwitchTo(startScene);
            }
            // Otherwise, just switch back to the previously active Scene. This can happen if the
            // start scene was a runtime-only Scene that was active while a plugin reload occurred.
            else if (activeScene.IsAvailable)
            {
                Scene.SwitchTo(activeScene);
            }

            OnLeaveSandbox();
            OnSandboxStateChanged();
            stateChange = false;
        }
Exemple #2
0
        public static bool Play()
        {
            if (state == SandboxState.Playing)
            {
                return(true);
            }

            // If the current Scene is unsaved when entering sandbox mode, ask whether this should be done before
            if (askUnsaved && state == SandboxState.Inactive && Scene.Current.IsRuntimeResource && !Scene.Current.IsEmpty)
            {
                askUnsaved = false;
                DialogResult result = MessageBox.Show(DualityEditorApp.MainForm,
                                                      GeneralRes.Msg_EnterSandboxUnsavedScene_Desc,
                                                      GeneralRes.Msg_EnterSandboxUnsavedScene_Caption,
                                                      MessageBoxButtons.YesNoCancel,
                                                      MessageBoxIcon.Question);
                if (result == DialogResult.Cancel)
                {
                    return(false);
                }
                if (result == DialogResult.Yes)
                {
                    DualityEditorApp.SaveCurrentScene(false);
                }
            }

            stateChange = true;
            if (state == SandboxState.Paused)
            {
                OnUnpausingSandbox();
                state = SandboxState.Playing;
            }
            else
            {
                OnEnteringSandbox();

                // Save the current scene
                DualityEditorApp.SaveCurrentScene();
                ContentRef <Scene> activeScene = Scene.Current;
                startScene = activeScene;

                // Leave the current Scene
                Scene.SwitchTo(null, true);

                // Force later Scene reload by disposing it
                if (!activeScene.IsRuntimeResource)
                {
                    activeScene.Res.Dispose();
                }

                state = SandboxState.Playing;
                DualityApp.SwitchExecutionContext(DualityApp.ExecutionContext.Game);

                // (Re)Load Scene - now in playing context
                Scene.SwitchTo(activeScene);
            }

            OnSandboxStateChanged();
            stateChange = false;
            return(true);
        }