The second one is probably closest to what you want. I'm assuming AMethod() is a method in the same script that calls Lua.RegisterFunction(). A few notes:
1. To avoid the potential of typos in strings, use the nameof() function. The Dialogue System carefully uses strings instead of nameof() because it still supports older Unity versions that don't have C# 6.0's nameof() function.
Code: Select all
Lua.RegisterFunction(nameof(AMethod), this, SymbolExtensions.GetMethodInfo(() => AMethod()));
2. If you're putting this script on the Dialogue Manager, use the Awake() method and
don't unregister the function in OnDisable():
Code: Select all
void Awake()
{
Lua.RegisterFunction(nameof(AMethod), this, SymbolExtensions.GetMethodInfo(() => AMethod()));
}
If you're putting the script on a GameObject that only appears in a specific scene and disappears when the scene is unloaded, you can use OnEnable() and OnDisable():
Code: Select all
void OnEnable()
{
Lua.RegisterFunction(nameof(AMethod), this, SymbolExtensions.GetMethodInfo(() => AMethod()));
}
void OnDisable()
{
Lua.UnregisterFunction(nameof(AMethod));
}
You register functions with Lua globally. You can't register the same function name (e.g., "AMethod") for MapA and MapB. However, you can register them under different names. Say GameObjects MapA and MapB both have the same script named Map that has a method named Method(). Then you can do this to register MapA.Method as "AMethod" and MapB.Method as "BMethod":
Code: Select all
void OnEnable()
{
Lua.RegisterFunction(gameObject.name + nameof(Method), this, SymbolExtensions.GetMethodInfo(() => Method()));
}
void OnDisable()
{
Lua.UnregisterFunction(gameObject.name + nameof(Method));
}