public static void Stop() { if (state == SandboxState.Inactive) { return; } stateChange = true; // Force later Scene reload by disposing it string curPath = null; if (!String.IsNullOrEmpty(Scene.Current.Path)) { curPath = Scene.CurrentPath; Scene.Current.Dispose(); } Time.TimeScale = 1.0f; // Reset time scale state = SandboxState.Inactive; DualityApp.ExecContext = DualityApp.ExecutionContext.Editor; // (Re)Load Scene if (curPath != null) { Scene.Current = ContentProvider.RequestContent <Scene>(curPath).Res; } OnLeaveSandbox(); OnSandboxStateChanged(); stateChange = false; }
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(); } // Stopp 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.ExecContext = DualityApp.ExecutionContext.Editor; // (Re)Load Scene - now in editor context Scene.SwitchTo(startScene); OnLeaveSandbox(); OnSandboxStateChanged(); stateChange = false; }
public static void Stop() { if (state == SandboxState.Inactive) { return; } stateChange = true; // Force later Scene reload by disposing it string curPath = null; if (!String.IsNullOrEmpty(Scene.Current.Path)) { curPath = Scene.CurrentPath; Scene.Current.Dispose(); } // Stopp 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.ExecContext = DualityApp.ExecutionContext.Editor; // (Re)Load Scene if (curPath != null) { Scene.SwitchTo(ContentProvider.RequestContent <Scene>(curPath)); } OnLeaveSandbox(); OnSandboxStateChanged(); stateChange = false; }
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; DualityApp.ExecContext = DualityApp.ExecutionContext.Game; } else { OnEnteringSandbox(); // Save the current scene DualityEditorApp.SaveCurrentScene(); // Force later Scene reload by disposing it string curPath = null; if (!String.IsNullOrEmpty(Scene.Current.Path)) { curPath = Scene.CurrentPath; Scene.Current.Dispose(); } state = SandboxState.Playing; DualityApp.ExecContext = DualityApp.ExecutionContext.Game; // (Re)Load Scene. if (curPath != null) Scene.SwitchTo(ContentProvider.RequestContent<Scene>(curPath), true); } OnSandboxStateChanged(); stateChange = false; return true; }
public static void Pause() { if (state != SandboxState.Playing) { return; } stateChange = true; state = SandboxState.Paused; OnPausedSandbox(); OnSandboxStateChanged(); stateChange = false; }
public static void Pause() { if (state != SandboxState.Playing) { return; } stateChange = true; state = SandboxState.Paused; DualityApp.ExecContext = DualityApp.ExecutionContext.Editor; OnPausedSandbox(); OnSandboxStateChanged(); stateChange = false; }
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(); } // Stopp 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.ExecContext = 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; }
public static void Stop() { if (state == SandboxState.Inactive) { return; } stateChange = true; // Force later Scene reload by disposing it if (!String.IsNullOrEmpty(Scene.Current.Path)) { Scene.Current.Dispose(); } // Stopp 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.ExecContext = DualityApp.ExecutionContext.Editor; // (Re)Load Scene if (startScene.Path != null) { Scene.SwitchTo(startScene); } // If it's a runtime-only / non-persistent scene, leave and re-enter it to allow objects to // re-initialize in the new execution context. else { Scene runtimeScene = Scene.Current; Scene.SwitchTo(null, true); Scene.SwitchTo(runtimeScene, true); } OnLeaveSandbox(); OnSandboxStateChanged(); stateChange = false; }
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; DualityApp.ExecContext = DualityApp.ExecutionContext.Game; } 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.ExecContext = DualityApp.ExecutionContext.Game; // (Re)Load Scene - now in playing context Scene.SwitchTo(activeScene); } OnSandboxStateChanged(); stateChange = false; return(true); }
public static void Stop() { if (state == SandboxState.Inactive) return; stateChange = true; // Force later Scene reload by disposing it string curPath = null; if (!String.IsNullOrEmpty(Scene.Current.Path)) { curPath = Scene.CurrentPath; Scene.Current.Dispose(); } Time.TimeScale = 1.0f; // Reset time scale Time.Resume(true); // Reset any previously (user-)generated time freeze events state = SandboxState.Inactive; DualityApp.ExecContext = DualityApp.ExecutionContext.Editor; // (Re)Load Scene if (curPath != null) Scene.SwitchTo(ContentProvider.RequestContent<Scene>(curPath)); OnLeaveSandbox(); OnSandboxStateChanged(); stateChange = false; }
public static void Pause() { if (state != SandboxState.Playing) return; stateChange = true; state = SandboxState.Paused; DualityApp.ExecContext = DualityApp.ExecutionContext.Editor; OnPausedSandbox(); OnSandboxStateChanged(); stateChange = false; }
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, EditorRes.GeneralRes.Msg_EnterSandboxUnsavedScene_Desc, EditorRes.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; DualityApp.ExecContext = DualityApp.ExecutionContext.Game; } else { OnEnteringSandbox(); // Save the current scene DualityEditorApp.SaveCurrentScene(); // Force later Scene reload by disposing it string curPath = null; if (!String.IsNullOrEmpty(Scene.Current.Path)) { curPath = Scene.CurrentPath; Scene.Current.Dispose(); } state = SandboxState.Playing; DualityApp.ExecContext = DualityApp.ExecutionContext.Game; // (Re)Load Scene. if (curPath != null) { Scene.Current = ContentProvider.RequestContent <Scene>(curPath).Res; } } OnSandboxStateChanged(); stateChange = false; return(true); }
// If initialization failed, the whole instance should just be discarded. internal async Task InitializeAsync() { if (state != SandboxState.Created) { throw new InvalidOperationException(); } var pipeName = "SandyBox." + Guid.NewGuid(); var pipe = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous); disposables.Add(pipe); Id = await Owner.HostStub.CreateSandbox(Name, pipeName); var procReader = new ByLineTextMessageReader(pipe) { LeaveReaderOpen = true }; disposables.Add(procReader); var procWriter = new ByLineTextMessageWriter(pipe) { LeaveWriterOpen = true }; disposables.Add(procWriter); // Wait for sandbox to start up. using (var cts = new CancellationTokenSource(5000)) { Message startedMessage = null; try { await pipe.WaitForConnectionAsync(cts.Token); startedMessage = await procReader.ReadAsync(m => m is RequestMessage rm && rm.Method == "NotifyStarted", cts.Token); } catch (OperationCanceledException) { } if (startedMessage == null) { throw new ExecutionHostException(Prompts.CannotStartExecutionHost_MissingNotifyStarted); } } // HOST var hostBuilder = new JsonRpcServiceHostBuilder(); hostBuilder.Register <HostingClientService>(); var host = hostBuilder.Build(); var serverHandler = new StreamRpcServerHandler(host); serverHandler.DefaultFeatures.Set <ISandboxContextFeature>(new SandboxContextFeature(Owner, this)); disposables.Add(serverHandler.Attach(procReader, procWriter)); // CLIENT var clientHandler = new StreamRpcClientHandler(); RpcClient = new JsonRpcClient(clientHandler); disposables.Add(clientHandler.Attach(procReader, procWriter)); SandboxStub = JsonRpcExecutionHost.ProxyBuilder.CreateProxy <ISandboxStub>(RpcClient); disposables.Reverse(); // Dispose in the reversed order. state = SandboxState.Started; }