diff --git a/Assets/Fungus/Thirdparty/FungusLua/Resources/Prefabs/Lua.prefab b/Assets/Fungus/Thirdparty/FungusLua/Resources/Prefabs/Lua.prefab
index f64868fe..bfd7cd1c 100644
--- a/Assets/Fungus/Thirdparty/FungusLua/Resources/Prefabs/Lua.prefab
+++ b/Assets/Fungus/Thirdparty/FungusLua/Resources/Prefabs/Lua.prefab
@@ -107,6 +107,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 4cc8a659e950044b69d7c62696c36962, type: 3}
m_Name:
m_EditorClassIdentifier:
+ allEnvironments: 0
+ luaEnvironment: {fileID: 11483650}
tableName:
registerTypes: 1
boundTypes: []
diff --git a/Assets/Fungus/Thirdparty/FungusLua/Scripts/Editor/LuaBindingsEditor.cs b/Assets/Fungus/Thirdparty/FungusLua/Scripts/Editor/LuaBindingsEditor.cs
index 0e9f0470..1817f201 100644
--- a/Assets/Fungus/Thirdparty/FungusLua/Scripts/Editor/LuaBindingsEditor.cs
+++ b/Assets/Fungus/Thirdparty/FungusLua/Scripts/Editor/LuaBindingsEditor.cs
@@ -15,8 +15,10 @@ namespace Fungus
{
protected ReorderableList boundObjectsList;
+ protected SerializedProperty allLuaEnvironmentsProp;
+ protected SerializedProperty luaEnvironmentProp;
protected SerializedProperty tableNameProp;
- protected SerializedProperty registerTypesProp;
+ protected SerializedProperty registerTypesProp;
protected SerializedProperty boundObjectsProp;
protected string bindingHelpItem = "";
@@ -24,6 +26,8 @@ namespace Fungus
protected virtual void OnEnable()
{
+ allLuaEnvironmentsProp = serializedObject.FindProperty("allEnvironments");
+ luaEnvironmentProp = serializedObject.FindProperty("luaEnvironment");
tableNameProp = serializedObject.FindProperty("tableName");
registerTypesProp = serializedObject.FindProperty("registerTypes");
boundObjectsProp = serializedObject.FindProperty("boundObjects");
@@ -140,6 +144,12 @@ namespace Fungus
{
serializedObject.Update();
+ EditorGUILayout.PropertyField(allLuaEnvironmentsProp);
+ if (!allLuaEnvironmentsProp.boolValue)
+ {
+ EditorGUILayout.PropertyField(luaEnvironmentProp);
+ }
+
EditorGUILayout.PropertyField(tableNameProp);
EditorGUILayout.PropertyField(registerTypesProp);
diff --git a/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaBindings.cs b/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaBindings.cs
index bee26ebc..1757402c 100644
--- a/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaBindings.cs
+++ b/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaBindings.cs
@@ -19,7 +19,7 @@ namespace Fungus
///
/// Add all declared bindings to the globals table.
///
- public abstract void AddBindings(Table globals);
+ public abstract void AddBindings(LuaEnvironment luaEnvironment);
}
///
@@ -39,6 +39,12 @@ namespace Fungus
public Component component;
}
+ [Tooltip("Add bindings to every Lua Environment in the scene. If false, only add bindings to a specific Lua Environment.")]
+ public bool allEnvironments = true;
+
+ [Tooltip("The specific LuaEnvironment to register the bindings in.")]
+ public LuaEnvironment luaEnvironment;
+
///
/// Name of global table variable to store bindings in. If left blank then each binding will be added as a global variable.
///
@@ -72,8 +78,18 @@ namespace Fungus
///
/// Add all declared bindings to the globals table.
///
- public override void AddBindings(Table globals)
+ public override void AddBindings(LuaEnvironment _luaEnvironment)
{
+ if (!allEnvironments &&
+ luaEnvironment != _luaEnvironment)
+ {
+ // Don't add bindings to this environment
+ return;
+ }
+
+ MoonSharp.Interpreter.Script interpreter = _luaEnvironment.Interpreter;
+ Table globals = interpreter.Globals;
+
Table bindingsTable = null;
if (tableName == "")
{
diff --git a/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaStore.cs b/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaStore.cs
index 02783c7c..b49f94bc 100644
--- a/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaStore.cs
+++ b/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaStore.cs
@@ -69,13 +69,16 @@ namespace Fungus
///
/// Callback to bind this LuaStore component with the "unity" table in a LuaEnvironment component.
///
- public override void AddBindings(Table globals)
+ public override void AddBindings(LuaEnvironment luaEnvironment)
{
if (!Init())
{
return;
}
+ MoonSharp.Interpreter.Script interpreter = luaEnvironment.Interpreter;
+ Table globals = interpreter.Globals;
+
if (globals == null)
{
Debug.LogError("Lua globals table is null");
diff --git a/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaUtils.cs b/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaUtils.cs
index ab6299ca..dd6bc8ef 100644
--- a/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaUtils.cs
+++ b/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaUtils.cs
@@ -165,16 +165,14 @@ namespace Fungus
}
///
- /// Binds all gameobjects and components defined in scene LuaBindings to the global table.
+ /// Binds all gameobjects and components defined in LuaBindings components to LuaEnvironments.
///
protected virtual void InitBindings()
{
- MoonSharp.Interpreter.Script interpreter = luaEnvironment.Interpreter;
-
LuaBindingsBase[] bindings = GameObject.FindObjectsOfType();
foreach (LuaBindingsBase binding in bindings)
{
- binding.AddBindings(interpreter.Globals);
+ binding.AddBindings(luaEnvironment);
}
}