Communicating with the Editor
Any communication between the runtime and the editor is done through the Service class, accessible via the Context singleton object. For example, to display a popup message in the editor, you can use the following code:
Context.Service.PromptMessage("Hey!", "I'm a message!");
Here are some of the commonly used methods:
void BroadcastOpenedScene(): Send the entire scene to the editor. You only need to do this after programmatically adding/removing assets and blueprints to/from the scene.void Toast(ToastSeverity severity, string header, string summary, string message = null, TimeSpan duration = default): Show a toast message in the editor. Ifmessageis notnull, the user can click on the toast to see the full message.void PromptMessage(string header, string message, bool markdown = false): Show a popup message in the editor. Ifmarkdownistrue, the message will be rendered as Markdown text.UniTask<bool> PromptConfirmation(string header, string message): Show a confirmation dialog in the editor. Returnstrueif the user clicks "OK", andfalseif the user clicks "Cancel".UniTask<T> PromptStructuredDataInput<T>(string header, T structuredData = null): Show a structured data input dialog in the editor. If passed astructuredDataobject, the dialog will be pre-filled with the data. Returns the structured data object after the user clicks "OK", ornullif the user clicks "Cancel".UniTask<T> PromptStructuredDataInput<T>(string header, Action<T> structuredDataInitializer): Similar to the above, but thestructuredDataInitializerfunction is called to initialize the structured data object.void ShowProgress(string message, float progress, TimeSpan timeout = default): Show a progress bar in the editor. Theprogressvalue should be between 0 and 1. Iftimeoutis specified, the progress bar will automatically hide after the specified duration.void HideProgress(): Hide the progress bar.void NavigateToGraph(Guid graphId, Guid nodeId = default): Navigate to the specified graph in the editor. IfnodeIdis specified, the editor will select the specified node in the graph.void NavigateToPlugin(string pluginId, string port = default): Navigate to the specified plugin in the editor. Ifportis specified, the editor will navigate to the specified port of the plugin.
tip
You can safely assume Context.Service is always available in the runtime, even if the editor is closed.