diff --git a/Assets/Fungus/Lua/Resources/Lua/fungus.txt b/Assets/Fungus/Lua/Resources/Lua/fungus.txt
index 3835c035..e9563d61 100644
--- a/Assets/Fungus/Lua/Resources/Lua/fungus.txt
+++ b/Assets/Fungus/Lua/Resources/Lua/fungus.txt
@@ -17,14 +17,18 @@ end
-- Returns the absolute time
-- Use this timing function to work correctly with the Lua Environment's timeScale property
-function M.time()
- return unity.luaenvironment.getTime()
+function M.gettime()
+ return unity.luautils.getTime()
end
-- Returns the delta time this frame
-- Use this timing function to work correctly with the Lua Environment's timeScale property
-function M.deltatime()
- return unity.luaenvironment.getDeltaTime()
+function M.getdeltatime()
+ return unity.luautils.getDeltaTime()
+end
+
+function M.settimescale(s)
+ unity.luautils.timeScale = s
end
-------------
@@ -33,8 +37,8 @@ end
-- Waits for a number of seconds
function M.wait(duration)
- local t = M.time()
- while (M.time() - t < duration) do
+ local t = M.gettime()
+ while (M.gettime() - t < duration) do
coroutine.yield()
end
end
@@ -43,10 +47,10 @@ end
-- Returns true if the function succeeded, or false if the timeout expired
--
function M.waitfor(fn, timeoutDuration)
- local t = M.time()
+ local t = M.gettime()
while (not fn()) do
coroutine.yield()
- if (M.time() - t > timeoutDuration) then
+ if (M.gettime() - t > timeoutDuration) then
return false
end
end
@@ -88,18 +92,18 @@ end
-- Set active language for string table
function M.setlanguage(languageCode)
- unity.luaenvironment.activeLanguage = languageCode
+ unity.luautils.activeLanguage = languageCode
end
-- Get a named string from the string table
function M.getstring(key)
- return unity.luaenvironment.GetString(key)
+ return unity.luautils.GetString(key)
end
-- Substitutes variables and localisation strings into a piece of text
-- e.g. v = 10, "Subbed value is [$v]" => "Subbed value is 10"
function M.sub(text)
- return unity.luaenvironment.substitute(text)
+ return unity.luautils.substitute(text)
end
--------------------
diff --git a/Assets/Fungus/Lua/Resources/Prefabs/LuaEnvironment.prefab b/Assets/Fungus/Lua/Resources/Prefabs/LuaEnvironment.prefab
index da5d6bbd..545dee15 100644
--- a/Assets/Fungus/Lua/Resources/Prefabs/LuaEnvironment.prefab
+++ b/Assets/Fungus/Lua/Resources/Prefabs/LuaEnvironment.prefab
@@ -9,6 +9,7 @@ GameObject:
m_Component:
- 4: {fileID: 495584}
- 114: {fileID: 11493126}
+ - 114: {fileID: 11486636}
m_Layer: 0
m_Name: LuaEnvironment
m_TagString: Untagged
@@ -28,7 +29,7 @@ Transform:
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
---- !u!114 &11493126
+--- !u!114 &11486636
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
@@ -36,15 +37,26 @@ MonoBehaviour:
m_GameObject: {fileID: 100640}
m_Enabled: 1
m_EditorHideFlags: 0
- m_Script: {fileID: 11500000, guid: ba19c26c1ba7243d2b57ebc4329cc7c6, type: 3}
+ m_Script: {fileID: 11500000, guid: c10f0b861365b42b0928858f7b086ff3, type: 3}
m_Name:
m_EditorClassIdentifier:
- remoteDebugger: 0
stringTable: {fileID: 0}
activeLanguage: en
timeScale: -1
registerTypes:
- {fileID: 4900000, guid: 9c3ab7a98d51241bbb499643399fa761, type: 3}
+--- !u!114 &11493126
+MonoBehaviour:
+ m_ObjectHideFlags: 1
+ m_PrefabParentObject: {fileID: 0}
+ m_PrefabInternal: {fileID: 100100000}
+ m_GameObject: {fileID: 100640}
+ m_Enabled: 1
+ m_EditorHideFlags: 0
+ m_Script: {fileID: 11500000, guid: ba19c26c1ba7243d2b57ebc4329cc7c6, type: 3}
+ m_Name:
+ m_EditorClassIdentifier:
+ remoteDebugger: 0
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
diff --git a/Assets/Fungus/Lua/Resources/Types/ExtensionTypes.txt b/Assets/Fungus/Lua/Resources/Types/ExtensionTypes.txt
deleted file mode 100644
index c65238fb..00000000
--- a/Assets/Fungus/Lua/Resources/Types/ExtensionTypes.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
diff --git a/Assets/Fungus/Lua/Resources/Types/ExtensionTypes.txt.meta b/Assets/Fungus/Lua/Resources/Types/ExtensionTypes.txt.meta
deleted file mode 100644
index c9bf1c6f..00000000
--- a/Assets/Fungus/Lua/Resources/Types/ExtensionTypes.txt.meta
+++ /dev/null
@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: 2978c0ed6806b42629d2bf7d0d1f220c
-timeCreated: 1459352238
-licenseType: Free
-TextScriptImporter:
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Fungus/Lua/Resources/Types/RegisterTypes.txt b/Assets/Fungus/Lua/Resources/Types/RegisterTypes.txt
index c38eab55..26b49036 100644
--- a/Assets/Fungus/Lua/Resources/Types/RegisterTypes.txt
+++ b/Assets/Fungus/Lua/Resources/Types/RegisterTypes.txt
@@ -19,6 +19,7 @@ Fungus.FloatVariable
Fungus.Flowchart
Fungus.FungusPrefs
Fungus.LuaEnvironment
+Fungus.LuaUtils
Fungus.GameObjectVariable
Fungus.IntegerVariable
Fungus.Label
diff --git a/Assets/Fungus/Lua/Scripts/Editor/LuaEnvironmentEditor.cs b/Assets/Fungus/Lua/Scripts/Editor/LuaUtilsEditor.cs
similarity index 93%
rename from Assets/Fungus/Lua/Scripts/Editor/LuaEnvironmentEditor.cs
rename to Assets/Fungus/Lua/Scripts/Editor/LuaUtilsEditor.cs
index 82a0c1ee..1236b34a 100644
--- a/Assets/Fungus/Lua/Scripts/Editor/LuaEnvironmentEditor.cs
+++ b/Assets/Fungus/Lua/Scripts/Editor/LuaUtilsEditor.cs
@@ -8,10 +8,9 @@ using System.Reflection;
using System.IO;
namespace Fungus
-{
-
- [CustomEditor (typeof(LuaEnvironment))]
- public class LuaEnvironmentEditor : Editor
+{
+ [CustomEditor (typeof(LuaUtils))]
+ public class LuaUtilsEditor : Editor
{
protected SerializedProperty registerTypesProp;
protected ReorderableList registerTypeList;
diff --git a/Assets/Fungus/Lua/Scripts/Editor/LuaEnvironmentEditor.cs.meta b/Assets/Fungus/Lua/Scripts/Editor/LuaUtilsEditor.cs.meta
similarity index 76%
rename from Assets/Fungus/Lua/Scripts/Editor/LuaEnvironmentEditor.cs.meta
rename to Assets/Fungus/Lua/Scripts/Editor/LuaUtilsEditor.cs.meta
index d4670c9e..384a5c43 100644
--- a/Assets/Fungus/Lua/Scripts/Editor/LuaEnvironmentEditor.cs.meta
+++ b/Assets/Fungus/Lua/Scripts/Editor/LuaUtilsEditor.cs.meta
@@ -1,6 +1,6 @@
fileFormatVersion: 2
-guid: 4fba065af9c124bbd837138d28ac0cab
-timeCreated: 1459508303
+guid: 2e8bbf4afc9f447ccb83004b8bbe3e1a
+timeCreated: 1459521262
licenseType: Free
MonoImporter:
serializedVersion: 2
diff --git a/Assets/Fungus/Lua/Scripts/LuaEnvironment.cs b/Assets/Fungus/Lua/Scripts/LuaEnvironment.cs
index 98a23660..b33eaa28 100644
--- a/Assets/Fungus/Lua/Scripts/LuaEnvironment.cs
+++ b/Assets/Fungus/Lua/Scripts/LuaEnvironment.cs
@@ -96,33 +96,6 @@ namespace Fungus
[Tooltip("Launches the remote Lua debugger in your browser and breaks execution at the first executed Lua command.")]
public bool remoteDebugger = false;
- ///
- /// Lua script file which defines the global string table used for localisation.
- ///
- [Tooltip("Lua script file which defines the global string table used for localisation.")]
- public TextAsset stringTable;
-
- ///
- /// The currently selected language in the string table. Affects variable substitution.
- ///
- [Tooltip("The currently selected language in the string table. Affects variable substitution.")]
- public string activeLanguage = "en";
-
- ///
- /// Time scale factor to apply when running Lua scripts.
- /// This allows pausing of time based operations by setting timescale to 0.
- /// Use the GetTime() and GetDeltaTime() functions to get scaled time values.
- /// If negative, then GetTime() and GetDeltaTime() return the same values as the standard Time class.
- ///
- [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();
-
///
/// Instance of remote debugging service when debugging option is enabled.
///
@@ -133,12 +106,7 @@ namespace Fungus
///
protected bool initialised = false;
- ///
- /// Cached referenence to the string table (if loaded).
- ///
- protected Table stringTableCached;
-
- protected virtual void Start()
+ protected virtual void Start()
{
InitInterpreter();
}
@@ -160,10 +128,13 @@ namespace Fungus
interpreter = new Script(CoreModules.Preset_Complete);
InitLuaScriptFiles();
- InitTypes();
- InitCustomObjects();
- InitBindings();
- InitStringTable();
+
+ // TODO: Use an interface here instead
+ LuaUtils luaUtils = GetComponent();
+ if (luaUtils != null)
+ {
+ luaUtils.Initialise();
+ }
if (remoteDebugger)
{
@@ -182,35 +153,6 @@ namespace Fungus
interpreter.Options.ScriptLoader = new LuaScriptLoader(result.OfType());
}
- ///
- /// 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 InitTypes()
- {
- // Register types
- foreach (TextAsset textFile in registerTypes)
- {
- if (textFile == null)
- {
- continue;
- }
-
- char[] separators = { '\r', '\n' };
- foreach (string typeName in textFile.text.Split(separators, StringSplitOptions.RemoveEmptyEntries))
- {
- // Skip comments and empty lines
- if (typeName.StartsWith("#") || typeName.Trim() == "")
- {
- continue;
- }
-
- RegisterType(typeName);
- }
- }
- }
-
///
/// Register a type given it's assembly qualified name.
///
@@ -250,178 +192,6 @@ namespace Fungus
}
}
- ///
- /// Register some commonly used Unity classes and objects for Lua interop.
- /// To register more class objects externally to this class, register them in the Awake method of any
- /// monobehavior in your scene.
- ///
- protected virtual void InitCustomObjects()
- {
- // Add the CLR class objects to a global unity table
- Table unityTable = new Table(interpreter);
- interpreter.Globals["unity"] = unityTable;
-
- // Static classes
- unityTable["time"] = UserData.CreateStatic(typeof(Time));
- unityTable["fungusprefs"] = UserData.CreateStatic(typeof(FungusPrefs));
-
- UserData.RegisterType(typeof(PODTypeFactory));
- unityTable["factory"] = UserData.CreateStatic(typeof(PODTypeFactory));
-
- // This Lua Environment component
- unityTable["luaenvironment"] = this;
-
- // Provide access to the Unity Test Tools (if available).
- Type testType = Type.GetType("IntegrationTest");
- if (testType != null)
- {
- UserData.RegisterType(testType);
- unityTable["test"] = UserData.CreateStatic(testType);
- }
-
- // Example of how to register an enum
- // UserData.RegisterType();
- // interpreter.Globals.Set("MyEnum", UserData.CreateStatic());
- }
-
- ///
- /// Binds all gameobjects and components defined in scene LuaBindings to the global table.
- ///
- protected virtual void InitBindings()
- {
- LuaBindingsBase[] bindings = GameObject.FindObjectsOfType();
- foreach (LuaBindingsBase binding in bindings)
- {
- binding.AddBindings(interpreter.Globals);
- }
- }
-
- ///
- /// Loads the global string table used for localisation.
- ///
- protected virtual void InitStringTable()
- {
- if (stringTable != null)
- {
- try
- {
- DynValue stringTableRes = interpreter.DoString(stringTable.text);
- if (stringTableRes.Type == DataType.Table)
- {
- stringTableCached = stringTableRes.Table;
- interpreter.Globals["stringtable"] = stringTableCached;
- }
- }
- catch (ScriptRuntimeException ex)
- {
- UnityEngine.Debug.LogError("Lua runtime error: " + ex.DecoratedMessage);
- }
- catch (InterpreterException ex)
- {
- UnityEngine.Debug.LogError(ex.DecoratedMessage);
- }
- }
- }
-
- ///
- /// Returns a string from the string table for this key.
- /// The string returned depends on the active language.
- ///
- public virtual string GetString(string key)
- {
- if (stringTableCached != null)
- {
- // Match against string table and active language
- DynValue stringTableVar = stringTableCached.Get(key);
- if (stringTableVar.Type == DataType.Table)
- {
- DynValue languageEntry = stringTableVar.Table.Get(activeLanguage);
- if (languageEntry.Type == DataType.String)
- {
- return languageEntry.String;
- }
- }
- }
-
- return "";
- }
-
- ///
- /// Substitutes specially formatted tokens in the text with global variables and string table values.
- /// The string table value used depends on the currently loaded string table and active language.
- ///
- public virtual string Substitute(string text)
- {
- string subbedText = text;
-
- // Instantiate the regular expression object.
- Regex r = new Regex("\\[\\$.*?\\]");
-
- // Match the regular expression pattern against a text string.
- var results = r.Matches(text);
- foreach (Match match in results)
- {
- string key = match.Value.Substring(2, match.Value.Length - 3);
-
- if (stringTableCached != null)
- {
- // Match against string table and active language
- DynValue stringTableVar = stringTableCached.Get(key);
- if (stringTableVar.Type == DataType.Table)
- {
- DynValue languageEntry = stringTableVar.Table.Get(activeLanguage);
- if (languageEntry.Type == DataType.String)
- {
- subbedText = subbedText.Replace(match.Value, languageEntry.String);
- }
- continue;
- }
- }
-
- // Match against global variables
- DynValue globalVar = interpreter.Globals.Get(key);
- if (globalVar.Type != DataType.Nil)
- {
- subbedText = subbedText.Replace(match.Value, globalVar.ToPrintString());
- continue;
- }
- }
-
- return subbedText;
- }
-
- ///
- /// Returns the time since level load, multiplied by timeScale.
- /// If timeScale is negative then returns the same as Time.timeSinceLevelLoaded.
- ///
- public float GetTime()
- {
- if (timeScale < 0f)
- {
- return Time.timeSinceLevelLoad;
- }
- else
- {
- return Time.unscaledTime * timeScale;
- }
- }
-
- ///
- /// Returns the delta time this frame, multiplied by timeScale.
- /// If timeScale is negative then returns the same as Time.deltaTime.
- ///
- public float GetDeltaTime()
- {
- if (timeScale < 0f)
- {
- return Time.deltaTime;
- }
- else
- {
- return Time.deltaTime * timeScale;
- }
- }
-
///
/// Load and run a string containing Lua script. May be run as a coroutine.
/// The Lua code to be run.
diff --git a/Assets/Fungus/Lua/Scripts/LuaUtils.cs b/Assets/Fungus/Lua/Scripts/LuaUtils.cs
new file mode 100644
index 00000000..8fcdb5cd
--- /dev/null
+++ b/Assets/Fungus/Lua/Scripts/LuaUtils.cs
@@ -0,0 +1,304 @@
+using UnityEngine;
+using System.Collections;
+using System.Collections.Generic;
+using System;
+using System.Linq;
+using System.Diagnostics;
+using System.Text.RegularExpressions;
+using MoonSharp.Interpreter;
+using MoonSharp.Interpreter.Interop;
+using MoonSharp.Interpreter.Loaders;
+using MoonSharp.RemoteDebugger;
+
+namespace Fungus
+{
+
+ public class LuaUtils : MonoBehaviour
+ {
+ ///
+ /// Lua script file which defines the global string table used for localisation.
+ ///
+ [Tooltip("Lua script file which defines the global string table used for localisation.")]
+ public TextAsset stringTable;
+
+ ///
+ /// The currently selected language in the string table. Affects variable substitution.
+ ///
+ [Tooltip("The currently selected language in the string table. Affects variable substitution.")]
+ public string activeLanguage = "en";
+
+ ///
+ /// Time scale factor to apply when running Lua scripts.
+ /// This allows pausing of time based operations by setting timescale to 0.
+ /// Use the GetTime() and GetDeltaTime() functions to get scaled time values.
+ /// If negative, then GetTime() and GetDeltaTime() return the same values as the standard Time class.
+ ///
+ [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();
+
+ ///
+ /// Flag used to avoid startup dependency issues.
+ ///
+ protected bool initialised = false;
+
+ ///
+ /// Cached reference to the string table (if loaded).
+ ///
+ protected Table stringTableCached;
+
+ ///
+ /// Cached reference to the Lua Environment component.
+ ///
+ protected LuaEnvironment luaEnvironment;
+
+ public virtual void Initialise()
+ {
+ luaEnvironment = GetComponent();
+ if (luaEnvironment == null)
+ {
+ UnityEngine.Debug.LogError("No Lua Environment found");
+ return;
+ }
+
+ if (luaEnvironment.Interpreter == null)
+ {
+ UnityEngine.Debug.LogError("No Lua interpreter found");
+ return;
+ }
+
+ InitTypes();
+ InitBindings();
+ InitCustomObjects();
+ InitStringTable();
+ }
+
+ ///
+ /// 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().
+ ///
+ protected virtual void InitTypes()
+ {
+ foreach (TextAsset textFile in registerTypes)
+ {
+ if (textFile == null)
+ {
+ continue;
+ }
+
+ char[] separators = { '\r', '\n' };
+ foreach (string typeName in textFile.text.Split(separators, StringSplitOptions.RemoveEmptyEntries))
+ {
+ // Skip comments and empty lines
+ if (typeName.StartsWith("#") || typeName.Trim() == "")
+ {
+ continue;
+ }
+
+ LuaEnvironment.RegisterType(typeName);
+ }
+ }
+ }
+
+ ///
+ /// Binds all gameobjects and components defined in scene LuaBindings to the global table.
+ ///
+ protected virtual void InitBindings()
+ {
+ MoonSharp.Interpreter.Script interpreter = luaEnvironment.Interpreter;
+
+ LuaBindingsBase[] bindings = GameObject.FindObjectsOfType();
+ foreach (LuaBindingsBase binding in bindings)
+ {
+ binding.AddBindings(interpreter.Globals);
+ }
+ }
+
+ ///
+ /// Register some commonly used Unity classes and objects for Lua interop.
+ /// To register more class objects externally to this class, register them in the Awake method of any
+ /// monobehavior in your scene.
+ ///
+ protected virtual void InitCustomObjects()
+ {
+ MoonSharp.Interpreter.Script interpreter = luaEnvironment.Interpreter;
+
+ // Add the CLR class objects to a global unity table
+ Table unityTable = new Table(interpreter);
+ interpreter.Globals["unity"] = unityTable;
+
+ // Static classes
+ unityTable["time"] = UserData.CreateStatic(typeof(Time));
+ unityTable["fungusprefs"] = UserData.CreateStatic(typeof(FungusPrefs));
+
+ UserData.RegisterType(typeof(PODTypeFactory));
+ unityTable["factory"] = UserData.CreateStatic(typeof(PODTypeFactory));
+
+ // Lua Environment and Lua Utils components
+ unityTable["luaenvironment"] = luaEnvironment;
+ unityTable["luautils"] = this;
+
+ // Provide access to the Unity Test Tools (if available).
+ Type testType = Type.GetType("IntegrationTest");
+ if (testType != null)
+ {
+ UserData.RegisterType(testType);
+ unityTable["test"] = UserData.CreateStatic(testType);
+ }
+
+ // Example of how to register an enum
+ // UserData.RegisterType();
+ // interpreter.Globals.Set("MyEnum", UserData.CreateStatic());
+ }
+
+ ///
+ /// Loads the global string table used for localisation.
+ ///
+ protected virtual void InitStringTable()
+ {
+ MoonSharp.Interpreter.Script interpreter = luaEnvironment.Interpreter;
+
+ if (stringTable != null)
+ {
+ try
+ {
+ DynValue stringTableRes = interpreter.DoString(stringTable.text);
+ if (stringTableRes.Type == DataType.Table)
+ {
+ stringTableCached = stringTableRes.Table;
+ interpreter.Globals["stringtable"] = stringTableCached;
+ }
+ }
+ catch (ScriptRuntimeException ex)
+ {
+ UnityEngine.Debug.LogError("Lua runtime error: " + ex.DecoratedMessage);
+ }
+ catch (InterpreterException ex)
+ {
+ UnityEngine.Debug.LogError(ex.DecoratedMessage);
+ }
+ }
+ }
+
+ ///
+ /// Returns a string from the string table for this key.
+ /// The string returned depends on the active language.
+ ///
+ public virtual string GetString(string key)
+ {
+ if (stringTableCached != null)
+ {
+ // Match against string table and active language
+ DynValue stringTableVar = stringTableCached.Get(key);
+ if (stringTableVar.Type == DataType.Table)
+ {
+ DynValue languageEntry = stringTableVar.Table.Get(activeLanguage);
+ if (languageEntry.Type == DataType.String)
+ {
+ return languageEntry.String;
+ }
+ }
+ }
+
+ return "";
+ }
+
+ ///
+ /// Substitutes specially formatted tokens in the text with global variables and string table values.
+ /// The string table value used depends on the currently loaded string table and active language.
+ ///
+ public virtual string Substitute(string text)
+ {
+ if (luaEnvironment == null)
+ {
+ UnityEngine.Debug.LogError("No Lua Environment found");
+ return text;
+ }
+
+ if (luaEnvironment.Interpreter == null)
+ {
+ UnityEngine.Debug.LogError("No Lua interpreter found");
+ return text;
+ }
+
+ MoonSharp.Interpreter.Script interpreter = luaEnvironment.Interpreter;
+
+ string subbedText = text;
+
+ // Instantiate the regular expression object.
+ Regex r = new Regex("\\[\\$.*?\\]");
+
+ // Match the regular expression pattern against a text string.
+ var results = r.Matches(text);
+ foreach (Match match in results)
+ {
+ string key = match.Value.Substring(2, match.Value.Length - 3);
+
+ // Match against string table and active language (if specified)
+ if (stringTableCached != null)
+ {
+ DynValue stringTableVar = stringTableCached.Get(key);
+ if (stringTableVar.Type == DataType.Table)
+ {
+ DynValue languageEntry = stringTableVar.Table.Get(activeLanguage);
+ if (languageEntry.Type == DataType.String)
+ {
+ subbedText = subbedText.Replace(match.Value, languageEntry.String);
+ }
+ continue;
+ }
+ }
+
+ // Match against global variables
+ DynValue globalVar = interpreter.Globals.Get(key);
+ if (globalVar.Type != DataType.Nil)
+ {
+ subbedText = subbedText.Replace(match.Value, globalVar.ToPrintString());
+ continue;
+ }
+ }
+
+ return subbedText;
+ }
+
+ ///
+ /// Returns the time since level load, multiplied by timeScale.
+ /// If timeScale is negative then returns the same as Time.timeSinceLevelLoaded.
+ ///
+ public float GetTime()
+ {
+ if (timeScale < 0f)
+ {
+ return Time.timeSinceLevelLoad;
+ }
+ else
+ {
+ return Time.unscaledTime * timeScale;
+ }
+ }
+
+ ///
+ /// Returns the delta time this frame, multiplied by timeScale.
+ /// If timeScale is negative then returns the same as Time.deltaTime.
+ ///
+ public float GetDeltaTime()
+ {
+ if (timeScale < 0f)
+ {
+ return Time.deltaTime;
+ }
+ else
+ {
+ return Time.deltaTime * timeScale;
+ }
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/Assets/Fungus/Lua/Scripts/LuaUtils.cs.meta b/Assets/Fungus/Lua/Scripts/LuaUtils.cs.meta
new file mode 100644
index 00000000..b3547547
--- /dev/null
+++ b/Assets/Fungus/Lua/Scripts/LuaUtils.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: c10f0b861365b42b0928858f7b086ff3
+timeCreated: 1459515524
+licenseType: Free
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Tests/Lua/FungusTests.unity b/Assets/Tests/Lua/FungusTests.unity
index 1c513267..f35ba23d 100644
--- a/Assets/Tests/Lua/FungusTests.unity
+++ b/Assets/Tests/Lua/FungusTests.unity
@@ -127,7 +127,51 @@ MonoBehaviour:
m_EditorClassIdentifier:
tableName:
registerTypes: 1
- boundTypes: []
+ 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.SayDialog, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+ - UnityEngine.AudioClip, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+ - System.Action, System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+ - Fungus.Character, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+ - Fungus.Flowchart, 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
+ - Fungus.FacingDirection, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+ - Fungus.PortraitState, Assembly-CSharp, 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.Font, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+ - UnityEngine.TextAnchor, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+ - UnityEngine.HorizontalWrapMode, UnityEngine, Version=0.0.0.0, Culture=neutral,
+ PublicKeyToken=null
+ - UnityEngine.VerticalWrapMode, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+ - UnityEngine.FontStyle, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+ - UnityEngine.TextGenerationSettings, UnityEngine, Version=0.0.0.0, Culture=neutral,
+ PublicKeyToken=null
+ - UnityEngine.Vector2, 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.AudioClip+PCMReaderCallback, UnityEngine, Version=0.0.0.0, Culture=neutral,
+ PublicKeyToken=null
+ - UnityEngine.AudioClip+PCMSetPositionCallback, UnityEngine, Version=0.0.0.0, Culture=neutral,
+ PublicKeyToken=null
boundObjects:
- key: saydialog
obj: {fileID: 2087053783}
@@ -1114,7 +1158,7 @@ MonoBehaviour:
fungus.assert (s.value == "a string")
- t = fungus.time()
+ t = fungus.gettime()
-- Execute a block to change the variable
@@ -1124,7 +1168,7 @@ MonoBehaviour:
fungus.runwait( b.Execute() )
- fungus.assert(fungus.time() - t >= 1)
+ fungus.assert(fungus.gettime() - t >= 1)
-- Check the new value of StringVar
@@ -8202,7 +8246,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
- m_IsActive: 1
+ m_IsActive: 0
--- !u!114 &1738857301
MonoBehaviour:
m_ObjectHideFlags: 0
diff --git a/Assets/Tests/Lua/LuaEnvironmentTests.unity b/Assets/Tests/Lua/LuaEnvironmentTests.unity
index f096fbab..69e8d3b3 100644
--- a/Assets/Tests/Lua/LuaEnvironmentTests.unity
+++ b/Assets/Tests/Lua/LuaEnvironmentTests.unity
@@ -288,10 +288,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
tableName:
- boundObjects:
- - key: dummycollection
- obj: {fileID: 367860753}
- component: {fileID: 367860754}
+ 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
@@ -307,6 +304,10 @@ MonoBehaviour:
- System.Single, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
- Fungus.DummyCollection, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
- UnityEngine.Sprite, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
+ boundObjects:
+ - key: dummycollection
+ obj: {fileID: 367860753}
+ component: {fileID: 367860754}
--- !u!1 &305346650
GameObject:
m_ObjectHideFlags: 0
@@ -357,10 +358,10 @@ MonoBehaviour:
luaEnvironment: {fileID: 0}
luaFile: {fileID: 0}
luaScript: "-- Test the timeout works in fungus.waitfor\nlocal value = false\n\nfunction
- fn()\n return value\nend\n\nt = fungus.time()\nfungus.waitfor(fn, 1)\nfungus.assert
- (fungus.time() - t >= 1)\n\n-- Test fungus.waitfor() exits if the function returns
- true\n-- If this doesn't work the test will timeout and fail\nvalue = true\nfungus.waitfor(fn,
- 1)\n\nfungus.pass()"
+ fn()\n return value\nend\n\nt = fungus.gettime()\nfungus.waitfor(fn, 1)\nfungus.assert
+ (fungus.gettime() - t >= 1)\n\n-- Test fungus.waitfor() exits if the function
+ returns true\n-- If this doesn't work the test will timeout and fail\nvalue =
+ true\nfungus.waitfor(fn, 1)\n\nfungus.pass()"
runAsCoroutine: 1
useFungusModule: 1
--- !u!1001 &364012152
@@ -477,7 +478,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
- m_IsActive: 0
+ m_IsActive: 1
--- !u!114 &637150168
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -829,11 +830,11 @@ MonoBehaviour:
-- Should take 1 second in realtime to wait for 1 second
- t= fungus.time()
+ t = fungus.gettime()
fungus.wait(1)
- t = fungus.time() - t
+ t = fungus.gettime() - t
fungus.assert(t >= 1)
@@ -842,13 +843,13 @@ MonoBehaviour:
-- Should take 2 seconds in realtime to wait for 1 second
- unity.luaenvironment.timeScale = 0.5
+ fungus.settimescale(0.5)
- t= fungus.time()
+ t = fungus.gettime()
fungus.wait(1)
- t = fungus.time() - t
+ t = fungus.gettime() - t
fungus.assert(t >= 1)
@@ -1332,6 +1333,7 @@ MonoBehaviour:
luaFile: {fileID: 0}
luaScript: '-- Test string table localisation system
+ print(stringtable)
fungus.assert(stringtable != nil)
@@ -1479,6 +1481,10 @@ Prefab:
propertyPath: stringTable
value:
objectReference: {fileID: 4900000, guid: 9900570d789fa4b29957e4b897af9e3b, type: 3}
+ - target: {fileID: 11486636, guid: 49031c561e16d4fcf91c12153f8e0b25, type: 2}
+ propertyPath: stringTable
+ value:
+ objectReference: {fileID: 4900000, guid: 9900570d789fa4b29957e4b897af9e3b, type: 3}
m_RemovedComponents:
- {fileID: 11403674, guid: 49031c561e16d4fcf91c12153f8e0b25, type: 2}
m_ParentPrefab: {fileID: 100100000, guid: 49031c561e16d4fcf91c12153f8e0b25, type: 2}
@@ -1502,7 +1508,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
- m_IsActive: 1
+ m_IsActive: 0
--- !u!114 &1900871525
MonoBehaviour:
m_ObjectHideFlags: 0
diff --git a/Assets/Tests/Resources.meta b/Assets/Tests/TestAssets/Resources.meta
similarity index 100%
rename from Assets/Tests/Resources.meta
rename to Assets/Tests/TestAssets/Resources.meta
diff --git a/Assets/Tests/Resources/Lua.meta b/Assets/Tests/TestAssets/Resources/Lua.meta
similarity index 100%
rename from Assets/Tests/Resources/Lua.meta
rename to Assets/Tests/TestAssets/Resources/Lua.meta
diff --git a/Assets/Tests/Resources/Lua/teststringtable.txt b/Assets/Tests/TestAssets/Resources/Lua/teststringtable.txt
similarity index 100%
rename from Assets/Tests/Resources/Lua/teststringtable.txt
rename to Assets/Tests/TestAssets/Resources/Lua/teststringtable.txt
diff --git a/Assets/Tests/Resources/Lua/teststringtable.txt.meta b/Assets/Tests/TestAssets/Resources/Lua/teststringtable.txt.meta
similarity index 100%
rename from Assets/Tests/Resources/Lua/teststringtable.txt.meta
rename to Assets/Tests/TestAssets/Resources/Lua/teststringtable.txt.meta