Module Script
Management and loading of Lua files
Previously we have introduced the Para Script component. Lua files loaded through the Para Script component provide functionality comparable to Unity Engine's Mono Behaviour component and also offer the capability to serialize data. However, how can we integrate Lua files that have other functionalities, such as Lua configuration files, common basic libraries, and third-party libraries into a ParaSpace project? We refer to these types of Lua files as Module Scripts. This topic describes how to load and manage Module Scripts.
The component used to load and manage Module Scripts is called Para Script Loader, as shown in the figure below:
You can use this component in the following way:
- After attaching the Para World Root component to an object, the Para Script Loader component is automatically added.
- This component has a default configuration item and a custom configuration item.
- The default configuration item is the ParaSpace Scripts Folder field, which points to the official Module Script directory provided by ParaSpace. You can click to view the Lua files in that directory and modify them. However, before you make any changes, make sure to make a copy. This is because these Lua files may be reset or removed during SDK upgrades. For more information about official Module Scripts, see [Official Module Scripts](official Lua library offered in the SDK).
- The custom configuration item refers to the Custom Scripts Folder field. You can use this field to configure the directory path for saving custom Module Scripts of each scene. For more information about custom Module Scripts, see [Custom Module Scripts](custom Lua library).
How are module scripts stored and loaded?
Module Scripts managed by the Para Script Loader component are serialized into binary data and saved to a Unity scene when the Unity scene is being saved. After a new scene is created, a new Lua virtual machine is also created and then loads and executes the Lua files managed by the Para Script Loader component.
Precautions
After a scene is loaded, the index.lua file in the ParaSpace Scripts Folder is executed first, followed by the index.lua file in the Custom Scripts Folder. These 2 index.lua files take precedence over any Lua files managed by Para Script.
Each scene allows only one Para Script Loader instance, which is automatically attached when the Para World Root component is added.
Updated over 1 year ago