/// <summary> /// Initializes the scripting engine, sets up converters, etc. /// </summary> /// <returns> /// A <see cref="Task"/> that represents the operation. /// </returns> /// <remarks> /// This method is asynchronous because initialization includes loading any available /// dynamic script. <seealso cref="LoadScriptAsync(Script)"/>. /// </remarks> private async Task InitializeScriptingAsync() { // Setup global type converters LuaCustomConverters.RegisterAll(); // Create the dynamic script object Script script = new Script(); // Register "Pure" functions as callable from Lua script script.Globals[nameof(GetRotationX)] = (Func<float>)GetRotationX; script.Globals[nameof(GetRotationY)] = (Func<float>)GetRotationY; script.Globals[nameof(GetRotationZ)] = (Func<float>)GetRotationZ; script.Globals[nameof(SetRotation)] = (Action<float, float, float>)SetRotation; // Register "Unity" functions as callable from Lua script script.Globals[nameof(GetRotationUnity)] = (Func<Vector3>)GetRotationUnity; script.Globals[nameof(SetRotationUnity)] = (Action<Vector3>)SetRotationUnity; // Load the script await LoadScriptAsync(script); // Store the dynamically loaded script in the class-level variable dynamicScript = script; }
/// <summary> /// Initializes the LuaManager /// </summary> public void Initialize() { LuaCustomConverters.RegisterAll(); }