Browse Source

Added LuaBindingsBase to implement custom binding systems

master
chrisgregan 9 years ago
parent
commit
9b08a656df
  1. 6
      Assets/Fungus/FungusScript/Scripts/FungusScript.cs
  2. 17
      Assets/Fungus/FungusScript/Scripts/LuaBindings.cs

6
Assets/Fungus/FungusScript/Scripts/FungusScript.cs

@ -273,12 +273,12 @@ namespace Fungus
}
/// <summary>
/// Binds all gameobjects and components defined in FungusBinding objects to the global scene table.
/// Binds all gameobjects and components defined in scene LuaBindings to the global table.
/// </summary>
protected virtual void InitBindings()
{
LuaBindings[] bindings = GameObject.FindObjectsOfType<LuaBindings>();
foreach (LuaBindings binding in bindings)
LuaBindingsBase[] bindings = GameObject.FindObjectsOfType<LuaBindingsBase>();
foreach (LuaBindingsBase binding in bindings)
{
binding.AddBindings(interpreter.Globals);
}

17
Assets/Fungus/FungusScript/Scripts/LuaBindings.cs

@ -9,11 +9,24 @@ using MoonSharp.Interpreter;
namespace Fungus
{
/// <summary>
/// Base class for a component which registers Lua Bindings.
/// When FungusScript initialises, it finds all components in the scene that inherit
/// from LuaBindingsBase and calls them to add their bindings.
/// </summary>
public abstract class LuaBindingsBase : MonoBehaviour
{
/// <summary>
/// Add all declared bindings to the globals table.
/// </summary>
public abstract void AddBindings(Table globals);
}
/// <summary>
/// Component which manages a list of bound objects to be accessed in Lua scripts.
/// </summary>
[ExecuteInEditMode]
public class LuaBindings : MonoBehaviour
public class LuaBindings : LuaBindingsBase
{
/// <summary>
/// Represents a single Unity object (+ optional component) bound to a string key.
@ -53,7 +66,7 @@ namespace Fungus
/// <summary>
/// Add all declared bindings to the globals table.
/// </summary>
public virtual void AddBindings(Table globals)
public override void AddBindings(Table globals)
{
Table bindingsTable = null;
if (tableName == "")

Loading…
Cancel
Save