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. Ifmessage
is 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. Ifmarkdown
istrue
, the message will be rendered as Markdown text.UniTask<bool> PromptConfirmation(string header, string message)
: Show a confirmation dialog in the editor. Returnstrue
if the user clicks "OK", andfalse
if the user clicks "Cancel".UniTask<T> PromptStructuredDataInput<T>(string header, T structuredData = null)
: Show a structured data input dialog in the editor. If passed astructuredData
object, the dialog will be pre-filled with the data. Returns the structured data object after the user clicks "OK", ornull
if the user clicks "Cancel".UniTask<T> PromptStructuredDataInput<T>(string header, Action<T> structuredDataInitializer)
: Similar to the above, but thestructuredDataInitializer
function is called to initialize the structured data object.void ShowProgress(string message, float progress, TimeSpan timeout = default)
: Show a progress bar in the editor. Theprogress
value should be between 0 and 1. Iftimeout
is 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. IfnodeId
is 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. Ifport
is 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.