require("objname"). The Objects list accepts any UnityEngine.Object, not just MonoBehaviours. To pick a specific MonoBehaviour component, you can right-click on the Inspector Tab of the selected GameObject and pick Properties. A standalone window will pop up for you to drag the specifc MonoBehavior from.
- Namespaces: You can map C# namespaces to JS module here. (i.e.
"UnityEngine.UIElements" => "UnityEngine/UIElements")
- Static Classes: Map C# static classes to JS module. (i.e.
"Unity.Mathematics.math" => "math")
ScriptEngine provides the following security settings for you to set in the Inspector.
- Catch .Net Exceptions
- Allow Reflection
- Memory Limit
- Recursion Depth
These are some of the security settings exposed directly from Jint. To set more granular security measures such as Member Accessor & TypeResolver, you can do so during the
OnPostInit event (refer to the event API below).
You can add additional USS Style Sheets here and also tweak screen breakpoints.
Here, you can set the OneJS WorkingDir paths for Editor and runtime. The Bundler will use this info for automatic bundling and extraction. The only thing you need to make sure is that the 2 paths are not the same.
Also under MISC, you can set what scripts you want to load before and after every engine reload.
ScriptEngine exposes some public APIs for you to use from code.
public string WorkingDir; // The OneJS Working Directory public Engine JintEngine; // Internal Jint Engine public Document Document; // Document object (`document` in js) public Dom DocumentBody; // document.body public DateTime StartTime // Engine Start time. Reset on every reload.
public event Action OnPostInit; // Happens after every ScriptEngine reload public event Action OnReload; // Happens when ScriptEngine is just about to reload
public void RunScript(string scriptPath); // Run a script as is public void ReloadAndRunScript(string scriptPath); // Reloads the ScriptEngine and then run a script public void RegisterReloadHandler(Action handler); // Sub to the OnReload event and will automatically unsub during reload. Useful for the Live Reload workflow