diff --git a/Assets/Fungus/Lua/Scripts/Commands/ExecuteLua.cs b/Assets/Fungus/Lua/Scripts/Commands/ExecuteLua.cs index ff8c2033..c42eb009 100644 --- a/Assets/Fungus/Lua/Scripts/Commands/ExecuteLua.cs +++ b/Assets/Fungus/Lua/Scripts/Commands/ExecuteLua.cs @@ -14,8 +14,11 @@ namespace Fungus [Tooltip("Lua Environment to use to execute this Lua script")] public LuaEnvironment luaEnvironment; + [Tooltip("A text file containing Lua script to execute.")] + public TextAsset luaFile; + [TextArea(10,100)] - [Tooltip("Lua script to execute. Use {$VarName} to insert a Flowchart variable in the Lua script.")] + [Tooltip("Lua script to execute. This text is appended to the contents of Lua file (if one is specified).")] public string luaScript; [Tooltip("Execute this Lua script as a Lua coroutine")] @@ -30,7 +33,10 @@ namespace Fungus protected string friendlyName = ""; - protected bool initialised ; + protected bool initialised; + + // Stores the compiled Lua code for fast execution later. + protected Closure luaFunction; protected virtual void Start() { @@ -55,19 +61,38 @@ namespace Fungus luaEnvironment = LuaEnvironment.GetLua(); } - initialised = true; + string s = GetLuaString(); + luaFunction = luaEnvironment.LoadLuaString(s, friendlyName); + + // Always initialise when playing in the editor. + // Allows the user to edit the Lua script while the game is playing. + if ( !(Application.isPlaying && Application.isEditor) ) + { + initialised = true; + } + + } + + protected virtual string GetLuaString() + { + if (luaFile == null) + { + return luaScript; + } + + return luaFile.text + "\n" + luaScript; } public override void OnEnter() { InitExecuteLua(); - - // Note: We can't pre compile the Lua script in this command because we want to - // support variable substitution in the Lua string. - // If this is too slow, consider using a LuaScript object and calling OnExecute() on it instead. - string subbed = GetFlowchart().SubstituteVariables(luaScript); - luaEnvironment.DoLuaString(subbed, friendlyName, runAsCoroutine, (returnValue) => { + if (luaFunction == null) + { + Continue(); + } + + luaEnvironment.RunLuaFunction(luaFunction, GetLuaString(), runAsCoroutine, (returnValue) => { StoreReturnVariable(returnValue); if (waitUntilFinished) { diff --git a/Assets/Fungus/Lua/Scripts/LuaExtensions.cs b/Assets/Fungus/Lua/Scripts/LuaExtensions.cs index ced82f45..2ddb6be0 100644 --- a/Assets/Fungus/Lua/Scripts/LuaExtensions.cs +++ b/Assets/Fungus/Lua/Scripts/LuaExtensions.cs @@ -41,7 +41,7 @@ namespace Fungus if (callBack != null) { - luaEnvironment.RunLuaCoroutine(callBack, text); + luaEnvironment.RunLuaFunction(callBack, text, true); } }); @@ -89,7 +89,7 @@ namespace Fungus if (callBack != null) { - luaEnvironment.RunLuaCoroutine(callBack, "menutimer"); + luaEnvironment.RunLuaFunction(callBack, "menutimer", true); } } } diff --git a/Assets/Fungus/Thirdparty/FungusLua/Resources/Lua/fungus.txt b/Assets/Fungus/Thirdparty/FungusLua/Resources/Lua/fungus.txt index 171867d7..0a665fe4 100644 --- a/Assets/Fungus/Thirdparty/FungusLua/Resources/Lua/fungus.txt +++ b/Assets/Fungus/Thirdparty/FungusLua/Resources/Lua/fungus.txt @@ -18,8 +18,8 @@ end -- Waits for a number of seconds function M.wait(duration) - local t = M.gettime() - while (M.gettime() - t < duration) do + local t = M.time.timeSinceLevelLoad + while (M.time.timeSinceLevelLoad - t < duration) do coroutine.yield() end end @@ -27,10 +27,10 @@ end -- Waits until the lamda function provided returns true, or the timeout expires. -- Returns true if the function succeeded, or false if the timeout expired function M.waitfor(fn, timeoutduration) - local t = M.gettime() + local t = M.time.timeSinceLevelLoad while (not fn()) do coroutine.yield() - if (M.gettime() - t > timeoutduration) then + if (M.time.timeSinceLevelLoad - t > timeoutduration) then return false end end diff --git a/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaEnvironment.cs b/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaEnvironment.cs index 783f56cb..12866b54 100644 --- a/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaEnvironment.cs +++ b/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaEnvironment.cs @@ -196,16 +196,43 @@ namespace Fungus } /// - /// Load and run a string containing Lua script. May be run as a coroutine. + /// Loads and compiles a string containing Lua script, returning a closure (Lua function) which can be executed later. /// The Lua code to be run. /// A descriptive name to be used in error reports. - /// Run the Lua code as a coroutine to support asynchronous operations. - /// Method to callback when the Lua code finishes exection. Supports return parameters. /// - public virtual void DoLuaString(string luaString, string friendlyName, bool runAsCoroutine, Action onComplete = null) + public virtual Closure LoadLuaString(string luaString, string friendlyName) { - Closure fn = LoadLuaString(luaString, friendlyName); + InitEnvironment(); + + // Load the Lua script + DynValue res = null; + try + { + res = interpreter.LoadString(luaString, null, friendlyName); + } + catch (InterpreterException ex) + { + LogException(ex.DecoratedMessage, luaString); + } + if (res.Type != DataType.Function) + { + UnityEngine.Debug.LogError("Failed to create Lua function from Lua string"); + return null; + } + + return res.Function; + } + + /// + /// Load and run a previously compiled Lua script. May be run as a coroutine. + /// A previously compiled Lua function. + /// The Lua code to display in case of an error. + /// Run the Lua code as a coroutine to support asynchronous operations. + /// Method to callback when the Lua code finishes exection. Supports return parameters. + /// + public virtual void RunLuaFunction(Closure fn, string luaString, bool runAsCoroutine, Action onComplete = null) + { if (fn == null) { if (onComplete != null) @@ -219,7 +246,7 @@ namespace Fungus // Execute the Lua script if (runAsCoroutine) { - StartCoroutine(RunLuaCoroutineInternal(fn, luaString, onComplete)); + StartCoroutine(RunLuaCoroutine(fn, luaString, onComplete)); } else { @@ -241,43 +268,16 @@ namespace Fungus } /// - /// Loads and compiles a string containing Lua script, returning a closure (Lua function) which can be executed later. + /// Load and run a string containing Lua script. May be run as a coroutine. /// The Lua code to be run. /// A descriptive name to be used in error reports. + /// Run the Lua code as a coroutine to support asynchronous operations. + /// Method to callback when the Lua code finishes exection. Supports return parameters. /// - public virtual Closure LoadLuaString(string luaString, string friendlyName) - { - InitEnvironment(); - - // Load the Lua script - DynValue res = null; - try - { - res = interpreter.LoadString(luaString, null, friendlyName); - } - catch (InterpreterException ex) - { - LogException(ex.DecoratedMessage, luaString); - } - - if (res.Type != DataType.Function) - { - UnityEngine.Debug.LogError("Failed to create Lua function from Lua string"); - return null; - } - - return res.Function; - } - - /// - /// Starts a Unity coroutine which updates a Lua coroutine each frame. - /// A MoonSharp closure object representing a function. - /// Debug text to display if an exception occurs (usually the Lua code that is being executed). - /// A delegate method that is called when the coroutine completes. Includes return parameter. - /// - public virtual void RunLuaCoroutine(Closure closure, string debugInfo, Action onComplete = null) + public virtual void DoLuaString(string luaString, string friendlyName, bool runAsCoroutine, Action onComplete = null) { - StartCoroutine(RunLuaCoroutineInternal(closure, debugInfo, onComplete)); + Closure fn = LoadLuaString(luaString, friendlyName); + RunLuaFunction(fn, luaString, runAsCoroutine, onComplete); } /// @@ -286,7 +286,7 @@ namespace Fungus /// Debug text to display if an exception occurs (usually the Lua code that is being executed). /// A delegate method that is called when the coroutine completes. Includes return parameter. /// - protected virtual IEnumerator RunLuaCoroutineInternal(Closure closure, string debugInfo, Action onComplete = null) + protected virtual IEnumerator RunLuaCoroutine(Closure closure, string debugInfo, Action onComplete = null) { DynValue co = interpreter.CreateCoroutine(closure); diff --git a/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaScript.cs b/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaScript.cs index 6fa0f3d9..2caca124 100644 --- a/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaScript.cs +++ b/Assets/Fungus/Thirdparty/FungusLua/Scripts/LuaScript.cs @@ -138,7 +138,7 @@ namespace Fungus } else { - luaEnvironment.RunLuaCoroutine(luaFunction, luaScript); + luaEnvironment.RunLuaFunction(luaFunction, luaScript, runAsCoroutine); } } } diff --git a/Assets/Tests/Lua/FungusTests.unity b/Assets/Tests/Lua/FungusTests.unity index cd0a7477..a835e190 100644 --- a/Assets/Tests/Lua/FungusTests.unity +++ b/Assets/Tests/Lua/FungusTests.unity @@ -813,12 +813,15 @@ MonoBehaviour: errorMessage: indentLevel: 0 luaEnvironment: {fileID: 0} + luaFile: {fileID: 4900000, guid: 6cbce76ae849c40cb86ed0bb1b6e1a95, type: 3} luaScript: '-- Test executing Lua script from a Fungus command - -- Test Flowchart variable substitution + -- Test Flowchart public variable substitution - check("{$StringVar}" == "it worked") + local s = sub("{$StringVar}") + + check(s == "it worked") pass()' @@ -852,7 +855,7 @@ MonoBehaviour: m_EditorClassIdentifier: nodeRect: serializedVersion: 2 - x: 67 + x: 68 y: 70 width: 120 height: 40 @@ -910,7 +913,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 4580f28dd8581476b810b38eea2f1316, type: 3} m_Name: m_EditorClassIdentifier: - scope: 0 + scope: 1 key: StringVar value: it worked --- !u!1 &95979348 @@ -1201,7 +1204,7 @@ MonoBehaviour: check (s.value == "a string") - t = gettime() + t = time.timeSinceLevelLoad -- Execute a block to change the variable @@ -1211,7 +1214,7 @@ MonoBehaviour: runwait( b.Execute() ) - check(gettime() - t >= 1) + check(time.timeSinceLevelLoad - t >= 1) -- Check the new value of StringVar @@ -5376,6 +5379,7 @@ MonoBehaviour: errorMessage: indentLevel: 0 luaEnvironment: {fileID: 0} + luaFile: {fileID: 0} luaScript: return true runAsCoroutine: 0 waitUntilFinished: 1 @@ -5491,6 +5495,7 @@ MonoBehaviour: errorMessage: indentLevel: 0 luaEnvironment: {fileID: 0} + luaFile: {fileID: 0} luaScript: return 1.0 runAsCoroutine: 0 waitUntilFinished: 1 @@ -5510,6 +5515,7 @@ MonoBehaviour: errorMessage: indentLevel: 0 luaEnvironment: {fileID: 0} + luaFile: {fileID: 0} luaScript: return 2 runAsCoroutine: 0 waitUntilFinished: 1 @@ -5529,6 +5535,7 @@ MonoBehaviour: errorMessage: indentLevel: 0 luaEnvironment: {fileID: 0} + luaFile: {fileID: 0} luaScript: return "a string" runAsCoroutine: 0 waitUntilFinished: 1 @@ -5604,6 +5611,7 @@ MonoBehaviour: errorMessage: indentLevel: 0 luaEnvironment: {fileID: 0} + luaFile: {fileID: 0} luaScript: 'local c = factory.color(1, 0.5, 1, 1) @@ -5626,6 +5634,7 @@ MonoBehaviour: errorMessage: indentLevel: 0 luaEnvironment: {fileID: 0} + luaFile: {fileID: 0} luaScript: return testgameobject runAsCoroutine: 0 waitUntilFinished: 1 @@ -5673,6 +5682,7 @@ MonoBehaviour: errorMessage: indentLevel: 0 luaEnvironment: {fileID: 0} + luaFile: {fileID: 0} luaScript: return testmaterial runAsCoroutine: 0 waitUntilFinished: 1 @@ -5706,6 +5716,7 @@ MonoBehaviour: errorMessage: indentLevel: 0 luaEnvironment: {fileID: 0} + luaFile: {fileID: 0} luaScript: return testgameobject runAsCoroutine: 0 waitUntilFinished: 1 @@ -5739,6 +5750,7 @@ MonoBehaviour: errorMessage: indentLevel: 0 luaEnvironment: {fileID: 0} + luaFile: {fileID: 0} luaScript: return mushroom runAsCoroutine: 0 waitUntilFinished: 1 @@ -5772,6 +5784,7 @@ MonoBehaviour: errorMessage: indentLevel: 0 luaEnvironment: {fileID: 0} + luaFile: {fileID: 0} luaScript: 'local v = factory.vector2(1,1) @@ -5808,6 +5821,7 @@ MonoBehaviour: errorMessage: indentLevel: 0 luaEnvironment: {fileID: 0} + luaFile: {fileID: 0} luaScript: return mousepointer runAsCoroutine: 0 waitUntilFinished: 1 @@ -5841,6 +5855,7 @@ MonoBehaviour: errorMessage: indentLevel: 0 luaEnvironment: {fileID: 0} + luaFile: {fileID: 0} luaScript: 'local v = factory.vector3(1,1,1) return v' @@ -7965,7 +7980,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!114 &1676590048 MonoBehaviour: m_ObjectHideFlags: 0 @@ -8325,7 +8340,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!114 &1730192709 MonoBehaviour: m_ObjectHideFlags: 0 @@ -8359,7 +8374,6 @@ Transform: m_Children: - {fileID: 56584889} - {fileID: 2134815026} - - {fileID: 2090444089} m_Father: {fileID: 0} m_RootOrder: 11 --- !u!1 &1736454666 @@ -8859,7 +8873,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 61dddfdc5e0e44ca298d8f46f7f5a915, type: 3} m_Name: m_EditorClassIdentifier: - selectedFlowchart: {fileID: 807616590} + selectedFlowchart: {fileID: 56584893} --- !u!4 &1791050794 Transform: m_ObjectHideFlags: 1 @@ -9951,49 +9965,6 @@ Canvas: m_SortingLayerID: 0 m_SortingOrder: 1 m_TargetDisplay: 0 ---- !u!1 &2090444088 -GameObject: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - serializedVersion: 4 - m_Component: - - 4: {fileID: 2090444089} - - 114: {fileID: 2090444090} - m_Layer: 0 - m_Name: LuaScript - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &2090444089 -Transform: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 2090444088} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 1730192710} - m_RootOrder: 2 ---- !u!114 &2090444090 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 2090444088} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 446caeace65234baaacd52095d24f101, type: 3} - m_Name: - m_EditorClassIdentifier: - luaEnvironment: {fileID: 0} - luaFile: {fileID: 0} - luaScript: - runAsCoroutine: 1 --- !u!1001 &2092185197 Prefab: m_ObjectHideFlags: 0 diff --git a/Assets/Tests/Lua/LuaEnvironmentTests.unity b/Assets/Tests/Lua/LuaEnvironmentTests.unity index 5cfe865f..e1d9459e 100644 --- a/Assets/Tests/Lua/LuaEnvironmentTests.unity +++ b/Assets/Tests/Lua/LuaEnvironmentTests.unity @@ -447,7 +447,7 @@ Transform: - {fileID: 1828947836} - {fileID: 1463630763} m_Father: {fileID: 0} - m_RootOrder: 11 + m_RootOrder: 10 --- !u!1 &304626605 GameObject: m_ObjectHideFlags: 0 @@ -552,8 +552,8 @@ 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 = gettime()\nwaitfor(fn, 1)\ncheck(gettime() - - t >= 1)\n\n-- Test fungus.waitfor() exits if the function returns true\n-- If + fn()\n return value\nend\n\nt = time.timeSinceLevelLoad\nwaitfor(fn, 1)\ncheck(time.timeSinceLevelLoad + - 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\nwaitfor(fn, 1)\n\npass()" runAsCoroutine: 1 --- !u!114 &305346653 @@ -576,56 +576,6 @@ MonoBehaviour: hasFailed: 0 executeMethods: 2 executeMethodName: OnExecute ---- !u!1001 &364012152 -Prefab: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - m_TransformParent: {fileID: 1900871526} - m_Modifications: - - target: {fileID: 495584, guid: 49031c561e16d4fcf91c12153f8e0b25, type: 2} - propertyPath: m_LocalPosition.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 495584, guid: 49031c561e16d4fcf91c12153f8e0b25, type: 2} - propertyPath: m_LocalPosition.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 495584, guid: 49031c561e16d4fcf91c12153f8e0b25, type: 2} - propertyPath: m_LocalPosition.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 495584, guid: 49031c561e16d4fcf91c12153f8e0b25, type: 2} - propertyPath: m_LocalRotation.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 495584, guid: 49031c561e16d4fcf91c12153f8e0b25, type: 2} - propertyPath: m_LocalRotation.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 495584, guid: 49031c561e16d4fcf91c12153f8e0b25, type: 2} - propertyPath: m_LocalRotation.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 495584, guid: 49031c561e16d4fcf91c12153f8e0b25, type: 2} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 495584, guid: 49031c561e16d4fcf91c12153f8e0b25, type: 2} - propertyPath: m_RootOrder - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 11493126, guid: 49031c561e16d4fcf91c12153f8e0b25, type: 2} - propertyPath: timeScale - value: -1 - objectReference: {fileID: 0} - m_RemovedComponents: [] - m_ParentPrefab: {fileID: 100100000, guid: 49031c561e16d4fcf91c12153f8e0b25, type: 2} - m_IsPrefabParent: 0 ---- !u!4 &364012153 stripped -Transform: - m_PrefabParentObject: {fileID: 495584, guid: 49031c561e16d4fcf91c12153f8e0b25, type: 2} - m_PrefabInternal: {fileID: 364012152} --- !u!1 &367860753 GameObject: m_ObjectHideFlags: 0 @@ -718,7 +668,6 @@ MonoBehaviour: m_EditorClassIdentifier: fungusModule: 0 activeLanguage: en - timeScale: -1 stringTables: [] registerTypes: - {fileID: 4900000, guid: 9c3ab7a98d51241bbb499643399fa761, type: 3} @@ -750,7 +699,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 @@ -785,7 +734,7 @@ Transform: - {fileID: 236999594} - {fileID: 305346651} m_Father: {fileID: 0} - m_RootOrder: 9 + m_RootOrder: 8 --- !u!1001 &652121444 Prefab: m_ObjectHideFlags: 0 @@ -960,7 +909,7 @@ Transform: - {fileID: 2093904138} - {fileID: 681659774} m_Father: {fileID: 0} - m_RootOrder: 7 + m_RootOrder: 6 --- !u!1 &804588883 GameObject: m_ObjectHideFlags: 0 @@ -1031,7 +980,6 @@ MonoBehaviour: m_EditorClassIdentifier: fungusModule: 0 activeLanguage: en - timeScale: -1 stringTables: [] registerTypes: - {fileID: 4900000, guid: 9c3ab7a98d51241bbb499643399fa761, type: 3} @@ -1184,7 +1132,6 @@ MonoBehaviour: m_EditorClassIdentifier: fungusModule: 0 activeLanguage: en - timeScale: -1 stringTables: [] registerTypes: - {fileID: 4900000, guid: 9c3ab7a98d51241bbb499643399fa761, type: 3} @@ -1202,113 +1149,6 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: remoteDebugger: 0 ---- !u!1 &1124932171 -GameObject: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - serializedVersion: 4 - m_Component: - - 4: {fileID: 1124932172} - - 114: {fileID: 1124932174} - - 114: {fileID: 1124932173} - m_Layer: 0 - m_Name: LuaScript - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &1124932172 -Transform: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1124932171} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: [] - m_Father: {fileID: 1900871526} - m_RootOrder: 1 ---- !u!114 &1124932173 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1124932171} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 446caeace65234baaacd52095d24f101, type: 3} - m_Name: - m_EditorClassIdentifier: - luaEnvironment: {fileID: 0} - luaFile: {fileID: 0} - luaScript: '-- Test time functions and time scaling - - - local t = 0 - - local timer = time.time - - - -- Wait with timeScale = -1 - - -- Should take 1 second in realtime to wait for 1 second - - t = gettime() - - wait(1) - - t = gettime() - t - - check(t >= 1) - - - -- Wait with timeScale = 0.5 - - -- Should take 2 seconds in realtime to wait for 1 second - - settimescale(0.5) - - t = gettime() - - wait(1) - - t = gettime() - t - - check(t >= 1) - - - -- The real elapsed time should be 3 seconds - - elapsed = (time.time - timer) - - check(elapsed >= 3) - - - pass()' - runAsCoroutine: 1 ---- !u!114 &1124932174 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1124932171} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 6ee79785811ba49399c1b56d7309e3df, type: 3} - m_Name: - m_EditorClassIdentifier: - executeAfterTime: 1 - repeatExecuteTime: 1 - repeatEveryTime: 1 - executeAfterFrames: 1 - repeatExecuteFrame: 1 - repeatEveryFrame: 1 - hasFailed: 0 - executeMethods: 2 - executeMethodName: OnExecute --- !u!4 &1167396341 stripped Transform: m_PrefabParentObject: {fileID: 495584, guid: 49031c561e16d4fcf91c12153f8e0b25, type: 2} @@ -1365,7 +1205,7 @@ Transform: - {fileID: 304626606} - {fileID: 113453956} m_Father: {fileID: 0} - m_RootOrder: 10 + m_RootOrder: 9 --- !u!1 &1258610945 GameObject: m_ObjectHideFlags: 0 @@ -1609,7 +1449,6 @@ MonoBehaviour: m_EditorClassIdentifier: fungusModule: 0 activeLanguage: en - timeScale: -1 stringTables: [] registerTypes: - {fileID: 4900000, guid: 9c3ab7a98d51241bbb499643399fa761, type: 3} @@ -1778,7 +1617,7 @@ Transform: - {fileID: 1932132174} - {fileID: 804588884} m_Father: {fileID: 0} - m_RootOrder: 12 + m_RootOrder: 11 --- !u!1 &1549270604 GameObject: m_ObjectHideFlags: 1 @@ -1818,7 +1657,7 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 8 + m_RootOrder: 7 --- !u!1 &1575922005 GameObject: m_ObjectHideFlags: 0 @@ -1869,7 +1708,7 @@ Transform: - {fileID: 159008373} - {fileID: 1073989295} m_Father: {fileID: 0} - m_RootOrder: 14 + m_RootOrder: 13 --- !u!1 &1734188738 GameObject: m_ObjectHideFlags: 0 @@ -2193,6 +2032,7 @@ MonoBehaviour: errorMessage: indentLevel: 0 luaEnvironment: {fileID: 0} + luaFile: {fileID: 0} luaScript: 'store.test = "ok" @@ -2365,58 +2205,7 @@ Transform: - {fileID: 870653407} - {fileID: 156811091} m_Father: {fileID: 0} - m_RootOrder: 13 ---- !u!1 &1900871524 -GameObject: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - serializedVersion: 4 - m_Component: - - 4: {fileID: 1900871526} - - 114: {fileID: 1900871525} - m_Layer: 0 - m_Name: TimeTest - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 0 ---- !u!114 &1900871525 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1900871524} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: b1dba0b27b0864740a8720e920aa88c0, type: 3} - m_Name: - m_EditorClassIdentifier: - timeout: 5 - ignored: 0 - succeedAfterAllAssertionsAreExecuted: 0 - expectException: 0 - expectedExceptionList: - succeedWhenExceptionIsThrown: 0 - includedPlatforms: -1 - platformsToIgnore: [] - dynamic: 0 - dynamicTypeName: ---- !u!4 &1900871526 -Transform: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1900871524} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_Children: - - {fileID: 364012153} - - {fileID: 1124932172} - m_Father: {fileID: 0} - m_RootOrder: 6 + m_RootOrder: 12 --- !u!1 &1932132173 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Tests/TestAssets/Text/TestLua.txt b/Assets/Tests/TestAssets/Text/TestLua.txt new file mode 100644 index 00000000..4cab3960 --- /dev/null +++ b/Assets/Tests/TestAssets/Text/TestLua.txt @@ -0,0 +1,3 @@ +-- Check that Lua in a file executes ok in ExecuteLua command +local v = 10 +check(v == 10) diff --git a/Assets/Tests/TestAssets/Text/TestLua.txt.meta b/Assets/Tests/TestAssets/Text/TestLua.txt.meta new file mode 100644 index 00000000..c07de567 --- /dev/null +++ b/Assets/Tests/TestAssets/Text/TestLua.txt.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6cbce76ae849c40cb86ed0bb1b6e1a95 +timeCreated: 1461651736 +licenseType: Free +TextScriptImporter: + userData: + assetBundleName: + assetBundleVariant: