diff --git a/Assets/Fungus/Lua/Scripts/Editor/LuaBindingsEditor.cs b/Assets/Fungus/Lua/Scripts/Editor/LuaBindingsEditor.cs index 3bb77b28..e6f5d3cb 100644 --- a/Assets/Fungus/Lua/Scripts/Editor/LuaBindingsEditor.cs +++ b/Assets/Fungus/Lua/Scripts/Editor/LuaBindingsEditor.cs @@ -17,6 +17,7 @@ namespace Fungus protected ReorderableList boundObjectsList; protected SerializedProperty tableNameProp; + protected SerializedProperty registerTypesProp; protected SerializedProperty boundObjectsProp; protected string bindingHelpItem = ""; @@ -25,6 +26,7 @@ namespace Fungus protected virtual void OnEnable() { tableNameProp = serializedObject.FindProperty("tableName"); + registerTypesProp = serializedObject.FindProperty("registerTypes"); boundObjectsProp = serializedObject.FindProperty("boundObjects"); CreateBoundObjectsList(); } @@ -140,6 +142,7 @@ namespace Fungus serializedObject.Update(); EditorGUILayout.PropertyField(tableNameProp); + EditorGUILayout.PropertyField(registerTypesProp); EditorGUILayout.LabelField("Object Bindings"); diff --git a/Assets/Fungus/Lua/Scripts/LuaBindings.cs b/Assets/Fungus/Lua/Scripts/LuaBindings.cs index fbc1c069..bee26ebc 100644 --- a/Assets/Fungus/Lua/Scripts/LuaBindings.cs +++ b/Assets/Fungus/Lua/Scripts/LuaBindings.cs @@ -45,14 +45,18 @@ namespace Fungus [Tooltip("Name of global table variable to store bindings in. If left blank then each binding will be added as a global variable.")] public string tableName = ""; + [Tooltip("Register all CLR types used by the bound objects so that they can be accessed from Lua. If you don't use this option you will need to register these types yourself.")] + public bool registerTypes = true; + + [HideInInspector] + public List boundTypes = new List(); + /// /// The list of Unity objects to be bound for access in Lua. /// [Tooltip("The list of Unity objects to be bound to make them accessible in Lua script.")] public List boundObjects = new List(); - public List boundTypes = new List(); - /// /// Always ensure there is at least one row in the bound objects list. /// @@ -97,10 +101,13 @@ namespace Fungus Debug.LogError("Bindings table must not be null"); } - // Register types of bound object with MoonSharp - foreach (string typeName in boundTypes) + // Register types of bound objects with MoonSharp + if (registerTypes) { - LuaEnvironment.RegisterType(typeName); + foreach (string typeName in boundTypes) + { + LuaEnvironment.RegisterType(typeName); + } } for (int i = 0; i < boundObjects.Count; ++i) diff --git a/Assets/FungusExamples/Lua/Trigger.unity b/Assets/FungusExamples/Lua/Trigger.unity index 009bdde6..6134575f 100644 --- a/Assets/FungusExamples/Lua/Trigger.unity +++ b/Assets/FungusExamples/Lua/Trigger.unity @@ -306,6 +306,39 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: tableName: + registerTypes: 1 + boundTypes: + - UnityEngine.GameObject, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + - UnityEngine.PrimitiveType, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + - UnityEngine.Component, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + - System.Type, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + - System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + - System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + - UnityEngine.SendMessageOptions, UnityEngine, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + - UnityEngine.SceneManagement.Scene, UnityEngine, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + - UnityEngine.Object, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + - System.Single, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + - Fungus.Flowchart, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + - Fungus.Block, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + - UnityEngine.Vector2, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + - System.Action, System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + - Fungus.Variable, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + - Fungus.Label, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + - Fungus.Command, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + - Fungus.CommandInfoAttribute, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, + PublicKeyToken=null + - UnityEngine.Rect, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + - Fungus.SayDialog, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + - UnityEngine.AudioClip, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + - Fungus.Character, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + - UnityEngine.Sprite, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + - UnityEngine.Color, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + - UnityEngine.UI.Button, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + - UnityEngine.Canvas, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + - UnityEngine.UI.Text, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + - UnityEngine.UI.Image, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null boundObjects: - key: flowchart obj: {fileID: 913136538} @@ -313,7 +346,6 @@ MonoBehaviour: - key: saydialog obj: {fileID: 974098819} component: {fileID: 974098824} - boundTypes: [] --- !u!4 &775333279 Transform: m_ObjectHideFlags: 0