![]() |
uLua v3.0.0
A Lua Modding Framework for Unity.
|
This MonoBehaviour sets up the API framework to your Unity scene. Add to an object in your scene and set up for use. More...
Public Member Functions | |
ScriptPackage | GetPackage (string packageName) |
Returns the ScriptPackage object for the specified package name. If the package is not found, returns a null value. More... | |
int | GetPackageCount () |
Returns the number of packages found under the script package path. | |
string | GetPackageName (int i) |
Returns the name of the package at the specified index. | |
bool | LoadPackage (string packageName) |
Public function used to load a ScriptPackage on demand. More... | |
LuaAssetBundle | GetAssetBundle (string filePath, string packageName="") |
Get a pre-loaded asset bundle from external assets. More... | |
AudioClip | GetAudioClip (string filePath, string packageName="") |
Get a pre-loaded audio clip from external assets. More... | |
string[] | GetAvailableAssets (string extension="", string packageName="") |
Get a list of available assets in the specified package. More... | |
Sprite | GetSprite (string filePath, string packageName="") |
Get a pre-loaded sprite from external assets. More... | |
TextAsset | GetTextAsset (string filePath, string packageName="") |
Get a pre-loaded text asset from external assets. More... | |
Texture2D | GetTexture2D (string filePath, string packageName="") |
Get a pre-loaded texture2D from external assets. More... | |
LuaAssetBundle | LoadAssetBundle (string filePath, string packageName="") |
Loads an asset bundle from the specified external file path. More... | |
Sprite | LoadSprite (string filePath, string packageName="") |
Loads a sprite from the specified external file path. More... | |
TextAsset | LoadTextAsset (string filePath, string packageName="") |
Loads a text asset from the specified external file path. More... | |
Texture2D | LoadTexture2D (string filePath, string packageName="") |
Loads a texture2D from the specified external file path. More... | |
Static Public Member Functions | |
static void | LoadSavedData (LuaMonoBehaviour targetObject, string index="SaveData") |
Loads table data saved for the specified object. More... | |
static void | SaveData (LuaMonoBehaviour targetObject, string index="SaveData") |
Saves table data from the specified object. More... | |
static void | Invoke (string luaEventName, params object[] args) |
Invokes a game event. More... | |
static void | RegisterEvent (string luaEventName, string handlerName="") |
Registers an event to the API. More... | |
static bool | RegisterEventHandler (string luaEventName, string handlerName, ILuaObject luaParent=null) |
Registers an event handler to be called when an event is invoked. More... | |
static void | RemoveEventHandlers (LuaMonoBehaviour luaParent) |
Removes all event handlers registered in a specific context. More... | |
static void | Log (string message) |
Logs a message to the console. More... | |
static void | LogError (string message) |
Logs an error to the console. More... | |
static void | LogWarning (string message) |
Logs a warning to the console. More... | |
static DynValue | CreateLuaTable () |
Creates a new Lua table. | |
static bool | ExecuteExternalFile (string file, bool overwriteExisting=false) |
Executes a script from the external directory. More... | |
static bool | ExecuteFile (string file, bool overwriteExisting=false) |
Executes a script from the resource directory. More... | |
static DynValue | ExecuteScript (string code, string codeFriendlyName="", bool overwriteExisting=false) |
Executes a Lua script. More... | |
static void | ExposeToLua< T > (T luaObject, LuaMonoBehaviour luaParent=null) |
Exposes an object to Lua. More... | |
static void | ExposeToLua (object targetObject, string luaName, ILuaObject luaParent=null) |
Exposes an object to Lua. More... | |
static void | RegisterIndexedType (Type type) |
Registers a type that implements the ILuaObject interface to Lua. More... | |
static void | RegisterType< T > () |
Registers a type to Lua. More... | |
This MonoBehaviour sets up the API framework to your Unity scene. Add to an object in your scene and set up for use.
Includes methods to execute Lua scripts, expose game objects to the API, and invoke events. This script invokes the SceneLoaded
event when the scene is loaded.
|
inlinestatic |
Executes a script from the external directory.
file | The Lua file to execute. The file extension must be omitted. |
overwriteExisting | (Optional) If true, the method will overwrite any previous script with the same filename. Otherwise, any previous script will be called from a hash table. |
|
inlinestatic |
Executes a script from the resource directory.
file | The Lua file to execute. The file extension must be omitted. |
overwriteExisting | (Optional) If true, the method will overwrite any previous script with the same filename. Otherwise, any previous script will be called from a hash table. |
|
static |
Executes a Lua script.
code | The Lua code to execute. |
codeFriendlyName | (Optional) A friendly name for the code, used for debugging. |
overwriteExisting | (Optional) If true, the method will overwrite any previous script with the same code. |
|
inlinestatic |
Exposes an object to Lua.
Exposes objects that do not implement the ILuaObject interface, such as MonoBehaviour.
targetObject | The object to be exposed to Lua. The generic type T must be a class. |
luaName | The name of the object in Lua. If the name is already used, a warning will be logged. |
luaParent | (Optional) The Lua parent of the object. If null, the object will be exposed as a global. |
|
inlinestatic |
Exposes an object to Lua.
Called internally by uLua.LuaMonoBehaviour. Can be called manually at any point or for objects which have ExposeTarget set to Manual.
luaObject | The object to be exposed to Lua. The generic type T must implement the ILuaObject interface. |
luaParent | The Lua parent of the object. If null, the object will be exposed as a global. |
T | : | class | |
T | : | ILuaObject |
|
inline |
Get a pre-loaded asset bundle from external assets.
This method is available as a built-in function for the Lua API.
filePath | The path to the asset bundle file |
packageName | The name of the package containing the asset bundle |
|
inline |
Get a pre-loaded audio clip from external assets.
This method is available as a built-in function for the Lua API.
filePath | The path to the audio clip file |
packageName | The name of the package containing the audio clip |
|
inline |
Get a list of available assets in the specified package.
This method is available as a built-in function for the Lua API.
extension | (Optional) The file extension to filter assets by (e.g. ".png", ".wav"). If empty, all assets will be returned. |
packageName | (Optional) The name of the package to get available assets from. |
ScriptPackage uLua.API.GetPackage | ( | string | packageName | ) |
Returns the ScriptPackage object for the specified package name. If the package is not found, returns a null value.
packageName | The name of the package. |
|
inline |
Get a pre-loaded sprite from external assets.
This method is available as a built-in function for the Lua API.
filePath | The path to the sprite file |
packageName | The name of the package containing the sprite |
|
inline |
Get a pre-loaded text asset from external assets.
This method is available as a built-in function for the Lua API.
filePath | The path to the text asset file |
packageName | The name of the package containing the text asset |
|
inline |
Get a pre-loaded texture2D from external assets.
This method is available as a built-in function for the Lua API.
filePath | The path to the texture2D file |
packageName | The name of the package containing the texture2D |
|
inlinestatic |
Invokes a game event.
This method is available as a built-in function for the Lua API. Events should registered AFTER Unity's Awake call to prevent unexpected behaviour (e.g. on Unity's scene loaded or start events).
luaEventName | The name of the event to be invoked. |
args | (Optional) Parameters for the event handler. |
|
inline |
Loads an asset bundle from the specified external file path.
This method is available as a built-in function for the Lua API.
filePath | The path to the asset bundle file |
packageName | The name of the package containing the asset bundle |
|
inline |
Public function used to load a ScriptPackage on demand.
packageName | The name of the ScriptPackage to be loaded. |
|
inlinestatic |
Loads table data saved for the specified object.
Saved data will be loaded from the SaveDataPath
under the external directory. This method is available as a built-in function for the Lua API.
targetObject | The object of which the saved data will be loaded. |
index | (Optional) The index of Object which contains the table data to be saved. Default value is "SaveData". |
|
inline |
Loads a sprite from the specified external file path.
This method is available as a built-in function for the Lua API.
filePath | The path to the sprite file |
packageName | The name of the package containing the sprite |
|
inline |
Loads a text asset from the specified external file path.
This method is available as a built-in function for the Lua API.
filePath | The path to the text asset file |
packageName | The name of the package containing the text asset |
|
inline |
Loads a texture2D from the specified external file path.
This method is available as a built-in function for the Lua API.
filePath | The path to the texture2D file |
packageName | The name of the package containing the texture2D |
|
inlinestatic |
Logs a message to the console.
Invokes the event 'LuaMessageLogged' which may be handled in Lua. This method is available as a built-in function for the Lua API.
|
inlinestatic |
Logs an error to the console.
Invokes the event 'LuaErrorLogged' which may be handled in Lua. This method is available as a built-in function for the Lua API.
|
inlinestatic |
Logs a warning to the console.
Invokes the event 'LuaWarningLogged' which may be handled in Lua. This method is available as a built-in function for the Lua API.
|
inlinestatic |
Registers an event to the API.
Events should registered AFTER Unity's Awake call to prevent unexpected behaviour (e.g. on Unity's scene loaded or start events).
luaEventName | The name of the event to be registered. |
handlerName | (Optional) The name of the event handler function. Defaults to 'On{Event}', e.g. the default even thandler for an event named 'LoadingFinished' would be 'OnLoadingFinished', |
|
inlinestatic |
Registers an event handler to be called when an event is invoked.
This method is available as a built-in function for the Lua API.
luaEventName | The name of the event. |
handlerName | The name of the event handler function. |
luaParent | (Optional) The parent object that contains the event handler implementation. If not specified, the event handler will be global. |
|
inlinestatic |
Registers a type that implements the ILuaObject interface to Lua.
Intended for use with LuaMonoBehaviour.
|
inlinestatic |
Registers a type to Lua.
Any C# or Unity type may be registered to use within the API. Use with caution.
|
inlinestatic |
Removes all event handlers registered in a specific context.
This method is available as a built-in function for the Lua API.
luaParent | The parent object that contains the event handler implementation. |
|
inlinestatic |
Saves table data from the specified object.
Data will be saved to the SaveDataPath
under the external directory. This method is available as a built-in function for the Lua API.
targetObject | The object for which the data will be saved. |
index | (Optional) The index of Object which contains the table data to be saved. Default value is "SaveData". |