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> /// <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> /// </summary>
protected virtual void InitBindings() protected virtual void InitBindings()
{ {
LuaBindings[] bindings = GameObject.FindObjectsOfType<LuaBindings>(); LuaBindingsBase[] bindings = GameObject.FindObjectsOfType<LuaBindingsBase>();
foreach (LuaBindings binding in bindings) foreach (LuaBindingsBase binding in bindings)
{ {
binding.AddBindings(interpreter.Globals); binding.AddBindings(interpreter.Globals);
} }

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

@ -9,11 +9,24 @@ using MoonSharp.Interpreter;
namespace Fungus 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> /// <summary>
/// Component which manages a list of bound objects to be accessed in Lua scripts. /// Component which manages a list of bound objects to be accessed in Lua scripts.
/// </summary> /// </summary>
[ExecuteInEditMode] [ExecuteInEditMode]
public class LuaBindings : MonoBehaviour public class LuaBindings : LuaBindingsBase
{ {
/// <summary> /// <summary>
/// Represents a single Unity object (+ optional component) bound to a string key. /// Represents a single Unity object (+ optional component) bound to a string key.
@ -53,7 +66,7 @@ namespace Fungus
/// <summary> /// <summary>
/// Add all declared bindings to the globals table. /// Add all declared bindings to the globals table.
/// </summary> /// </summary>
public virtual void AddBindings(Table globals) public override void AddBindings(Table globals)
{ {
Table bindingsTable = null; Table bindingsTable = null;
if (tableName == "") if (tableName == "")

Loading…
Cancel
Save