Browse Source

Merge pull request #429 from FungusGames/bindings-register-types

Added Register Types option in Lua Bindings component
master
Chris Gregan 9 years ago
parent
commit
418ef557a1
  1. 3
      Assets/Fungus/Lua/Scripts/Editor/LuaBindingsEditor.cs
  2. 17
      Assets/Fungus/Lua/Scripts/LuaBindings.cs
  3. 34
      Assets/FungusExamples/Lua/Trigger.unity

3
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");

17
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<string> boundTypes = new List<string>();
/// <summary>
/// The list of Unity objects to be bound for access in Lua.
/// </summary>
[Tooltip("The list of Unity objects to be bound to make them accessible in Lua script.")]
public List<BoundObject> boundObjects = new List<BoundObject>();
public List<string> boundTypes = new List<string>();
/// <summary>
/// Always ensure there is at least one row in the bound objects list.
/// </summary>
@ -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)

34
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

Loading…
Cancel
Save