diff --git a/Assets/Fungus/FungusScript/Resources/Prefabs/FungusScript.prefab b/Assets/Fungus/FungusScript/Resources/Prefabs/FungusScript.prefab
index c9955b3d..c15862dd 100644
--- a/Assets/Fungus/FungusScript/Resources/Prefabs/FungusScript.prefab
+++ b/Assets/Fungus/FungusScript/Resources/Prefabs/FungusScript.prefab
@@ -43,6 +43,10 @@ MonoBehaviour:
stringTable: {fileID: 0}
activeLanguage: en
timeScale: -1
+ registerTypes:
+ - {fileID: 4900000, guid: 9c3ab7a98d51241bbb499643399fa761, type: 3}
+ registerExtensionTypes:
+ - {fileID: 4900000, guid: 2978c0ed6806b42629d2bf7d0d1f220c, type: 3}
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
diff --git a/Assets/Fungus/FungusScript/Resources/Types.meta b/Assets/Fungus/FungusScript/Resources/Types.meta
new file mode 100644
index 00000000..2d70dc30
--- /dev/null
+++ b/Assets/Fungus/FungusScript/Resources/Types.meta
@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: 57dca145d09854514a2a33ff8e42bfba
+folderAsset: yes
+timeCreated: 1459352267
+licenseType: Free
+DefaultImporter:
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Fungus/FungusScript/Resources/Types/ExtensionTypes.txt b/Assets/Fungus/FungusScript/Resources/Types/ExtensionTypes.txt
new file mode 100644
index 00000000..0897d1de
--- /dev/null
+++ b/Assets/Fungus/FungusScript/Resources/Types/ExtensionTypes.txt
@@ -0,0 +1,2 @@
+Fungus.FungusScriptExtensions, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+
diff --git a/Assets/Fungus/FungusScript/Resources/Types/ExtensionTypes.txt.meta b/Assets/Fungus/FungusScript/Resources/Types/ExtensionTypes.txt.meta
new file mode 100644
index 00000000..c9bf1c6f
--- /dev/null
+++ b/Assets/Fungus/FungusScript/Resources/Types/ExtensionTypes.txt.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 2978c0ed6806b42629d2bf7d0d1f220c
+timeCreated: 1459352238
+licenseType: Free
+TextScriptImporter:
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Fungus/FungusScript/Resources/Types/RegisterTypes.txt b/Assets/Fungus/FungusScript/Resources/Types/RegisterTypes.txt
new file mode 100644
index 00000000..9c6292bb
--- /dev/null
+++ b/Assets/Fungus/FungusScript/Resources/Types/RegisterTypes.txt
@@ -0,0 +1,87 @@
+Fungus.AnimatorVariable, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+Fungus.AudioSourceVariable, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+Fungus.Block, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+Fungus.BooleanVariable, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+Fungus.Character, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+Fungus.ColorVariable, 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
+Fungus.FacingDirection, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+Fungus.FloatVariable, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+Fungus.Flowchart, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+Fungus.FungusPrefs, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+Fungus.FungusScript, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+Fungus.GameObjectVariable, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+Fungus.IntegerVariable, 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.MaterialVariable, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+Fungus.MenuDialog, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+Fungus.ObjectVariable, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+Fungus.PortraitState, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+Fungus.SayDialog, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+Fungus.SpriteVariable, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+Fungus.StringVariable, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+Fungus.TextureVariable, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+Fungus.TransformVariable, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+Fungus.Variable, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+Fungus.Vector2Variable, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+Fungus.Vector3Variable, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+System.Action, System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+System.Collections.IEnumerator, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+System.IntPtr, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+System.Object, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+System.Single, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+System.Type, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+System.UInt32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+Task, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.AudioClip, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.AudioClipLoadType, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.AudioDataLoadState, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.AudioSource, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.Bounds, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.Canvas, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.Color, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.Component, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.ComputeBuffer, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.Coroutine, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.EventSystems.BaseEventData, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.EventSystems.PointerEventData, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.Font, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.FontStyle, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.GameObject, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.HorizontalWrapMode, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.Material, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.MaterialGlobalIlluminationFlags, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.Matrix4x4, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.MonoBehaviour, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.Object, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.PrimitiveType, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.Quaternion, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.Rect, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.RectTransform, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.SceneManagement.Scene, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.ScriptableObject, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.SendMessageOptions, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.Shader, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.Sprite, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.SpriteMeshType, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.SpritePackingMode, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.SpritePackingRotation, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.TextAnchor, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.TextGenerationSettings, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.TextGenerator, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.Texture, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.Texture2D, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.TextureFormat, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.Time, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.Transform, 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.UI.Image, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.UI.Slider, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.UI.Text, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.Vector2, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.Vector3, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.Vector4, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+UnityEngine.VerticalWrapMode, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
diff --git a/Assets/Fungus/FungusScript/Resources/Types/RegisterTypes.txt.meta b/Assets/Fungus/FungusScript/Resources/Types/RegisterTypes.txt.meta
new file mode 100644
index 00000000..e7ace731
--- /dev/null
+++ b/Assets/Fungus/FungusScript/Resources/Types/RegisterTypes.txt.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 9c3ab7a98d51241bbb499643399fa761
+timeCreated: 1459352229
+licenseType: Free
+TextScriptImporter:
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Fungus/FungusScript/Scripts/Editor/FungusScriptEditor.cs b/Assets/Fungus/FungusScript/Scripts/Editor/FungusScriptEditor.cs
new file mode 100644
index 00000000..444a561e
--- /dev/null
+++ b/Assets/Fungus/FungusScript/Scripts/Editor/FungusScriptEditor.cs
@@ -0,0 +1,65 @@
+using UnityEditor;
+using UnityEditorInternal;
+using UnityEngine;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.IO;
+
+namespace Fungus
+{
+
+ [CustomEditor (typeof(FungusScript))]
+ public class FungusScriptEditor : Editor
+ {
+ protected SerializedProperty registerTypesProp;
+ protected ReorderableList registerTypeList;
+
+ protected SerializedProperty registerExtensionTypesProp;
+ protected ReorderableList registerExtensionTypesList;
+
+ protected virtual void OnEnable()
+ {
+ registerTypesProp = serializedObject.FindProperty("registerTypes");
+ registerTypeList = new ReorderableList(serializedObject, registerTypesProp, true, true, true, true);
+
+ registerTypeList.drawHeaderCallback = (Rect rect) => {
+ EditorGUI.LabelField(rect, "Register Types");
+ };
+
+ registerTypeList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => {
+ Rect r = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
+ SerializedProperty element = registerTypesProp.GetArrayElementAtIndex(index);
+ EditorGUI.PropertyField(r, element, new GUIContent(""));
+ };
+
+ registerExtensionTypesProp = serializedObject.FindProperty("registerExtensionTypes");
+
+ registerExtensionTypesList = new ReorderableList(serializedObject, registerExtensionTypesProp, true, true, true, true);
+
+ registerExtensionTypesList.drawHeaderCallback = (Rect rect) => {
+ EditorGUI.LabelField(rect, "Register Extension Types");
+ };
+
+ registerExtensionTypesList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => {
+ Rect r = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
+ SerializedProperty element = registerExtensionTypesProp.GetArrayElementAtIndex(index);
+ EditorGUI.PropertyField(r, element, new GUIContent(""));
+ };
+ }
+
+ public override void OnInspectorGUI()
+ {
+ base.OnInspectorGUI();
+
+ serializedObject.Update();
+
+ registerTypeList.DoLayoutList();
+ registerExtensionTypesList.DoLayoutList();
+
+ serializedObject.ApplyModifiedProperties();
+ }
+ }
+
+}
diff --git a/Assets/Fungus/FungusScript/Thirdparty/FungusExtensions/RegisterFungusTypes.cs.meta b/Assets/Fungus/FungusScript/Scripts/Editor/FungusScriptEditor.cs.meta
similarity index 76%
rename from Assets/Fungus/FungusScript/Thirdparty/FungusExtensions/RegisterFungusTypes.cs.meta
rename to Assets/Fungus/FungusScript/Scripts/Editor/FungusScriptEditor.cs.meta
index 4ad178ed..0b17c174 100644
--- a/Assets/Fungus/FungusScript/Thirdparty/FungusExtensions/RegisterFungusTypes.cs.meta
+++ b/Assets/Fungus/FungusScript/Scripts/Editor/FungusScriptEditor.cs.meta
@@ -1,6 +1,6 @@
fileFormatVersion: 2
-guid: becdb52a4ba7c476d89008442adfc3ef
-timeCreated: 1458920418
+guid: f4acd124c87104104a6b71bff9b35b0b
+timeCreated: 1459332962
licenseType: Free
MonoImporter:
serializedVersion: 2
diff --git a/Assets/Fungus/FungusScript/Scripts/Editor/LuaBindingsEditor.cs b/Assets/Fungus/FungusScript/Scripts/Editor/LuaBindingsEditor.cs
index b826942c..c36dbb31 100644
--- a/Assets/Fungus/FungusScript/Scripts/Editor/LuaBindingsEditor.cs
+++ b/Assets/Fungus/FungusScript/Scripts/Editor/LuaBindingsEditor.cs
@@ -148,12 +148,6 @@ namespace Fungus
ShowBindingMemberInfo();
- // Update the bound types on every tick to make sure they're up to date.
- // This could be a bit heavy on performance if the bound object list is long, but
- // I couldn't get it to work reliably by only updating when the list has changed.
- // This only happens when inspecting a Fungus Bindings component so I think it'll be ok.
- PopulateBoundTypes();
-
serializedObject.ApplyModifiedProperties();
}
@@ -345,7 +339,7 @@ namespace Fungus
///
/// Update the list of bound types on the LuaBindings object.
///
- protected virtual void PopulateBoundTypes()
+ protected virtual void PopulateUserDataTypes()
{
LuaBindings luaBindings = target as LuaBindings;
@@ -367,17 +361,12 @@ namespace Fungus
}
}
- // Store the final list of types in the luaBindings object
- SerializedProperty boundTypesProp = serializedObject.FindProperty("boundTypes");
- boundTypesProp.ClearArray();
- int index = 0;
- foreach (System.Type t in typeSet)
- {
- boundTypesProp.InsertArrayElementAtIndex(index);
- SerializedProperty element = boundTypesProp.GetArrayElementAtIndex(index);
- element.stringValue = t.AssemblyQualifiedName;
- index++;
- }
+ string s = "";
+ foreach (System.Type t in typeSet)
+ {
+ s += t.AssemblyQualifiedName + "\n";
+ }
+ Debug.Log(s);
}
///
diff --git a/Assets/Fungus/FungusScript/Scripts/Editor/MenuItems.cs b/Assets/Fungus/FungusScript/Scripts/Editor/MenuItems.cs
index c04f1cb5..64b6433d 100644
--- a/Assets/Fungus/FungusScript/Scripts/Editor/MenuItems.cs
+++ b/Assets/Fungus/FungusScript/Scripts/Editor/MenuItems.cs
@@ -45,7 +45,7 @@ namespace Fungus
EditorGUIUtility.PingObject(asset);
}
}
-
+
///
/// Spawns a prefab in the scene based on it's filename in a Resources folder in the project.
/// If centerInScene is true then the object will be placed centered in the view window with z = 0.
@@ -84,6 +84,17 @@ namespace Fungus
return go;
}
+
+ ///
+ /// Create new asset from type with unique name at
+ /// selected folder in project window. Asset creation can be cancelled by pressing
+ /// escape key when asset is initially being named.
+ ///
+ /// Type of scriptable object.
+ public static void CreateAsset() where T : ScriptableObject {
+ var asset = ScriptableObject.CreateInstance();
+ ProjectWindowUtil.CreateAsset(asset, typeof(T).Name + ".asset");
+ }
}
}
diff --git a/Assets/Fungus/FungusScript/Scripts/FungusScript.cs b/Assets/Fungus/FungusScript/Scripts/FungusScript.cs
index 3e023912..a671fa51 100644
--- a/Assets/Fungus/FungusScript/Scripts/FungusScript.cs
+++ b/Assets/Fungus/FungusScript/Scripts/FungusScript.cs
@@ -97,6 +97,18 @@ namespace Fungus
[Tooltip("Time scale factor to apply when running Lua scripts. If negative then uses the same values as the standard Time class.")]
public float timeScale = -1f;
+ ///
+ /// A text file listing the c# types that can be accessed from Lua.
+ ///
+ [HideInInspector]
+ public List registerTypes = new List();
+
+ ///
+ /// A text file listing the c# extension types that can be accessed from Lua.
+ ///
+ [HideInInspector]
+ public List registerExtensionTypes = new List();
+
///
/// Instance of remote debugging service when debugging option is enabled.
///
@@ -134,12 +146,11 @@ namespace Fungus
// See the MoonSharp documentation for details.
interpreter = new Script(CoreModules.Preset_Complete);
- RegisterLuaScriptFiles();
- RegisterCLRTypes();
- RegisterFungus();
- RegisterCLRClassObjects();
- RegisterBindings();
- LoadStringTable();
+ InitLuaScriptFiles();
+ InitTypes();
+ InitCustomObjects();
+ InitBindings();
+ InitStringTable();
if (remoteDebugger)
{
@@ -152,75 +163,98 @@ namespace Fungus
///
/// Register all Lua files in the project so they can be accessed at runtime.
///
- protected virtual void RegisterLuaScriptFiles()
+ protected virtual void InitLuaScriptFiles()
{
object[] result = Resources.LoadAll("Lua", typeof(TextAsset));
interpreter.Options.ScriptLoader = new FungusScriptLoader(result.OfType());
}
///
- /// Registers a commonly used subset of Unity types for Lua interop.
- /// To register more types externally to this class, register them in the Awake method of any
- /// monobehavior in your scene.
+ /// Registers all listed c# types for interop with Lua.
+ /// You can also register types directly in the Awake method of any
+ /// monobehavior in your scene using UserData.RegisterType() directly.
///
- protected virtual void RegisterCLRTypes()
+ protected virtual void InitTypes()
{
- // Core types needed by FungusScript
- UserData.RegisterType();
- UserData.RegisterType();
- UserData.RegisterType();
- UserData.RegisterType();
- UserData.RegisterType();
- UserData.RegisterType();
- UserData.RegisterType();
-
- // Monobehaviors and other Unity.Objects
- UserData.RegisterType();
- UserData.RegisterType();
- UserData.RegisterType();
- UserData.RegisterType();
- UserData.RegisterType();
- UserData.RegisterType();
- UserData.RegisterType();
- UserData.RegisterType();
-
- // Value types
- UserData.RegisterType();
- UserData.RegisterType();
- UserData.RegisterType();
- UserData.RegisterType();
- UserData.RegisterType();
- UserData.RegisterType