uLua v3.0.0
A Lua Modding Framework for Unity.
uLua.LuaMonoBehaviour Class Reference

MonoBehaviour script exposed to Lua. You may use this class as a base for your API game objects. More...

Public Member Functions

void Expose ()
 Exposes the object to Lua. More...
 
DynValue InvokeLua (string functionName, params object[] args)
 Invokes a Lua callback function. More...
 
void Expose ()
 Exposes the object to Lua.
 

Protected Member Functions

virtual void Awake ()
 Exposes the game object to Lua if ExposeOn is set to 'Awake'. More...
 
virtual void OnDestroy ()
 Invokes the OnExit callback and removes the object from Lua. More...
 
virtual void OnEnable ()
 Exposes the game object to Lua if ExposeOn is set to 'OnEnable'. More...
 
virtual void OnExpose ()
 Scriptable method called when an object is exposed to Lua. More...
 
virtual void Start ()
 Exposes the game object to Lua if ExposeOn is set to 'Start'. More...
 

Properties

DynValue this[DynValue key] [get, set]
 Returns a dynamic value indexed by a dynamic value Key.
 
DynValue this[string key] [get, set]
 Returns a dynamic value indexed by a string key.
 
bool EnableObjectScript [get, set]
 Indicates whether the object script is enabled for this object.
 
ExposeTarget ExposeTarget [get, set]
 Indicates when this object will be exposed to Lua.
 
LuaMonoBehaviour LuaParent [get, set]
 Use to access/set the parent of an object.
 
bool IsExposed [get]
 Tracks if an object has been exposed to Lua.
 
string LuaHandle [get]
 Returns a unique handle of a Lua object.
 
string LuaName [get, set]
 Use to access the name of an object.
 
- Properties inherited from uLua.Core.ILuaObject
DynValue this[DynValue key] [get, set]
 Returns a dynamic value indexed by a dynamic value Key. More...
 
DynValue this[string key] [get, set]
 Returns a dynamic value indexed by a string key. More...
 
LuaMonoBehaviour LuaParent [get, set]
 Use to access/set the parent of an object. More...
 
bool IsExposed [get]
 Tracks if an object has been exposed to Lua. More...
 
string LuaHandle [get]
 Returns a unique handle of a Lua object.
 
string LuaName [get]
 Use to access the name of an object. More...
 

Detailed Description

MonoBehaviour script exposed to Lua. You may use this class as a base for your API game objects.

Instances of this class are exposed to Lua if configured. All public members of derived classes will be exposed to Lua. Prior to exposing an object of type uLua.LuaMonoBehaviour, the derived type T must be registered to Lua by calling API.RegisterIndexedType().

Member Function Documentation

◆ Awake()

virtual void uLua.LuaMonoBehaviour.Awake ( )
inlineprotectedvirtual

Exposes the game object to Lua if ExposeOn is set to 'Awake'.

The LuaParent object must be set prior to this method being called. Objects will not be exposed to Lua if ExposeOn is set to None. If the object is exposed here, this method will also invoke an OnLoad callback and execute a resource script for the object if EnableObjectScript is set to true.

◆ Expose()

void uLua.LuaMonoBehaviour.Expose ( )
inline

Exposes the object to Lua.

The property IsExposed can be used to check if this method has been called. The IsExposed flag cannot be reset.

Implements uLua.Core.ILuaObject.

◆ InvokeLua()

DynValue uLua.LuaMonoBehaviour.InvokeLua ( string  functionName,
params object[]  args 
)
inline

Invokes a Lua callback function.

The callback function must be implemented in a Lua script as a member of this object.

Parameters
functionNameThe name of the callback function to be called.
args(Optional) Parameters for the callback function.

◆ OnDestroy()

virtual void uLua.LuaMonoBehaviour.OnDestroy ( )
inlineprotectedvirtual

Invokes the OnExit callback and removes the object from Lua.

This method is called by Unity Engine when a game object is destroyed.

◆ OnEnable()

virtual void uLua.LuaMonoBehaviour.OnEnable ( )
inlineprotectedvirtual

Exposes the game object to Lua if ExposeOn is set to 'OnEnable'.

The LuaParent object must be set prior to this method being called. Objects will not be exposed to Lua if ExposeOn is set to None. If the object is exposed here, this method will also invoke an OnLoad callback and execute a resource script for the object if EnableObjectScript is set to true. Resource scripts are only executed for objects which are globals in Lua (i.e. LuaParent is set to null).

◆ OnExpose()

virtual void uLua.LuaMonoBehaviour.OnExpose ( )
inlineprotectedvirtual

Scriptable method called when an object is exposed to Lua.

Executes the object Lua script and invokes OnLoad by default.

◆ Start()

virtual void uLua.LuaMonoBehaviour.Start ( )
inlineprotectedvirtual

Exposes the game object to Lua if ExposeOn is set to 'Start'.

The LuaParent object must be set prior to this method being called. Objects will not be exposed to Lua if ExposeOn is set to None. If the object is exposed here, this method will also invoke an OnLoad callback and execute a resource script for the object if EnableObjectScript is set to true. Resource scripts are only executed for objects which are globals in Lua (i.e. LuaParent is set to null).