diff --git a/Assets/AssetStoreTools/Editor/AssetStoreTools.dll b/Assets/AssetStoreTools/Editor/AssetStoreTools.dll index e64fad36..b8e299f0 100644 Binary files a/Assets/AssetStoreTools/Editor/AssetStoreTools.dll and b/Assets/AssetStoreTools/Editor/AssetStoreTools.dll differ diff --git a/Assets/AssetStoreTools/Editor/AssetStoreTools.dll.meta b/Assets/AssetStoreTools/Editor/AssetStoreTools.dll.meta index 5244b496..c3b7c6a0 100644 --- a/Assets/AssetStoreTools/Editor/AssetStoreTools.dll.meta +++ b/Assets/AssetStoreTools/Editor/AssetStoreTools.dll.meta @@ -1,22 +1,34 @@ fileFormatVersion: 2 -guid: f02b3fe0a866fca419671914a860554a +guid: 46975cd389724d0499db55591d961a35 +timeCreated: 1499691956 +licenseType: Store PluginImporter: - serializedVersion: 1 + serializedVersion: 2 iconMap: {} executionOrder: {} isPreloaded: 0 + isOverridable: 0 platformData: - Any: - enabled: 0 - settings: {} - Editor: - enabled: 1 - settings: - DefaultValueInitialized: true - WindowsStoreApps: - enabled: 0 - settings: - CPU: AnyCPU + data: + first: + Any: + second: + enabled: 0 + settings: {} + data: + first: + Editor: Editor + second: + enabled: 1 + settings: + DefaultValueInitialized: true + data: + first: + Windows Store Apps: WindowsStoreApps + second: + enabled: 0 + settings: + CPU: AnyCPU userData: assetBundleName: assetBundleVariant: diff --git a/Assets/AssetStoreTools/Editor/AssetStoreToolsExtra.dll b/Assets/AssetStoreTools/Editor/AssetStoreToolsExtra.dll index 9113c327..2b1615cc 100644 Binary files a/Assets/AssetStoreTools/Editor/AssetStoreToolsExtra.dll and b/Assets/AssetStoreTools/Editor/AssetStoreToolsExtra.dll differ diff --git a/Assets/AssetStoreTools/Editor/AssetStoreToolsExtra.dll.meta b/Assets/AssetStoreTools/Editor/AssetStoreToolsExtra.dll.meta index 3af281fc..84563037 100644 --- a/Assets/AssetStoreTools/Editor/AssetStoreToolsExtra.dll.meta +++ b/Assets/AssetStoreTools/Editor/AssetStoreToolsExtra.dll.meta @@ -1,22 +1,34 @@ fileFormatVersion: 2 -guid: 07e97bd03b7bdeb40bbc176326cd8d7a +guid: a4f7ad432f1fed24caa2acbe1ceeef39 +timeCreated: 1499692003 +licenseType: Store PluginImporter: - serializedVersion: 1 + serializedVersion: 2 iconMap: {} executionOrder: {} isPreloaded: 0 + isOverridable: 0 platformData: - Any: - enabled: 0 - settings: {} - Editor: - enabled: 1 - settings: - DefaultValueInitialized: true - WindowsStoreApps: - enabled: 0 - settings: - CPU: AnyCPU + data: + first: + Any: + second: + enabled: 0 + settings: {} + data: + first: + Editor: Editor + second: + enabled: 1 + settings: + DefaultValueInitialized: true + data: + first: + Windows Store Apps: WindowsStoreApps + second: + enabled: 0 + settings: + CPU: AnyCPU userData: assetBundleName: assetBundleVariant: diff --git a/Assets/AssetStoreTools/Editor/DroidSansMono.ttf.meta b/Assets/AssetStoreTools/Editor/DroidSansMono.ttf.meta index c0e7824e..8347e678 100644 --- a/Assets/AssetStoreTools/Editor/DroidSansMono.ttf.meta +++ b/Assets/AssetStoreTools/Editor/DroidSansMono.ttf.meta @@ -1,5 +1,7 @@ fileFormatVersion: 2 -guid: 928f503de488e44408a8625d75d54c61 +guid: d54231d61af8b414486b80e17598cce1 +timeCreated: 1499692004 +licenseType: Store TrueTypeFontImporter: serializedVersion: 2 fontSize: 16 diff --git a/Assets/AssetStoreTools/Editor/icon.png.meta b/Assets/AssetStoreTools/Editor/icon.png.meta index 8813c5d6..642a0457 100644 --- a/Assets/AssetStoreTools/Editor/icon.png.meta +++ b/Assets/AssetStoreTools/Editor/icon.png.meta @@ -1,5 +1,7 @@ fileFormatVersion: 2 -guid: 3ef5b3d0acd79c3499f502f1b991678a +guid: 7d783a70b51365a49a04d3f369611b99 +timeCreated: 1499692003 +licenseType: Store TextureImporter: fileIDToRecycleName: {} serializedVersion: 2 @@ -25,7 +27,7 @@ TextureImporter: cubemapConvolutionExponent: 1.5 seamlessCubemap: 0 textureFormat: -1 - maxTextureSize: 1024 + maxTextureSize: 2048 textureSettings: filterMode: -1 aniso: -1 diff --git a/Assets/Fungus/Docs/CHANGELOG.txt b/Assets/Fungus/Docs/CHANGELOG.txt index 829a72ba..d21f6b8a 100644 --- a/Assets/Fungus/Docs/CHANGELOG.txt +++ b/Assets/Fungus/Docs/CHANGELOG.txt @@ -2,6 +2,104 @@ Changelog {#changelog} ========= [TOC] +v3.8.0 {#v3_8_0} +====== + +Many thanks to contributors stevehalliwell, FrederickKDP, MeMark2, KVinS, charblar, FatPuzo for their work on this release! + +## Added +- Added Flowchart.HasBlock() and ExecuteIfHasBlock() methods +- Added Global Variable support. Variables have new 'Global' variable scope. +- Added GlobalVar demo scene + +## Changed +- Updated project version to Unity 2017.4.0f1 +- Refactored the set variable system to make it easier to add variable comparison options +- Added comparison and setting of GameObjects variables +- Updated Batch for newer versions of Unity3D web player #650 + +## Fixed +- Fixed compile errors in Unity 2018.1 beta +- Fixed compiler warnings in Untity2017.3 +- Fixed repeat play of music #659 +- Fixed conflicting EditorResource folder issue #664 +- Fixed SaveMenu DontDestroyOnLoad problems #661 +- Fixed docs: the block name in 6 of "Connections between Blocks" section from "Block2" to "Start" #663 +- Fixed lua say() function to match new say method parameters + +v3.7.0 {#v3_7_0} +====== + +Many thanks to maintainer Steve Halliwell for all the amazing new functionality in this release! + +## Added +- Added Playground examples showing 3 simple arcade games made using Fungus +- Added Rigidbody2D variable type +- Added Vector3 FungusCommands - Fields, Normalise, Convert to Vector2, Arithetic +- Added TransformProperty FungusCommand. Get and Set a transform's fields and properties. Does not currently support rotation, localRotation nor the Mat4x4 commands as we do not have the appropriate FungusVariables to store them in +- Added FungusCommand to Reload Current Scene +- Added Rigidbody2D FungusCommands - AddForce, AddTorque, StopMotion +- Added Input GetAxis fungusCommand, fetch Input.GetAxis and store in a FloatData +- SpawnObject FungusCommand can now store the gameobject it instantiates and can spawn at itself +- Destroy FungusCommand can now be told to pass down a delay to Destroy +- Added Fungus Commands for most of MathF +- Added Math demo scene +- Added Mouse fungus event demo scene +- Added Monobehaviour fungus event handlers and physics demo scene +- Added LeanTween commands and demo scene that approximates the old iTween demo +- Added SpeakingCharacter property to SayDialog +- Added Fungus panel in editor preferences +- Added option to toggle off the fungus icon in the hierarchy in case it conflicts with other tools or is just undesired +- Added TextTag WVO WaitForVoiceOver #572 +- Added ability to show variable list in the Flowchart Inspector #643 +- OpenURL FungusCommand renamed, fixes #554 #642 + +## Changed +- SaveManager now uses json files in a FungusSaves sub directory for all platforms but webplayer & webgl which still use playerprefs +- GetCommandInfo returns the highest priority CommandInfo to better support multiple names while maintaining what is shown in the inspector +- Allow multiple CommandInfos to be added to a class SpawnObject can now also be found under GameObject/Instantiate +- Changed Fungus icon loading to use FungusEditorResources + +## Fixed +- Fixed typo in BlockEditor.BlockField() #633 +- Fixed custom editor for ElseIf command #630 +- Fixed Prefab Variable Dereferencing #618 +- Fixed typo in Set Interactable description #647 +- Fixed choice dialogues were not set to stay during the MenuDialogue #640 +- Fixed camera fading and panning at the same time (thanks to iBicha!) #624 +- Fixed warnings on Unity 2017.2 + +v3.6.0 {#v3_6_0} +====== + +## Added +- Support use of \n newline character in Say and Conversation text +- Added Fungus-Playmaker integration package in Fungus/Integrations/PlayMaker #602 - thanks Nilihum +- Added Delete Save Data button to Save Menu inspector. +- Variable substitution works in Set Variable (String) command +- New "BlockNameAndCustom" Keymode for Save Point command, use both block name and custom key together. #597 - thanks Trieger +- Added portrait DimColor #601 - thanks MorningFunGame +- Lua If and Lua Else If commands #609 - thanks PillowFightIo +- Stop a named Block in a Flowchart +- Added utility to convert all files to Mac line endings + +## Changed +- Made all methods virtual in SayDialog.cs #607 thanks PillowFightIo +- Updated project to Unity 5.6.1, fixed some warnings. +- Use transform.Find instead of deprecated transform.FindChild +- Replaced some uses of slow GameObject.FindObjectOfType() and FindDerivedTypes() + +## Fixed +- Fixed Write command "Clear Text" option not working #594 +- Fixed portrait hide bug in conversation #590 - thanks to lealeelu +- Fixed stopping audio in conversation #592 - thanks to lealeelu +- Fixed can't use FungusLua separately to rest of Fungus #596 +- Fixed can't inspect disabled Flowchart #598 +- Fixed Cmd+Left Click doesn't register as right click on OSX #595 +- Fixed luautils won't work on FungusLua standalone #604 +- Fixed Save Menu: clicking to left of collapsed menu clicks hidden buttons #615 +- Fixed Localization only localizes character name, not story text #611, #614 + v3.5.1 {#v3_5_1} ====== diff --git a/Assets/Fungus/EditorResources/FungusEditorResources.asset b/Assets/Fungus/EditorResources/FungusEditorResources.asset index 05ea3abc..0e6ef67d 100644 --- a/Assets/Fungus/EditorResources/FungusEditorResources.asset +++ b/Assets/Fungus/EditorResources/FungusEditorResources.asset @@ -27,6 +27,9 @@ MonoBehaviour: duplicate: free: {fileID: 2800000, guid: c97f334c466215a4f93eff31de3c1591, type: 3} pro: {fileID: 2800000, guid: 2f17490d993c84bd7872ef6588ffba47, type: 3} + fungus_mushroom: + free: {fileID: 2800000, guid: 1c99c9bf7557e23469ed5dfce00504c0, type: 3} + pro: {fileID: 2800000, guid: 6368c1c16ebb1694091262337e4f8c44, type: 3} up: free: {fileID: 2800000, guid: 8f1242ad894201f43b2b6d52fd990f77, type: 3} pro: {fileID: 2800000, guid: 2a76a781db2994b33b83cd84b8835da7, type: 3} diff --git a/Assets/Fungus/EditorResources/FungusEditorResources.asset.meta b/Assets/Fungus/EditorResources/FungusEditorResources.asset.meta index c92acc45..5b3d0b54 100644 --- a/Assets/Fungus/EditorResources/FungusEditorResources.asset.meta +++ b/Assets/Fungus/EditorResources/FungusEditorResources.asset.meta @@ -1,8 +1,9 @@ fileFormatVersion: 2 guid: 29cae11326cb84802b83fc3ff25a47e8 -timeCreated: 1478978272 +timeCreated: 1495441032 licenseType: Free NativeFormatImporter: + mainObjectFileID: 11400000 userData: assetBundleName: assetBundleVariant: diff --git a/Assets/Fungus/EditorResources/Icons/Pro/fungus_mushroom.png b/Assets/Fungus/EditorResources/Icons/Pro/fungus_mushroom.png new file mode 100644 index 00000000..ab22ce9c Binary files /dev/null and b/Assets/Fungus/EditorResources/Icons/Pro/fungus_mushroom.png differ diff --git a/Assets/Fungus/EditorResources/Icons/Pro/fungus_mushroom.png.meta b/Assets/Fungus/EditorResources/Icons/Pro/fungus_mushroom.png.meta new file mode 100644 index 00000000..360d5b0d --- /dev/null +++ b/Assets/Fungus/EditorResources/Icons/Pro/fungus_mushroom.png.meta @@ -0,0 +1,92 @@ +fileFormatVersion: 2 +guid: 6368c1c16ebb1694091262337e4f8c44 +timeCreated: 1500456217 +licenseType: Free +TextureImporter: + fileIDToRecycleName: {} + serializedVersion: 4 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 0 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + filterMode: 1 + aniso: -1 + mipBias: -1 + wrapMode: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spritePixelsToUnits: 100 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 2 + textureShape: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - buildTarget: DefaultTexturePlatform + maxTextureSize: 1024 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + - buildTarget: Standalone + maxTextureSize: 1024 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + - buildTarget: Android + maxTextureSize: 1024 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + - buildTarget: WebGL + maxTextureSize: 1024 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + spritePackingTag: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/EditorResources/Icons/fungus_mushroom.png b/Assets/Fungus/EditorResources/Icons/fungus_mushroom.png new file mode 100644 index 00000000..ab22ce9c Binary files /dev/null and b/Assets/Fungus/EditorResources/Icons/fungus_mushroom.png differ diff --git a/Assets/Fungus/EditorResources/Icons/fungus_mushroom.png.meta b/Assets/Fungus/EditorResources/Icons/fungus_mushroom.png.meta new file mode 100644 index 00000000..6433d929 --- /dev/null +++ b/Assets/Fungus/EditorResources/Icons/fungus_mushroom.png.meta @@ -0,0 +1,92 @@ +fileFormatVersion: 2 +guid: 1c99c9bf7557e23469ed5dfce00504c0 +timeCreated: 1500455974 +licenseType: Free +TextureImporter: + fileIDToRecycleName: {} + serializedVersion: 4 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 0 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + filterMode: 1 + aniso: -1 + mipBias: -1 + wrapMode: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spritePixelsToUnits: 100 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 2 + textureShape: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - buildTarget: DefaultTexturePlatform + maxTextureSize: 1024 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + - buildTarget: Standalone + maxTextureSize: 1024 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + - buildTarget: Android + maxTextureSize: 1024 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + - buildTarget: WebGL + maxTextureSize: 1024 + textureFormat: -1 + textureCompression: 0 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + spritePackingTag: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Integrations/Playmaker.meta b/Assets/Fungus/Integrations/Playmaker.meta new file mode 100644 index 00000000..88e769b7 --- /dev/null +++ b/Assets/Fungus/Integrations/Playmaker.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: f24b15e84ed1f42e39fd80dd9042c882 +folderAsset: yes +timeCreated: 1489513669 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Integrations/Playmaker/Fungus-PlayMaker.unitypackage b/Assets/Fungus/Integrations/Playmaker/Fungus-PlayMaker.unitypackage index a03e563e..8af0d970 100644 Binary files a/Assets/Fungus/Integrations/Playmaker/Fungus-PlayMaker.unitypackage and b/Assets/Fungus/Integrations/Playmaker/Fungus-PlayMaker.unitypackage differ diff --git a/Assets/Fungus/Integrations/Playmaker/Fungus-PlayMaker.unitypackage.meta b/Assets/Fungus/Integrations/Playmaker/Fungus-PlayMaker.unitypackage.meta new file mode 100644 index 00000000..3560ad24 --- /dev/null +++ b/Assets/Fungus/Integrations/Playmaker/Fungus-PlayMaker.unitypackage.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 81dbcde0f90df4e9ba9ca2794490e57a +timeCreated: 1491251885 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Integrations/Playmaker/ReadMe.txt b/Assets/Fungus/Integrations/Playmaker/ReadMe.txt index 2c9a741d..95a395bc 100644 --- a/Assets/Fungus/Integrations/Playmaker/ReadMe.txt +++ b/Assets/Fungus/Integrations/Playmaker/ReadMe.txt @@ -21,4 +21,5 @@ Usage To write Playmaker variable values to Fungus Variables, use the Action Browser > ScriptControl > Write To Fungus command. To execute a block in a Fungus flowchart from , use the Action Browser > ScriptControl > Playmaker Execute Block command. To trigger a global state transition in Playmaker from Fungus, use the Playmaker > Global State Transition command. -To read Fungus variable values into Playmaker Variables, use the Action Browser > ScriptControl > Receive Fungus Variable command. \ No newline at end of file +To read Fungus variable values into Playmaker Variables, use the Action Browser > ScriptControl > Receive Fungus Variable command. +To write Fungus variable values from the inspector into Playmaker global variables, use the Playmaker > Write To Playmaker command. \ No newline at end of file diff --git a/Assets/Fungus/Integrations/Playmaker/ReadMe.txt.meta b/Assets/Fungus/Integrations/Playmaker/ReadMe.txt.meta new file mode 100644 index 00000000..18268499 --- /dev/null +++ b/Assets/Fungus/Integrations/Playmaker/ReadMe.txt.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1cd4689522982464db8b5de6a590db9b +timeCreated: 1491251886 +licenseType: Free +TextScriptImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Condition.cs b/Assets/Fungus/Scripts/Commands/Condition.cs index d0c4e38f..a8dacb34 100644 --- a/Assets/Fungus/Scripts/Commands/Condition.cs +++ b/Assets/Fungus/Scripts/Commands/Condition.cs @@ -8,11 +8,6 @@ namespace Fungus [AddComponentMenu("")] public abstract class Condition : Command { - [Tooltip("The type of comparison to be performed")] - [SerializeField] protected CompareOperator compareOperator; - - #region Public members - public static string GetOperatorDescription(CompareOperator compareOperator) { string summary = ""; @@ -41,6 +36,157 @@ namespace Fungus return summary; } + #region Public members + + public override void OnEnter() + { + + if (ParentBlock == null) + { + return; + } + + if( !HasNeededProperties() ) + { + Continue(); + return; + } + + if( !this.IsElseIf ) + { + EvaluateAndContinue(); + } + else + { + System.Type previousCommandType = ParentBlock.GetPreviousActiveCommandType(); + + if (previousCommandType.IsSubclassOf(typeof(Condition))) + { + // Else If behaves the same as an If command + EvaluateAndContinue(); + } + else + { + // Else If behaves mostly like an Else command, + // but will also jump to a following Else command. + + // Stop if this is the last command in the list + if (CommandIndex >= ParentBlock.CommandList.Count - 1) + { + StopParentBlock(); + return; + } + + // Find the next End command at the same indent level as this Else If command + int indent = indentLevel; + for (int i = CommandIndex + 1; i < ParentBlock.CommandList.Count; ++i) + { + var command = ParentBlock.CommandList[i]; + + if (command.IndentLevel == indent) + { + System.Type type = command.GetType(); + if (type == typeof(End)) + { + // Execute command immediately after the Else or End command + Continue(command.CommandIndex + 1); + return; + } + } + } + + // No End command found + StopParentBlock(); + } + } + } + + public override bool OpenBlock() + { + return true; + } + #endregion + + protected virtual void EvaluateAndContinue() + { + if (EvaluateCondition()) + { + OnTrue(); + } + else + { + OnFalse(); + } + } + + protected virtual void OnTrue() + { + Continue(); + } + + protected virtual void OnFalse() + { + // Last command in block + if (CommandIndex >= ParentBlock.CommandList.Count) + { + StopParentBlock(); + return; + } + + // Find the next Else, ElseIf or End command at the same indent level as this If command + for (int i = CommandIndex + 1; i < ParentBlock.CommandList.Count; ++i) + { + Command nextCommand = ParentBlock.CommandList[i]; + + if (nextCommand == null) + { + continue; + } + + // Find next command at same indent level as this If command + // Skip disabled commands, comments & labels + if (!((Command)nextCommand).enabled || + nextCommand.GetType() == typeof(Comment) || + nextCommand.GetType() == typeof(Label) || + nextCommand.IndentLevel != indentLevel) + { + continue; + } + + System.Type type = nextCommand.GetType(); + if (type == typeof(Else) || + type == typeof(End)) + { + if (i >= ParentBlock.CommandList.Count - 1) + { + // Last command in Block, so stop + StopParentBlock(); + } + else + { + // Execute command immediately after the Else or End command + Continue(nextCommand.CommandIndex + 1); + return; + } + } + else if (type.IsSubclassOf(typeof(Condition)) && (nextCommand as Condition).IsElseIf) + { + // Execute the Else If command + Continue(i); + + return; + } + } + + // No matching End command found, so just stop the block + StopParentBlock(); + } + + protected abstract bool EvaluateCondition(); + + protected abstract bool HasNeededProperties(); + + protected virtual bool IsElseIf { get { return false; } } } } \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Destroy.cs b/Assets/Fungus/Scripts/Commands/Destroy.cs index 5aa4615f..8288d4b3 100644 --- a/Assets/Fungus/Scripts/Commands/Destroy.cs +++ b/Assets/Fungus/Scripts/Commands/Destroy.cs @@ -9,23 +9,30 @@ namespace Fungus /// /// Destroys a specified game object in the scene. /// - [CommandInfo("Scripting", - "Destroy", + [CommandInfo("Scripting", + "Destroy", "Destroys a specified game object in the scene.")] [AddComponentMenu("")] [ExecuteInEditMode] public class Destroy : Command - { + { [Tooltip("Reference to game object to destroy")] [SerializeField] protected GameObjectData _targetGameObject; + [Tooltip("Optional delay given to destroy")] + [SerializeField] + protected FloatData destroyInXSeconds = new FloatData(0); + #region Public members public override void OnEnter() { if (_targetGameObject.Value != null) { - Destroy(_targetGameObject.Value); + if (destroyInXSeconds.Value != 0) + Destroy(_targetGameObject, destroyInXSeconds.Value); + else + Destroy(_targetGameObject.Value); } Continue(); @@ -38,7 +45,7 @@ namespace Fungus return "Error: No game object selected"; } - return _targetGameObject.Value.name; + return _targetGameObject.Value.name + (destroyInXSeconds.Value == 0 ? "" : " in " + destroyInXSeconds.Value.ToString()); } public override Color GetButtonColor() @@ -46,6 +53,14 @@ namespace Fungus return new Color32(235, 191, 217, 255); } + public override bool HasReference(Variable variable) + { + if (_targetGameObject.gameObjectRef == variable || destroyInXSeconds.floatRef == variable) + return true; + + return false; + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/ElseIf.cs b/Assets/Fungus/Scripts/Commands/ElseIf.cs index e6cabf71..eee6ab14 100644 --- a/Assets/Fungus/Scripts/Commands/ElseIf.cs +++ b/Assets/Fungus/Scripts/Commands/ElseIf.cs @@ -12,54 +12,11 @@ namespace Fungus "Else If", "Marks the start of a command block to be executed when the preceding If statement is False and the test expression is true.")] [AddComponentMenu("")] - public class ElseIf : If + public class ElseIf : VariableCondition { - #region Public members - - public override void OnEnter() - { - System.Type previousCommandType = ParentBlock.GetPreviousActiveCommandType(); - - if (previousCommandType == typeof(If) || - previousCommandType == typeof(ElseIf) ) - { - // Else If behaves the same as an If command - EvaluateAndContinue(); - } - else - { - // Else If behaves mostly like an Else command, - // but will also jump to a following Else command. - - // Stop if this is the last command in the list - if (CommandIndex >= ParentBlock.CommandList.Count - 1) - { - StopParentBlock(); - return; - } + protected override bool IsElseIf { get { return true; } } - // Find the next End command at the same indent level as this Else If command - int indent = indentLevel; - for (int i = CommandIndex + 1; i < ParentBlock.CommandList.Count; ++i) - { - var command = ParentBlock.CommandList[i]; - - if (command.IndentLevel == indent) - { - System.Type type = command.GetType(); - if (type == typeof(End)) - { - // Execute command immediately after the Else or End command - Continue(command.CommandIndex + 1); - return; - } - } - } - - // No End command found - StopParentBlock(); - } - } + #region Public members public override bool OpenBlock() { diff --git a/Assets/Fungus/Scripts/Commands/If.cs b/Assets/Fungus/Scripts/Commands/If.cs index 680c17f8..c8d15fb0 100644 --- a/Assets/Fungus/Scripts/Commands/If.cs +++ b/Assets/Fungus/Scripts/Commands/If.cs @@ -12,189 +12,10 @@ namespace Fungus "If", "If the test expression is true, execute the following command block.")] [AddComponentMenu("")] - public class If : Condition + public class If : VariableCondition { - [Tooltip("Variable to use in expression")] - [VariableProperty(typeof(BooleanVariable), - typeof(IntegerVariable), - typeof(FloatVariable), - typeof(StringVariable))] - [SerializeField] protected Variable variable; - - [Tooltip("Boolean value to compare against")] - [SerializeField] protected BooleanData booleanData; - - [Tooltip("Integer value to compare against")] - [SerializeField] protected IntegerData integerData; - - [Tooltip("Float value to compare against")] - [SerializeField] protected FloatData floatData; - - [Tooltip("String value to compare against")] - [SerializeField] protected StringDataMulti stringData; - - protected virtual void EvaluateAndContinue() - { - if (EvaluateCondition()) - { - OnTrue(); - } - else - { - OnFalse(); - } - } - - protected virtual void OnTrue() - { - Continue(); - } - - protected virtual void OnFalse() - { - // Last command in block - if (CommandIndex >= ParentBlock.CommandList.Count) - { - StopParentBlock(); - return; - } - - // Find the next Else, ElseIf or End command at the same indent level as this If command - for (int i = CommandIndex + 1; i < ParentBlock.CommandList.Count; ++i) - { - Command nextCommand = ParentBlock.CommandList[i]; - - if (nextCommand == null) - { - continue; - } - - // Find next command at same indent level as this If command - // Skip disabled commands, comments & labels - if (!((Command)nextCommand).enabled || - nextCommand.GetType() == typeof(Comment) || - nextCommand.GetType() == typeof(Label) || - nextCommand.IndentLevel != indentLevel) - { - continue; - } - - System.Type type = nextCommand.GetType(); - if (type == typeof(Else) || - type == typeof(End)) - { - if (i >= ParentBlock.CommandList.Count - 1) - { - // Last command in Block, so stop - StopParentBlock(); - } - else - { - // Execute command immediately after the Else or End command - Continue(nextCommand.CommandIndex + 1); - return; - } - } - else if (type == typeof(ElseIf)) - { - // Execute the Else If command - Continue(i); - - return; - } - } - - // No matching End command found, so just stop the block - StopParentBlock(); - } - - protected virtual bool EvaluateCondition() - { - BooleanVariable booleanVariable = variable as BooleanVariable; - IntegerVariable integerVariable = variable as IntegerVariable; - FloatVariable floatVariable = variable as FloatVariable; - StringVariable stringVariable = variable as StringVariable; - - bool condition = false; - - if (booleanVariable != null) - { - condition = booleanVariable.Evaluate(compareOperator, booleanData.Value); - } - else if (integerVariable != null) - { - condition = integerVariable.Evaluate(compareOperator, integerData.Value); - } - else if (floatVariable != null) - { - condition = floatVariable.Evaluate(compareOperator, floatData.Value); - } - else if (stringVariable != null) - { - condition = stringVariable.Evaluate(compareOperator, stringData.Value); - } - - return condition; - } - #region Public members - - public override void OnEnter() - { - if (ParentBlock == null) - { - return; - } - - if (variable == null) - { - Continue(); - return; - } - - EvaluateAndContinue(); - } - - public override string GetSummary() - { - if (variable == null) - { - return "Error: No variable selected"; - } - - string summary = variable.Key + " "; - summary += Condition.GetOperatorDescription(compareOperator) + " "; - - if (variable.GetType() == typeof(BooleanVariable)) - { - summary += booleanData.GetDescription(); - } - else if (variable.GetType() == typeof(IntegerVariable)) - { - summary += integerData.GetDescription(); - } - else if (variable.GetType() == typeof(FloatVariable)) - { - summary += floatData.GetDescription(); - } - else if (variable.GetType() == typeof(StringVariable)) - { - summary += stringData.GetDescription(); - } - - return summary; - } - - public override bool HasReference(Variable variable) - { - return (variable == this.variable); - } - - public override bool OpenBlock() - { - return true; - } - + public override Color GetButtonColor() { return new Color32(253, 253, 150, 255); diff --git a/Assets/Fungus/Scripts/Commands/Input.meta b/Assets/Fungus/Scripts/Commands/Input.meta new file mode 100644 index 00000000..8d13dfad --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Input.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 90098f8abed37d1418f36896e7e1279d +folderAsset: yes +timeCreated: 1503744400 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Input/GetAxis.cs b/Assets/Fungus/Scripts/Commands/Input/GetAxis.cs new file mode 100644 index 00000000..644ecbb2 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Input/GetAxis.cs @@ -0,0 +1,60 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Fungus +{ + // + /// Store Input.GetAxis in a variable + /// + [CommandInfo("Input", + "GetAxis", + "Store Input.GetAxis in a variable")] + [AddComponentMenu("")] + public class GetAxis : Command + { + [SerializeField] + protected StringData axisName; + + [Tooltip("If true, calls GetAxisRaw instead of GetAxis")] + [SerializeField] + protected bool axisRaw = false; + + [Tooltip("Float to store the value of the GetAxis")] + [SerializeField] + protected FloatData outValue; + + public override void OnEnter() + { + if (axisRaw) + { + outValue.Value = Input.GetAxisRaw(axisName.Value); + } + else + { + outValue.Value = Input.GetAxis(axisName.Value); + } + + Continue(); + } + + public override string GetSummary() + { + return axisName + (axisRaw ? " Raw" : ""); + } + + public override Color GetButtonColor() + { + return new Color32(235, 191, 217, 255); + } + + public override bool HasReference(Variable variable) + { + if (axisName.stringRef == variable || outValue.floatRef == variable) + return true; + + return false; + } + + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Input/GetAxis.cs.meta b/Assets/Fungus/Scripts/Commands/Input/GetAxis.cs.meta new file mode 100644 index 00000000..3c3eef2f --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Input/GetAxis.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: bb18ee740f55ba24680c15466ff13ece +timeCreated: 1503744409 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/LeanTween.meta b/Assets/Fungus/Scripts/Commands/LeanTween.meta new file mode 100644 index 00000000..89ab4ee6 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/LeanTween.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 53bec3476dd0fa945af5703dda0cd24f +folderAsset: yes +timeCreated: 1501401094 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/LeanTween/BaseLeanTweenCommand.cs b/Assets/Fungus/Scripts/Commands/LeanTween/BaseLeanTweenCommand.cs new file mode 100644 index 00000000..e617d284 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/LeanTween/BaseLeanTweenCommand.cs @@ -0,0 +1,116 @@ +using UnityEngine; +using UnityEngine.Serialization; + +namespace Fungus +{ + /// + /// Abstract base class for LeanTween commands. + /// + [ExecuteInEditMode] + public abstract class BaseLeanTweenCommand : Command + { + [Tooltip("Target game object to apply the Tween to")] + [SerializeField] + protected GameObjectData _targetObject; + + [Tooltip("The time in seconds the animation will take to complete")] + [SerializeField] + protected FloatData _duration = new FloatData(1f); + + public enum ToFrom { To, From } + [Tooltip("Does the tween act from current TO destination or is it reversed and act FROM destination to its current")] + [SerializeField] + protected ToFrom _toFrom; + public bool IsInFromMode { get { return _toFrom == ToFrom.From; } } + + public enum AbsAdd { Absolute, Additive } + [Tooltip("Does the tween use the value as a target or as a delta to be added to current.")] + [SerializeField] + protected AbsAdd _absAdd; + public bool IsInAddativeMode { get { return _absAdd == AbsAdd.Additive; } } + + + [Tooltip("The shape of the easing curve applied to the animation")] + [SerializeField] + protected LeanTweenType easeType = LeanTweenType.easeInOutQuad; + + [Tooltip("The type of loop to apply once the animation has completed")] + [SerializeField] + protected LeanTweenType loopType = LeanTweenType.once; + + [Tooltip("Number of times to repeat the tween, -1 is infinite.")] + [SerializeField] + protected int repeats = 0; + + [Tooltip("Stop any previously LeanTweens on this object before adding this one. Warning; expensive.")] + [SerializeField] + protected bool stopPreviousTweens = false; + + [Tooltip("Wait until the tween has finished before executing the next command")] + [SerializeField] + protected bool waitUntilFinished = true; + + + [HideInInspector] protected LTDescr ourTween; + + + protected virtual void OnTweenComplete() + { + Continue(); + } + + #region Public members + + public override void OnEnter() + { + if (_targetObject.Value == null) + { + Continue(); + return; + } + + if (stopPreviousTweens) + { + LeanTween.cancel(_targetObject.Value); + } + + ourTween = ExecuteTween(); + + ourTween.setEase(easeType) + .setRepeat(repeats) + .setLoopType(loopType); + + if (waitUntilFinished) + { + if(ourTween != null) + { + ourTween.setOnComplete(OnTweenComplete); + } + } + else + { + Continue(); + } + } + + public abstract LTDescr ExecuteTween(); + + public override string GetSummary() + { + if (_targetObject.Value == null) + { + return "Error: No target object selected"; + } + + return _targetObject.Value.name + " over " + _duration.Value + " seconds"; + } + + public override Color GetButtonColor() + { + return new Color32(233, 163, 180, 255); + } + + #endregion + + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/LeanTween/BaseLeanTweenCommand.cs.meta b/Assets/Fungus/Scripts/Commands/LeanTween/BaseLeanTweenCommand.cs.meta new file mode 100644 index 00000000..b5346d65 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/LeanTween/BaseLeanTweenCommand.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 22379d19093ceb34098232d6f1b848a0 +timeCreated: 1499564933 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/LeanTween/MoveLean.cs b/Assets/Fungus/Scripts/Commands/LeanTween/MoveLean.cs new file mode 100644 index 00000000..319bb21a --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/LeanTween/MoveLean.cs @@ -0,0 +1,55 @@ + +using UnityEngine; +using UnityEngine.Serialization; +using System.Collections; +using System; + +namespace Fungus +{ + /// + /// Moves a game object to a specified position over time. The position can be defined by a transform in another object (using To Transform) or by setting an absolute position (using To Position, if To Transform is set to None). + /// + [CommandInfo("LeanTween", + "Move", + "Moves a game object to a specified position over time. The position can be defined by a transform in another object (using To Transform) or by setting an absolute position (using To Position, if To Transform is set to None).")] + [AddComponentMenu("")] + [ExecuteInEditMode] + public class MoveLean : BaseLeanTweenCommand + { + [Tooltip("Target transform that the GameObject will move to")] + [SerializeField] + protected TransformData _toTransform; + + [Tooltip("Target world position that the GameObject will move to, if no From Transform is set")] + [SerializeField] + protected Vector3Data _toPosition; + + [Tooltip("Whether to animate in world space or relative to the parent. False by default.")] + [SerializeField] + protected bool isLocal; + + + public override LTDescr ExecuteTween() + { + var loc = _toTransform.Value == null ? _toPosition.Value : _toTransform.Value.position; + + if(IsInAddativeMode) + { + loc += _targetObject.Value.transform.position; + } + + if(IsInFromMode) + { + var cur = _targetObject.Value.transform.position; + _targetObject.Value.transform.position = loc; + loc = cur; + } + + if (isLocal) + return LeanTween.moveLocal(_targetObject.Value, loc, _duration); + else + return LeanTween.move(_targetObject.Value, loc, _duration); + } + + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/LeanTween/MoveLean.cs.meta b/Assets/Fungus/Scripts/Commands/LeanTween/MoveLean.cs.meta new file mode 100644 index 00000000..89e3529a --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/LeanTween/MoveLean.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 3ca31fffe1be42a49b96bbb8b7ff5a50 +timeCreated: 1499566229 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/LeanTween/RotateLean.cs b/Assets/Fungus/Scripts/Commands/LeanTween/RotateLean.cs new file mode 100644 index 00000000..eaa26761 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/LeanTween/RotateLean.cs @@ -0,0 +1,74 @@ + +using UnityEngine; +using UnityEngine.Serialization; +using System.Collections; +using System; + +namespace Fungus +{ + /// + /// Rotates a game object to the specified angles over time. + /// + [CommandInfo("LeanTween", + "Rotate", + "Rotates a game object to the specified angles over time.")] + [AddComponentMenu("")] + [ExecuteInEditMode] + public class RotateLean : BaseLeanTweenCommand + { + [Tooltip("Target transform that the GameObject will rotate to")] + [SerializeField] + protected TransformData _toTransform; + + [Tooltip("Target rotation that the GameObject will rotate to, if no To Transform is set")] + [SerializeField] + protected Vector3Data _toRotation; + + [Tooltip("Whether to animate in world space or relative to the parent. False by default.")] + [SerializeField] + protected bool isLocal; + + public enum RotateMode { PureRotate, LookAt2D, LookAt3D} + [Tooltip("Whether to use the provided Transform or Vector as a target to look at rather than a euler to match.")] + [SerializeField] + protected RotateMode rotateMode = RotateMode.PureRotate; + + + public override LTDescr ExecuteTween() + { + var rot = _toTransform.Value == null ? _toRotation.Value : _toTransform.Value.rotation.eulerAngles; + + if(rotateMode == RotateMode.LookAt3D) + { + var pos = _toTransform.Value == null ? _toRotation.Value : _toTransform.Value.position; + var dif = pos - _targetObject.Value.transform.position; + rot = Quaternion.LookRotation(dif.normalized).eulerAngles; + } + else if(rotateMode == RotateMode.LookAt2D) + { + var pos = _toTransform.Value == null ? _toRotation.Value : _toTransform.Value.position; + var dif = pos - _targetObject.Value.transform.position; + dif.z = 0; + + rot = Quaternion.FromToRotation(_targetObject.Value.transform.up, dif.normalized).eulerAngles; + } + + if (IsInAddativeMode) + { + rot += _targetObject.Value.transform.rotation.eulerAngles; + } + + if (IsInFromMode) + { + var cur = _targetObject.Value.transform.rotation.eulerAngles; + _targetObject.Value.transform.rotation = Quaternion.Euler(rot); + rot = cur; + } + + if (isLocal) + return LeanTween.rotateLocal(_targetObject.Value, rot, _duration); + else + return LeanTween.rotate(_targetObject.Value, rot, _duration); + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/LeanTween/RotateLean.cs.meta b/Assets/Fungus/Scripts/Commands/LeanTween/RotateLean.cs.meta new file mode 100644 index 00000000..78458eb0 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/LeanTween/RotateLean.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: b8feaa22bae049c43a1c6dfe095c498c +timeCreated: 1499583595 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/LeanTween/ScaleLean.cs b/Assets/Fungus/Scripts/Commands/LeanTween/ScaleLean.cs new file mode 100644 index 00000000..cc26391f --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/LeanTween/ScaleLean.cs @@ -0,0 +1,46 @@ + +using UnityEngine; +using UnityEngine.Serialization; +using System.Collections; +using System; + +namespace Fungus +{ + /// + /// Changes a game object's scale to a specified value over time. + /// + [CommandInfo("LeanTween", + "Scale", + "Changes a game object's scale to a specified value over time.")] + [AddComponentMenu("")] + [ExecuteInEditMode] + public class ScaleLean : BaseLeanTweenCommand + { + [Tooltip("Target transform that the GameObject will scale to")] + [SerializeField] + protected TransformData _toTransform; + + [Tooltip("Target scale that the GameObject will scale to, if no To Transform is set")] + [SerializeField] + protected Vector3Data _toScale = new Vector3Data(Vector3.one); + + public override LTDescr ExecuteTween() + { + var sc = _toTransform.Value == null ? _toScale.Value : _toTransform.Value.localScale; + + if (IsInAddativeMode) + { + sc += _targetObject.Value.transform.localScale; + } + + if (IsInFromMode) + { + var cur = _targetObject.Value.transform.localScale; + _targetObject.Value.transform.localScale = sc; + sc = cur; + } + + return LeanTween.scale(_targetObject.Value, sc, _duration); + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/LeanTween/ScaleLean.cs.meta b/Assets/Fungus/Scripts/Commands/LeanTween/ScaleLean.cs.meta new file mode 100644 index 00000000..22a144b9 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/LeanTween/ScaleLean.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 30cbb61ab588b1a4093d2ef0254045b0 +timeCreated: 1499585056 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/LeanTween/StopTweensLean.cs b/Assets/Fungus/Scripts/Commands/LeanTween/StopTweensLean.cs new file mode 100644 index 00000000..19bf64d7 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/LeanTween/StopTweensLean.cs @@ -0,0 +1,47 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + + +namespace Fungus +{ + /// + /// + /// + [CommandInfo("LeanTween", + "StopTweens", + "Stops the LeanTweens on a target GameObject")] + [AddComponentMenu("")] + [ExecuteInEditMode] + public class StopTweensLean : Command + { + [Tooltip("Target game object stop LeanTweens on")] + [SerializeField] + protected GameObjectData _targetObject; + + public override void OnEnter() + { + if (_targetObject.Value != null) + { + LeanTween.cancel(_targetObject.Value); + } + + Continue(); + } + + public override string GetSummary() + { + if (_targetObject.Value == null) + { + return "Error: No target object selected"; + } + + return "Stop all LeanTweens on " + _targetObject.Value.name; + } + + public override Color GetButtonColor() + { + return new Color32(233, 163, 180, 255); + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/LeanTween/StopTweensLean.cs.meta b/Assets/Fungus/Scripts/Commands/LeanTween/StopTweensLean.cs.meta new file mode 100644 index 00000000..837cb4ca --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/LeanTween/StopTweensLean.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: d998218fa600bac43adbc431e9dd6c0c +timeCreated: 1499761355 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/LuaCondition.cs b/Assets/Fungus/Scripts/Commands/LuaCondition.cs new file mode 100644 index 00000000..7bd7d81d --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/LuaCondition.cs @@ -0,0 +1,126 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using Fungus; +using MoonSharp.Interpreter; + +namespace Fungus +{ + public class LuaCondition : Condition + { + [Tooltip("Lua Environment to use to execute this Lua script (null for global)")] + [SerializeField] protected LuaEnvironment luaEnvironment; + + [Tooltip("The lua comparison string to run; implicitly prepends 'return' onto this")] + [TextArea] + public string luaCompareString; + protected bool initialised; + protected string friendlyName = ""; + protected Closure luaFunction; + + protected override bool EvaluateCondition() + { + bool condition = false; + luaEnvironment.RunLuaFunction(luaFunction, false, (returnValue) => { + if( returnValue != null ) + { + condition = returnValue.Boolean; + } + else + { + Debug.LogWarning("No return value from " + friendlyName); + } + }); + return condition; + } + + protected override bool HasNeededProperties() + { + return !string.IsNullOrEmpty(luaCompareString); + } + + protected virtual void Start() + { + InitExecuteLua(); + } + + protected virtual string GetLuaString() + { + return "return not not (" + luaCompareString + ")"; + } + + /// + /// Initialises the Lua environment and compiles the Lua string for execution later on. + /// + protected virtual void InitExecuteLua() + { + if (initialised) + { + return; + } + + // Cache a descriptive name to use in Lua error messages + friendlyName = gameObject.name + "." + ParentBlock.BlockName + "." + this.GetType().ToString() + " #" + CommandIndex.ToString(); + + Flowchart flowchart = GetFlowchart(); + + // See if a Lua Environment has been assigned to this Flowchart + if (luaEnvironment == null) + { + luaEnvironment = flowchart.LuaEnv; + } + + // No Lua Environment specified so just use any available or create one. + if (luaEnvironment == null) + { + luaEnvironment = LuaEnvironment.GetLua(); + } + + string s = GetLuaString(); + luaFunction = luaEnvironment.LoadLuaFunction(s, friendlyName); + + // Add a binding to the parent flowchart + if (flowchart.LuaBindingName != "") + { + Table globals = luaEnvironment.Interpreter.Globals; + if (globals != null) + { + globals[flowchart.LuaBindingName] = flowchart; + } + } + + // 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; + } + + } + + #region Public members + + public override string GetSummary() + { + if (string.IsNullOrEmpty(luaCompareString)) + { + return "Error: no lua compare string provided"; + } + + return luaCompareString; + } + + + public override bool OpenBlock() + { + return true; + } + + public override Color GetButtonColor() + { + return new Color32(253, 253, 150, 255); + } + + #endregion + } +} diff --git a/Assets/Fungus/Scripts/Commands/LuaCondition.cs.meta b/Assets/Fungus/Scripts/Commands/LuaCondition.cs.meta new file mode 100644 index 00000000..5073dfed --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/LuaCondition.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 75ddfadd68d3d4713803a6b170cb0b51 +timeCreated: 1493078204 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/LuaElseIf.cs b/Assets/Fungus/Scripts/Commands/LuaElseIf.cs new file mode 100644 index 00000000..c7a647a5 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/LuaElseIf.cs @@ -0,0 +1,38 @@ +// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus). +// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE) + +using UnityEngine; + +namespace Fungus +{ + /// + /// Marks the start of a command block to be executed when the preceding If statement is False and the test expression is true. + /// + [CommandInfo("Flow", + "Lua Else If", + "Marks the start of a command block to be executed when the preceding If statement is False and the test expression is true.")] + [AddComponentMenu("")] + public class LuaElseIf : LuaCondition + { + protected override bool IsElseIf { get { return true; } } + + #region Public members + + public override bool OpenBlock() + { + return true; + } + + public override bool CloseBlock() + { + return true; + } + + public override Color GetButtonColor() + { + return new Color32(253, 253, 150, 255); + } + + #endregion + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/LuaElseIf.cs.meta b/Assets/Fungus/Scripts/Commands/LuaElseIf.cs.meta new file mode 100644 index 00000000..fae44b6f --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/LuaElseIf.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 9739de3269e5246b399e3a1cd41b94de +timeCreated: 1493078204 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/LuaIf.cs b/Assets/Fungus/Scripts/Commands/LuaIf.cs new file mode 100644 index 00000000..0a69e412 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/LuaIf.cs @@ -0,0 +1,26 @@ +// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus). +// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE) + +using UnityEngine; + +namespace Fungus +{ + /// + /// If the test expression is true, execute the following command block. + /// + [CommandInfo("Flow", + "Lua If", + "If the test expression is true, execute the following command block.")] + [AddComponentMenu("")] + public class LuaIf : LuaCondition + { + #region Public members + + public override Color GetButtonColor() + { + return new Color32(253, 253, 150, 255); + } + + #endregion + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/LuaIf.cs.meta b/Assets/Fungus/Scripts/Commands/LuaIf.cs.meta new file mode 100644 index 00000000..c67f5d4f --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/LuaIf.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: a8d396bcbf372485cad471c0bb64bb44 +timeCreated: 1493078204 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Math.meta b/Assets/Fungus/Scripts/Commands/Math.meta new file mode 100644 index 00000000..5bfbbb1d --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 09c52cfe3a6ff4747a9c207bec24ba11 +folderAsset: yes +timeCreated: 1503202781 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Math/Abs.cs b/Assets/Fungus/Scripts/Commands/Math/Abs.cs new file mode 100644 index 00000000..8b9bc27e --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Abs.cs @@ -0,0 +1,26 @@ +using UnityEngine; + +namespace Fungus +{ + /// + /// Command to execute and store the result of a Abs + /// + [CommandInfo("Math", + "Abs", + "Command to execute and store the result of a Abs")] + [AddComponentMenu("")] + public class Abs : BaseUnaryMathCommand + { + public override void OnEnter() + { + outValue.Value = Mathf.Abs(inValue.Value); + + Continue(); + } + + public override string GetSummary() + { + return "Abs"; + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/Abs.cs.meta b/Assets/Fungus/Scripts/Commands/Math/Abs.cs.meta new file mode 100644 index 00000000..50bde0dc --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Abs.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 6d11e978db36df445816ec2535d381ce +timeCreated: 1501211592 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Math/BaseUnaryMathCommand.cs b/Assets/Fungus/Scripts/Commands/Math/BaseUnaryMathCommand.cs new file mode 100644 index 00000000..253d834e --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/BaseUnaryMathCommand.cs @@ -0,0 +1,25 @@ +using UnityEngine; + +namespace Fungus +{ + /// + /// Base class for all simple Unary + /// + [AddComponentMenu("")] + public abstract class BaseUnaryMathCommand : Command + { + [Tooltip("Value to be passed in to the function.")] + [SerializeField] + protected FloatData inValue; + + [Tooltip("Where the result of the function is stored.")] + [SerializeField] + protected FloatData outValue; + + public override Color GetButtonColor() + { + return new Color32(235, 191, 217, 255); + } + + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/BaseUnaryMathCommand.cs.meta b/Assets/Fungus/Scripts/Commands/Math/BaseUnaryMathCommand.cs.meta new file mode 100644 index 00000000..1fc01c3c --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/BaseUnaryMathCommand.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 513a02811ba512d4ab54d157a15ae8c2 +timeCreated: 1501211592 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Math/Clamp.cs b/Assets/Fungus/Scripts/Commands/Math/Clamp.cs new file mode 100644 index 00000000..75ce2934 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Clamp.cs @@ -0,0 +1,66 @@ +using UnityEngine; + +namespace Fungus +{ + /// + /// Command to contain a value between a lower and upper bound, with optional wrapping modes + /// + [CommandInfo("Math", + "Clamp", + "Command to contain a value between a lower and upper bound, with optional wrapping modes")] + [AddComponentMenu("")] + public class Clamp : Command + { + public enum Mode + { + Clamp, + Repeat, + PingPong + } + + [SerializeField] + protected Mode mode = Mode.Clamp; + + //[Tooltip("LHS Value ")] + [SerializeField] + protected FloatData lower, upper, value; + + [Tooltip("Result put here, if using pingpong don't use the same var for value as outValue.")] + [SerializeField] + protected FloatData outValue; + + public override void OnEnter() + { + var l = lower.Value; + var u = upper.Value; + var v = value.Value; + + switch (mode) + { + case Mode.Clamp: + outValue.Value = Mathf.Clamp(value.Value, lower.Value, upper.Value); + break; + case Mode.Repeat: + outValue.Value = (Mathf.Repeat(v - l, u - l)) + l; + break; + case Mode.PingPong: + outValue.Value = (Mathf.PingPong(v - l, u - l)) + l; + break; + default: + break; + } + + Continue(); + } + + public override string GetSummary() + { + return Mode.Clamp.ToString() + (mode != Mode.Clamp ? " & " + mode.ToString() : ""); + } + + public override Color GetButtonColor() + { + return new Color32(235, 191, 217, 255); + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/Clamp.cs.meta b/Assets/Fungus/Scripts/Commands/Math/Clamp.cs.meta new file mode 100644 index 00000000..9e93100f --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Clamp.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 2929f1e90a24b6446a70d27316cff20a +timeCreated: 1501225403 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Math/Curve.cs b/Assets/Fungus/Scripts/Commands/Math/Curve.cs new file mode 100644 index 00000000..69c8d76a --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Curve.cs @@ -0,0 +1,29 @@ +using UnityEngine; + +namespace Fungus +{ + /// + /// Pass a value through an AnimationCurve + /// + [CommandInfo("Math", + "Curve", + "Pass a value through an AnimationCurve")] + [AddComponentMenu("")] + public class Curve : BaseUnaryMathCommand + { + [SerializeField] + protected AnimationCurve curve = AnimationCurve.Linear(0, 0, 1, 1); + + public override void OnEnter() + { + outValue.Value = curve.Evaluate(inValue.Value); + + Continue(); + } + + public override string GetSummary() + { + return "Curve"; + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/Curve.cs.meta b/Assets/Fungus/Scripts/Commands/Math/Curve.cs.meta new file mode 100644 index 00000000..b67fc8fc --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Curve.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: c03f48fc50d3747478ad85653a21a5f5 +timeCreated: 1501226831 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Math/Exp.cs b/Assets/Fungus/Scripts/Commands/Math/Exp.cs new file mode 100644 index 00000000..6e5c4723 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Exp.cs @@ -0,0 +1,26 @@ +using UnityEngine; + +namespace Fungus +{ + /// + /// Command to execute and store the result of a Exp + /// + [CommandInfo("Math", + "Exp", + "Command to execute and store the result of a Exp")] + [AddComponentMenu("")] + public class Exp : BaseUnaryMathCommand + { + public override void OnEnter() + { + outValue.Value = Mathf.Exp(inValue.Value); + + Continue(); + } + + public override string GetSummary() + { + return "Exp"; + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/Exp.cs.meta b/Assets/Fungus/Scripts/Commands/Math/Exp.cs.meta new file mode 100644 index 00000000..3e609ebf --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Exp.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: f28df8ed8a80fa345b3b5e3dcacdea65 +timeCreated: 1501211938 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Math/Inv.cs b/Assets/Fungus/Scripts/Commands/Math/Inv.cs new file mode 100644 index 00000000..fcd6a5d3 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Inv.cs @@ -0,0 +1,28 @@ +using UnityEngine; + +namespace Fungus +{ + /// + /// Multiplicative Inverse of a float (1/f) + /// + [CommandInfo("Math", + "Inverse", + "Multiplicative Inverse of a float (1/f)")] + [AddComponentMenu("")] + public class Inv : BaseUnaryMathCommand + { + public override void OnEnter() + { + var v = inValue.Value; + + outValue.Value = v != 0 ? (1.0f / inValue.Value) : 0.0f; + + Continue(); + } + + public override string GetSummary() + { + return "Inverse 1/f"; + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/Inv.cs.meta b/Assets/Fungus/Scripts/Commands/Math/Inv.cs.meta new file mode 100644 index 00000000..fc54c386 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Inv.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 36d3a877e83b1d1478f1ac099414d17a +timeCreated: 1501213679 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Math/InvLerp.cs b/Assets/Fungus/Scripts/Commands/Math/InvLerp.cs new file mode 100644 index 00000000..a593dc0d --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/InvLerp.cs @@ -0,0 +1,46 @@ +using UnityEngine; + +namespace Fungus +{ + /// + /// Calculates the inverse lerp, the percentage a value is between two others. + /// + [CommandInfo("Math", + "InvLerp", + "Calculates the inverse lerp, the percentage a value is between two others.")] + [AddComponentMenu("")] + public class InvLerp : Command + { + [Tooltip("Clamp percentage to 0-1?")] + [SerializeField] + protected bool clampResult = true; + + //[Tooltip("LHS Value ")] + [SerializeField] + protected FloatData a, b, value; + + //[Tooltip("Where the result of the function is stored.")] + [SerializeField] + protected FloatData outValue; + + public override void OnEnter() + { + if (clampResult) + outValue.Value = Mathf.InverseLerp(a.Value, b.Value, value.Value); + else + outValue.Value = (value.Value - a.Value) / (b.Value - a.Value); + + Continue(); + } + + public override string GetSummary() + { + return "InvLerp [" + a.Value.ToString() + "-" + b.Value.ToString() + "]"; + } + + public override Color GetButtonColor() + { + return new Color32(235, 191, 217, 255); + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/InvLerp.cs.meta b/Assets/Fungus/Scripts/Commands/Math/InvLerp.cs.meta new file mode 100644 index 00000000..d6d1bc84 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/InvLerp.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 80c88869f66a81f4b95e843c36724e65 +timeCreated: 1501213063 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Math/Lerp.cs b/Assets/Fungus/Scripts/Commands/Math/Lerp.cs new file mode 100644 index 00000000..5caedf46 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Lerp.cs @@ -0,0 +1,63 @@ +using UnityEngine; + +namespace Fungus +{ + /// + /// Linearly Interpolate from A to B + /// + [CommandInfo("Math", + "Lerp", + "Linearly Interpolate from A to B")] + [AddComponentMenu("")] + public class Lerp : Command + { + public enum Mode + { + Lerp, + LerpUnclamped, + LerpAngle + } + + [SerializeField] + protected Mode mode = Mode.Lerp; + + //[Tooltip("LHS Value ")] + [SerializeField] + protected FloatData a = new FloatData(0), b = new FloatData(1), percentage; + + //[Tooltip("Where the result of the function is stored.")] + [SerializeField] + protected FloatData outValue; + + public override void OnEnter() + { + switch (mode) + { + case Mode.Lerp: + outValue.Value = Mathf.Lerp(a.Value, b.Value, percentage.Value); + break; + case Mode.LerpUnclamped: + outValue.Value = Mathf.LerpUnclamped(a.Value, b.Value, percentage.Value); + break; + case Mode.LerpAngle: + outValue.Value = Mathf.LerpAngle(a.Value, b.Value, percentage.Value); + break; + default: + break; + } + + Continue(); + } + + public override string GetSummary() + { + return mode.ToString() + " [" + a.Value.ToString() + "-" + b.Value.ToString() + "]"; + } + + public override Color GetButtonColor() + { + return new Color32(235, 191, 217, 255); + } + + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/Lerp.cs.meta b/Assets/Fungus/Scripts/Commands/Math/Lerp.cs.meta new file mode 100644 index 00000000..da0b39de --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Lerp.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: b44d8d3a71d3e7b45a89437c8f84e687 +timeCreated: 1501212773 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Math/Log.cs b/Assets/Fungus/Scripts/Commands/Math/Log.cs new file mode 100644 index 00000000..2c7da4bb --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Log.cs @@ -0,0 +1,56 @@ +using UnityEngine; + +namespace Fungus +{ + /// + /// Command to execute and store the result of a Log + /// + [CommandInfo("Math", + "Log", + "Command to execute and store the result of a Log")] + [AddComponentMenu("")] + public class Log : BaseUnaryMathCommand + { + public enum Mode + { + Base10, + Natural + } + + [Tooltip("Which log to use, natural or base 10")] + [SerializeField] + protected Mode mode = Mode.Natural; + + public override void OnEnter() + { + switch (mode) + { + case Mode.Base10: + outValue.Value = Mathf.Log10(inValue.Value); + break; + case Mode.Natural: + outValue.Value = Mathf.Log(inValue.Value); + break; + default: + break; + } + + Continue(); + } + + public override string GetSummary() + { + switch (mode) + { + case Mode.Base10: + return "Log Base 10"; + case Mode.Natural: + return "Natural Log"; + default: + break; + } + + return "Log"; + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/Log.cs.meta b/Assets/Fungus/Scripts/Commands/Math/Log.cs.meta new file mode 100644 index 00000000..c8d8d449 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Log.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 47ecda391b679d8449893d4466f41b13 +timeCreated: 1501211938 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Math/Map.cs b/Assets/Fungus/Scripts/Commands/Math/Map.cs new file mode 100644 index 00000000..61f7fb23 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Map.cs @@ -0,0 +1,48 @@ +using UnityEngine; + +namespace Fungus +{ + /// + /// Map a value that exists in 1 range of numbers to another. + /// + [CommandInfo("Math", + "Map", + "Map a value that exists in 1 range of numbers to another.")] + [AddComponentMenu("")] + public class Map : Command + { + //[Tooltip("LHS Value ")] + [SerializeField] + protected FloatData initialRangeLower = new FloatData(0), initialRangeUpper = new FloatData(1), value; + + [SerializeField] + protected FloatData newRangeLower = new FloatData(0), newRangeUpper = new FloatData(1); + + [SerializeField] + protected FloatData outValue; + + public override void OnEnter() + { + var p = value.Value - initialRangeLower.Value; + p /= initialRangeUpper.Value - initialRangeLower.Value; + + var res = p * (newRangeUpper.Value - newRangeLower.Value); + res += newRangeLower.Value; + + outValue.Value = res; + + Continue(); + } + + public override string GetSummary() + { + return "Map [" + initialRangeLower.Value.ToString() + "-" + initialRangeUpper.Value.ToString() + "] to [" + + newRangeLower.Value.ToString() + "-" + newRangeUpper.Value.ToString() + "]"; + } + + public override Color GetButtonColor() + { + return new Color32(235, 191, 217, 255); + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/Map.cs.meta b/Assets/Fungus/Scripts/Commands/Math/Map.cs.meta new file mode 100644 index 00000000..d38c5070 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Map.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 78d80bb5401d8044eb9eee0d4eb0b645 +timeCreated: 1501226122 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Math/MinMax.cs b/Assets/Fungus/Scripts/Commands/Math/MinMax.cs new file mode 100644 index 00000000..9efeb0a0 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/MinMax.cs @@ -0,0 +1,61 @@ +using UnityEngine; + +namespace Fungus +{ + /// + /// Command to store the min or max of 2 values + /// + [CommandInfo("Math", + "MinMax", + "Command to store the min or max of 2 values")] + [AddComponentMenu("")] + public class MinMax : Command + { + public enum Function + { + Min, + Max + } + + [Tooltip("Min Or Max")] + [SerializeField] + protected Function function = Function.Min; + + //[Tooltip("LHS Value ")] + [SerializeField] + protected FloatData inLHSValue, inRHSValue; + + //[Tooltip("Where the result of the function is stored.")] + [SerializeField] + protected FloatData outValue; + + public override void OnEnter() + { + switch (function) + { + case Function.Min: + outValue.Value = Mathf.Min(inLHSValue.Value, inRHSValue.Value); + break; + case Function.Max: + outValue.Value = Mathf.Max(inLHSValue.Value, inRHSValue.Value); + break; + default: + break; + } + + + Continue(); + } + + public override string GetSummary() + { + return function.ToString(); + } + + public override Color GetButtonColor() + { + return new Color32(235, 191, 217, 255); + } + + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/MinMax.cs.meta b/Assets/Fungus/Scripts/Commands/Math/MinMax.cs.meta new file mode 100644 index 00000000..f356cd42 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/MinMax.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 514ec18f5085cba48bbe6701e4697eb0 +timeCreated: 1501212523 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Math/Neg.cs b/Assets/Fungus/Scripts/Commands/Math/Neg.cs new file mode 100644 index 00000000..883ef7de --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Neg.cs @@ -0,0 +1,26 @@ +using UnityEngine; + +namespace Fungus +{ + /// + /// Negate a float + /// + [CommandInfo("Math", + "Negate", + "Negate a float")] + [AddComponentMenu("")] + public class Neg : BaseUnaryMathCommand + { + public override void OnEnter() + { + outValue.Value = -(inValue.Value); + + Continue(); + } + + public override string GetSummary() + { + return "Negate"; + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/Neg.cs.meta b/Assets/Fungus/Scripts/Commands/Math/Neg.cs.meta new file mode 100644 index 00000000..c23c52d6 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Neg.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: ff146879925212d4988aa4318efcbbd5 +timeCreated: 1501213679 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Math/Pow.cs b/Assets/Fungus/Scripts/Commands/Math/Pow.cs new file mode 100644 index 00000000..e20db290 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Pow.cs @@ -0,0 +1,39 @@ +using UnityEngine; + +namespace Fungus +{ + /// + /// Raise a value to the power of another + /// + [CommandInfo("Math", + "Pow", + "Raise a value to the power of another.")] + [AddComponentMenu("")] + public class Pow : Command + { + [SerializeField] + protected FloatData baseValue, exponentValue; + + [Tooltip("Where the result of the function is stored.")] + [SerializeField] + protected FloatData outValue; + + public override void OnEnter() + { + outValue.Value = Mathf.Pow(baseValue.Value, exponentValue.Value); + + Continue(); + } + + public override string GetSummary() + { + return "Pow"; + } + + public override Color GetButtonColor() + { + return new Color32(235, 191, 217, 255); + } + + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/Pow.cs.meta b/Assets/Fungus/Scripts/Commands/Math/Pow.cs.meta new file mode 100644 index 00000000..1fd5077c --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Pow.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 23b09e2ab627fec4cb0200f7252dbc90 +timeCreated: 1501497818 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Math/Round.cs b/Assets/Fungus/Scripts/Commands/Math/Round.cs new file mode 100644 index 00000000..418893f7 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Round.cs @@ -0,0 +1,50 @@ +using UnityEngine; + +namespace Fungus +{ + /// + /// Command to execute and store the result of a Round + /// + [CommandInfo("Math", + "Round", + "Command to execute and store the result of a Round")] + [AddComponentMenu("")] + public class Round : BaseUnaryMathCommand + { + public enum Mode + { + Round, + Floor, + Ceil + } + + [Tooltip("Mode; Round (closest), floor(smaller) or ceil(bigger).")] + [SerializeField] + protected Mode function = Mode.Round; + + public override void OnEnter() + { + switch (function) + { + case Mode.Round: + outValue.Value = Mathf.Round(inValue.Value); + break; + case Mode.Floor: + outValue.Value = Mathf.Floor(inValue.Value); + break; + case Mode.Ceil: + outValue.Value = Mathf.Ceil(inValue.Value); + break; + default: + break; + } + + Continue(); + } + + public override string GetSummary() + { + return function.ToString(); + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/Round.cs.meta b/Assets/Fungus/Scripts/Commands/Math/Round.cs.meta new file mode 100644 index 00000000..3dab99b2 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Round.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: b9c834185b491334d8e41ca4fc49a56e +timeCreated: 1501212403 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Math/Sign.cs b/Assets/Fungus/Scripts/Commands/Math/Sign.cs new file mode 100644 index 00000000..d3b3ebb9 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Sign.cs @@ -0,0 +1,26 @@ +using UnityEngine; + +namespace Fungus +{ + /// + /// Command to execute and store the result of a Sign + /// + [CommandInfo("Math", + "Sign", + "Command to execute and store the result of a Sign")] + [AddComponentMenu("")] + public class Sign : BaseUnaryMathCommand + { + public override void OnEnter() + { + outValue.Value = Mathf.Sign(inValue.Value); + + Continue(); + } + + public override string GetSummary() + { + return "Sign"; + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/Sign.cs.meta b/Assets/Fungus/Scripts/Commands/Math/Sign.cs.meta new file mode 100644 index 00000000..8f7a7a9f --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Sign.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 6a03542258f6b654b8a6d64938803f71 +timeCreated: 1501211938 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Math/Sqrt.cs b/Assets/Fungus/Scripts/Commands/Math/Sqrt.cs new file mode 100644 index 00000000..57500efe --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Sqrt.cs @@ -0,0 +1,26 @@ +using UnityEngine; + +namespace Fungus +{ + /// + /// Command to execute and store the result of a Sqrt + /// + [CommandInfo("Math", + "Sqrt", + "Command to execute and store the result of a Sqrt")] + [AddComponentMenu("")] + public class Sqrt : BaseUnaryMathCommand + { + public override void OnEnter() + { + outValue.Value = Mathf.Sqrt(inValue.Value); + + Continue(); + } + + public override string GetSummary() + { + return "Sqrt"; + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/Sqrt.cs.meta b/Assets/Fungus/Scripts/Commands/Math/Sqrt.cs.meta new file mode 100644 index 00000000..3242b4de --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Sqrt.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 6e52daa13ab8fe7499a7774ebc194fc5 +timeCreated: 1501211938 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Math/ToInt.cs b/Assets/Fungus/Scripts/Commands/Math/ToInt.cs new file mode 100644 index 00000000..e4a15b24 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/ToInt.cs @@ -0,0 +1,65 @@ +using UnityEngine; + +namespace Fungus +{ + /// + /// Command to execute and store the result of a float to int conversion + /// + [CommandInfo("Math", + "ToInt", + "Command to execute and store the result of a float to int conversion")] + [AddComponentMenu("")] + public class ToInt : Command + { + public enum Mode + { + RoundToInt, + FloorToInt, + CeilToInt, + } + + + [Tooltip("To integer mode; round, floor or ceil.")] + [SerializeField] + protected Mode function = Mode.RoundToInt; + + [Tooltip("Value to be passed in to the function.")] + [SerializeField] + protected FloatData inValue; + + [Tooltip("Where the result of the function is stored.")] + [SerializeField] + protected IntegerData outValue; + + public override void OnEnter() + { + switch (function) + { + case Mode.RoundToInt: + outValue.Value = Mathf.RoundToInt(inValue.Value); + break; + case Mode.FloorToInt: + outValue.Value = Mathf.FloorToInt(inValue.Value); + break; + case Mode.CeilToInt: + outValue.Value = Mathf.CeilToInt(inValue.Value); + break; + default: + break; + } + + Continue(); + } + + public override string GetSummary() + { + return function.ToString(); + } + + public override Color GetButtonColor() + { + return new Color32(235, 191, 217, 255); + } + + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/ToInt.cs.meta b/Assets/Fungus/Scripts/Commands/Math/ToInt.cs.meta new file mode 100644 index 00000000..334b3535 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/ToInt.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 209dba259f0c4134daa0ec3b64c78062 +timeCreated: 1501210911 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Math/Trig.cs b/Assets/Fungus/Scripts/Commands/Math/Trig.cs new file mode 100644 index 00000000..998cf902 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Trig.cs @@ -0,0 +1,77 @@ +using UnityEngine; + +namespace Fungus +{ + /// + /// Command to execute and store the result of basic trigonometry + /// + [CommandInfo("Math", + "Trig", + "Command to execute and store the result of basic trigonometry")] + [AddComponentMenu("")] + public class Trig : BaseUnaryMathCommand + { + public enum Function + { + Rad2Deg, + Deg2Rad, + ACos, + ASin, + ATan, + Cos, + Sin, + Tan + } + + + [Tooltip("Trigonometric function to run.")] + [SerializeField] + protected Function function = Function.Sin; + + public override void OnEnter() + { + switch (function) + { + case Function.Rad2Deg: + outValue.Value = inValue.Value * Mathf.Rad2Deg; + break; + case Function.Deg2Rad: + outValue.Value = inValue.Value * Mathf.Deg2Rad; + break; + case Function.ACos: + outValue.Value = Mathf.Acos(inValue.Value); + break; + case Function.ASin: + outValue.Value = Mathf.Asin(inValue.Value); + break; + case Function.ATan: + outValue.Value = Mathf.Atan(inValue.Value); + break; + case Function.Cos: + outValue.Value = Mathf.Cos(inValue.Value); + break; + case Function.Sin: + outValue.Value = Mathf.Sin(inValue.Value); + break; + case Function.Tan: + outValue.Value = Mathf.Tan(inValue.Value); + break; + default: + break; + } + + Continue(); + } + + public override string GetSummary() + { + return function.ToString(); + } + + public override Color GetButtonColor() + { + return new Color32(235, 191, 217, 255); + } + + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Math/Trig.cs.meta b/Assets/Fungus/Scripts/Commands/Math/Trig.cs.meta new file mode 100644 index 00000000..2d6aec0f --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Math/Trig.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: ee9ab1525ab1b794489f2517aab1d5e2 +timeCreated: 1501148787 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Menu.cs b/Assets/Fungus/Scripts/Commands/Menu.cs index 458fd195..a64578dc 100644 --- a/Assets/Fungus/Scripts/Commands/Menu.cs +++ b/Assets/Fungus/Scripts/Commands/Menu.cs @@ -35,6 +35,9 @@ namespace Fungus [Tooltip("A custom Menu Dialog to use to display this menu. All subsequent Menu commands will use this dialog.")] [SerializeField] protected MenuDialog setMenuDialog; + [Tooltip("If true, this option will be passed to the Menu Dialogue but marked as hidden, this can be used to hide options while maintaining a Menu Shuffle.")] + [SerializeField] protected BooleanData hideThisOption = new BooleanData(false); + #region Public members public MenuDialog SetMenuDialog { get { return setMenuDialog; } set { setMenuDialog = value; } } @@ -47,11 +50,9 @@ namespace Fungus MenuDialog.ActiveMenuDialog = setMenuDialog; } - bool hideOption = (hideIfVisited && targetBlock != null && targetBlock.GetExecutionCount() > 0); + bool hideOption = (hideIfVisited && targetBlock != null && targetBlock.GetExecutionCount() > 0) || hideThisOption.Value; - if (!hideOption) - { - var menuDialog = MenuDialog.GetMenuDialog(); + var menuDialog = MenuDialog.GetMenuDialog(); if (menuDialog != null) { menuDialog.SetActive(true); @@ -59,10 +60,9 @@ namespace Fungus var flowchart = GetFlowchart(); string displayText = flowchart.SubstituteVariables(text); - menuDialog.AddOption(displayText, interactable, targetBlock); + menuDialog.AddOption(displayText, interactable, hideOption, targetBlock); } - } - + Continue(); } diff --git a/Assets/Fungus/Scripts/Commands/MenuShuffle.cs b/Assets/Fungus/Scripts/Commands/MenuShuffle.cs new file mode 100644 index 00000000..fcaf0082 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/MenuShuffle.cs @@ -0,0 +1,59 @@ +// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus). +// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE) + +using UnityEngine; +using UnityEngine.Serialization; +using System.Collections.Generic; + +namespace Fungus +{ + /// + /// Shuffle the order of the items in a Fungus Menu + /// + [CommandInfo("Narrative", + "Menu Shuffle", + "Shuffle the order of the items in a Fungus Menu")] + [AddComponentMenu("")] + [ExecuteInEditMode] + public class MenuShuffle : Command + { + public enum Mode + { + Every, + Once + } + [SerializeField] + [Tooltip("Determines if the order is shuffled everytime this command is it (Every) or if it is consistent when returned to but random (Once)")] + protected Mode shuffleMode = Mode.Once; + + private int seed = -1; + + public override void OnEnter() + { + var menuDialog = MenuDialog.GetMenuDialog(); + + //if we shuffle every time or we haven't shuffled yet + if(shuffleMode == Mode.Every || seed == -1) + { + seed = Random.Range(0,1000000); + } + + if (menuDialog != null) + { + menuDialog.Shuffle(new System.Random(seed)); + } + + Continue(); + } + + public override string GetSummary() + { + return shuffleMode.ToString(); + } + + public override Color GetButtonColor() + { + return new Color32(184, 210, 235, 255); + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/MenuShuffle.cs.meta b/Assets/Fungus/Scripts/Commands/MenuShuffle.cs.meta new file mode 100644 index 00000000..7e4ba734 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/MenuShuffle.cs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4d88125c88dab4a44851835e94ff4d90 +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: diff --git a/Assets/Fungus/Scripts/Commands/OpenURL.cs b/Assets/Fungus/Scripts/Commands/OpenURL.cs index 21e440e6..a13714fc 100644 --- a/Assets/Fungus/Scripts/Commands/OpenURL.cs +++ b/Assets/Fungus/Scripts/Commands/OpenURL.cs @@ -12,7 +12,7 @@ namespace Fungus [CommandInfo("Scripting", "Open URL", "Opens the specified URL in the browser.")] - public class LinkToWebsite : Command + public class OpenURL : Command { [Tooltip("URL to open in the browser")] [SerializeField] protected StringData url = new StringData(); diff --git a/Assets/Fungus/Scripts/Commands/Property.meta b/Assets/Fungus/Scripts/Commands/Property.meta new file mode 100644 index 00000000..d2aa6cd5 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Property.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 103d5735e5e7b4a409ae0bb18c246f22 +folderAsset: yes +timeCreated: 1513473561 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Rigidbody2D.meta b/Assets/Fungus/Scripts/Commands/Rigidbody2D.meta new file mode 100644 index 00000000..8f473125 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Rigidbody2D.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 168ad11319df4784eaaf28cf8e564365 +folderAsset: yes +timeCreated: 1503731365 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Rigidbody2D/AddForce2D.cs b/Assets/Fungus/Scripts/Commands/Rigidbody2D/AddForce2D.cs new file mode 100644 index 00000000..bedb42a4 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Rigidbody2D/AddForce2D.cs @@ -0,0 +1,85 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Fungus +{ + // + /// Add force to a Rigidbody2D + /// + [CommandInfo("Rigidbody2D", + "AddForce2D", + "Add force to a Rigidbody2D")] + [AddComponentMenu("")] + public class AddForce2D : Command + { + [SerializeField] + protected Rigidbody2DData rb; + + [SerializeField] + protected ForceMode2D forceMode = ForceMode2D.Force; + + public enum ForceFunction + { + AddForce, + AddForceAtPosition, + AddRelativeForce + } + + [SerializeField] + protected ForceFunction forceFunction = ForceFunction.AddForce; + + [Tooltip("Vector of force to be added")] + [SerializeField] + protected Vector2Data force; + + [Tooltip("Scale factor to be applied to force as it is used.")] + [SerializeField] + protected FloatData forceScaleFactor = new FloatData(1); + + [Tooltip("World position the force is being applied from. Used only in AddForceAtPosition")] + [SerializeField] + protected Vector2Data atPosition; + + public override void OnEnter() + { + switch (forceFunction) + { + case ForceFunction.AddForce: + rb.Value.AddForce(force.Value * forceScaleFactor.Value, forceMode); + break; + case ForceFunction.AddForceAtPosition: + rb.Value.AddForceAtPosition(force.Value * forceScaleFactor.Value, atPosition.Value, forceMode); + break; + case ForceFunction.AddRelativeForce: + rb.Value.AddRelativeForce(force.Value * forceScaleFactor.Value, forceMode); + break; + default: + break; + } + + + Continue(); + } + + public override string GetSummary() + { + return forceMode.ToString() + ": " + force.ToString(); + } + + public override Color GetButtonColor() + { + return new Color32(235, 191, 217, 255); + } + + public override bool HasReference(Variable variable) + { + if (rb.rigidbody2DRef == variable || force.vector2Ref == variable || forceScaleFactor.floatRef == variable || + atPosition.vector2Ref == variable) + return true; + + return false; + } + + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Rigidbody2D/AddForce2D.cs.meta b/Assets/Fungus/Scripts/Commands/Rigidbody2D/AddForce2D.cs.meta new file mode 100644 index 00000000..f0b09f1e --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Rigidbody2D/AddForce2D.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 59927941e3d79be4dac4408058904465 +timeCreated: 1503094848 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Rigidbody2D/AddTorque2D.cs b/Assets/Fungus/Scripts/Commands/Rigidbody2D/AddTorque2D.cs new file mode 100644 index 00000000..59c2b3a3 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Rigidbody2D/AddTorque2D.cs @@ -0,0 +1,56 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Fungus +{ + // + /// Add Torque to a Rigidbody2D + /// + [CommandInfo("Rigidbody2D", + "AddTorque2D", + "Add Torque to a Rigidbody2D")] + [AddComponentMenu("")] + public class AddTorque2D : Command + { + [SerializeField] + protected Rigidbody2DData rb; + + [SerializeField] + protected ForceMode2D forceMode = ForceMode2D.Force; + + [Tooltip("Amount of torque to be added")] + [SerializeField] + protected FloatData force; + + public override void OnEnter() + { + rb.Value.AddTorque(force.Value, forceMode); + + Continue(); + } + + public override string GetSummary() + { + if (rb.Value == null) + { + return "Error: rb not set"; + } + + return forceMode.ToString() + ": " + force.Value.ToString() + (force.floatRef != null ? " (" + force.floatRef.Key + ")" : ""); + } + + public override Color GetButtonColor() + { + return new Color32(235, 191, 217, 255); + } + + public override bool HasReference(Variable variable) + { + if (rb.rigidbody2DRef == variable || force.floatRef == variable) + return true; + + return false; + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Rigidbody2D/AddTorque2D.cs.meta b/Assets/Fungus/Scripts/Commands/Rigidbody2D/AddTorque2D.cs.meta new file mode 100644 index 00000000..07ab3da3 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Rigidbody2D/AddTorque2D.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 42fb61d4cee69b244bcf4fcc8e4ae28b +timeCreated: 1503744011 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Rigidbody2D/StopMotionRigidBody2D.cs b/Assets/Fungus/Scripts/Commands/Rigidbody2D/StopMotionRigidBody2D.cs new file mode 100644 index 00000000..ef4c0e31 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Rigidbody2D/StopMotionRigidBody2D.cs @@ -0,0 +1,69 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Fungus +{ + // + /// Stop velocity and angular velocity on a Rigidbody2D + /// + [CommandInfo("Rigidbody2D", + "StopMotion2D", + "Stop velocity and angular velocity on a Rigidbody2D")] + [AddComponentMenu("")] + public class StopMotionRigidBody2D : Command + { + [SerializeField] + protected Rigidbody2DData rb; + + public enum Motion + { + Velocity, + AngularVelocity, + AngularAndLinearVelocity + } + + [SerializeField] + protected Motion motionToStop = Motion.AngularAndLinearVelocity; + + public override void OnEnter() + { + switch (motionToStop) + { + case Motion.Velocity: + rb.Value.velocity = Vector2.zero; + break; + case Motion.AngularVelocity: + rb.Value.angularVelocity = 0; + break; + case Motion.AngularAndLinearVelocity: + rb.Value.angularVelocity = 0; + rb.Value.velocity = Vector2.zero; + break; + default: + break; + } + + Continue(); + } + + public override string GetSummary() + { + return motionToStop.ToString(); + } + + public override Color GetButtonColor() + { + return new Color32(235, 191, 217, 255); + } + + public override bool HasReference(Variable variable) + { + if (rb.rigidbody2DRef == variable) + return true; + + return false; + } + + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Rigidbody2D/StopMotionRigidBody2D.cs.meta b/Assets/Fungus/Scripts/Commands/Rigidbody2D/StopMotionRigidBody2D.cs.meta new file mode 100644 index 00000000..07fd7833 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Rigidbody2D/StopMotionRigidBody2D.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: bd2e830ee16360d418acee50d83c9c13 +timeCreated: 1504225685 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Say.cs b/Assets/Fungus/Scripts/Commands/Say.cs index 44a2e583..b86af519 100644 --- a/Assets/Fungus/Scripts/Commands/Say.cs +++ b/Assets/Fungus/Scripts/Commands/Say.cs @@ -48,6 +48,11 @@ namespace Fungus [Tooltip("Stop playing voiceover when text finishes writing.")] [SerializeField] protected bool stopVoiceover = true; + [Tooltip("Wait for the Voice Over to complete before continuing")] + [SerializeField] protected bool waitForVO = false; + + //add wait for vo that overrides stopvo + [Tooltip("Sets the active Say dialog with a reference to a Say Dialog object in the scene. All story text will now display using this Say Dialog.")] [SerializeField] protected SayDialog setSayDialog; @@ -120,7 +125,7 @@ namespace Fungus string subbedText = flowchart.SubstituteVariables(displayText); - sayDialog.Say(subbedText, !extendPrevious, waitForClick, fadeWhenDone, stopVoiceover, voiceOverClip, delegate { + sayDialog.Say(subbedText, !extendPrevious, waitForClick, fadeWhenDone, stopVoiceover, waitForVO, voiceOverClip, delegate { Continue(); }); } diff --git a/Assets/Fungus/Scripts/Commands/Scene.meta b/Assets/Fungus/Scripts/Commands/Scene.meta new file mode 100644 index 00000000..f19e680f --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Scene.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 3c625aa42f45f484cb2a4f4bef7adede +folderAsset: yes +timeCreated: 1501237083 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Scene/ReloadScene.cs b/Assets/Fungus/Scripts/Commands/Scene/ReloadScene.cs new file mode 100644 index 00000000..76161593 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Scene/ReloadScene.cs @@ -0,0 +1,35 @@ +using UnityEngine; + +namespace Fungus +{ + /// + /// Reload the current scene + /// + [CommandInfo("Scene", + "Reload", + "Reload the current scene")] + [AddComponentMenu("")] + public class ReloadScene : Command + { + [Tooltip("Image to display while loading the scene")] + [SerializeField] + protected Texture2D loadingImage; + + public override void OnEnter() + { + SceneLoader.LoadScene(UnityEngine.SceneManagement.SceneManager.GetActiveScene().name, loadingImage); + + Continue(); + } + + public override string GetSummary() + { + return ""; + } + + public override Color GetButtonColor() + { + return new Color32(235, 191, 217, 255); + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Scene/ReloadScene.cs.meta b/Assets/Fungus/Scripts/Commands/Scene/ReloadScene.cs.meta new file mode 100644 index 00000000..c1c1fc63 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Scene/ReloadScene.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 9c784b19efbe8424fa879e0d6d883281 +timeCreated: 1501237128 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/SetInteractable.cs b/Assets/Fungus/Scripts/Commands/SetInteractable.cs index 66d77eb1..e258883c 100644 --- a/Assets/Fungus/Scripts/Commands/SetInteractable.cs +++ b/Assets/Fungus/Scripts/Commands/SetInteractable.cs @@ -12,7 +12,7 @@ namespace Fungus /// [CommandInfo("UI", "Set Interactable", - "Set the interactable sate of selectable objects.")] + "Set the interactable state of selectable objects.")] public class SetInteractable : Command { [Tooltip("List of objects to be affected by the command")] diff --git a/Assets/Fungus/Scripts/Commands/SetVariable.cs b/Assets/Fungus/Scripts/Commands/SetVariable.cs index bf61f99c..4b3d9b8b 100644 --- a/Assets/Fungus/Scripts/Commands/SetVariable.cs +++ b/Assets/Fungus/Scripts/Commands/SetVariable.cs @@ -2,28 +2,10 @@ // It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE) using UnityEngine; +using System.Collections.Generic; namespace Fungus { - /// - /// Mathematical operations that can be performed on variables. - /// - public enum SetOperator - { - /// = operator. - Assign, - /// =! operator. - Negate, - /// += operator. - Add, - /// -= operator. - Subtract, - /// *= operator. - Multiply, - /// /= operator. - Divide - } - /// /// Sets a Boolean, Integer, Float or String variable to a new value using a simple arithmetic operation. The value can be a constant or reference another variable of the same type. /// @@ -37,7 +19,8 @@ namespace Fungus [VariableProperty(typeof(BooleanVariable), typeof(IntegerVariable), typeof(FloatVariable), - typeof(StringVariable))] + typeof(StringVariable), + typeof(GameObjectVariable))] [SerializeField] protected Variable variable; [Tooltip("The type of math operation to be performed")] @@ -55,6 +38,9 @@ namespace Fungus [Tooltip("String value to set with")] [SerializeField] protected StringDataMulti stringData; + [Tooltip("GameObject value to set with")] + [SerializeField] protected GameObjectData gameObjectData; + protected virtual void DoSetOperation() { if (variable == null) @@ -64,90 +50,42 @@ namespace Fungus if (variable.GetType() == typeof(BooleanVariable)) { - BooleanVariable lhs = (variable as BooleanVariable); - bool rhs = booleanData.Value; - - switch (setOperator) - { - default: - case SetOperator.Assign: - lhs.Value = rhs; - break; - case SetOperator.Negate: - lhs.Value = !rhs; - break; - } + BooleanVariable booleanVariable = (variable as BooleanVariable); + booleanVariable.Apply(setOperator, booleanData.Value); } else if (variable.GetType() == typeof(IntegerVariable)) { - IntegerVariable lhs = (variable as IntegerVariable); - int rhs = integerData.Value; - - switch (setOperator) - { - default: - case SetOperator.Assign: - lhs.Value = rhs; - break; - case SetOperator.Add: - lhs.Value += rhs; - break; - case SetOperator.Subtract: - lhs.Value -= rhs; - break; - case SetOperator.Multiply: - lhs.Value *= rhs; - break; - case SetOperator.Divide: - lhs.Value /= rhs; - break; - } + IntegerVariable integerVariable = (variable as IntegerVariable); + integerVariable.Apply(setOperator, integerData.Value); } else if (variable.GetType() == typeof(FloatVariable)) { - FloatVariable lhs = (variable as FloatVariable); - float rhs = floatData.Value; - - switch (setOperator) - { - default: - case SetOperator.Assign: - lhs.Value = rhs; - break; - case SetOperator.Add: - lhs.Value += rhs; - break; - case SetOperator.Subtract: - lhs.Value -= rhs; - break; - case SetOperator.Multiply: - lhs.Value *= rhs; - break; - case SetOperator.Divide: - lhs.Value /= rhs; - break; - } + FloatVariable floatVariable = (variable as FloatVariable); + floatVariable.Apply(setOperator, floatData.Value); } else if (variable.GetType() == typeof(StringVariable)) { - StringVariable lhs = (variable as StringVariable); - string rhs = stringData.Value; - + StringVariable stringVariable = (variable as StringVariable); var flowchart = GetFlowchart(); - rhs = flowchart.SubstituteVariables(rhs); - - switch (setOperator) - { - default: - case SetOperator.Assign: - lhs.Value = rhs; - break; - } + stringVariable.Apply(setOperator, flowchart.SubstituteVariables(stringData.Value)); + } + else if (variable.GetType() == typeof(GameObjectVariable)) + { + GameObjectVariable gameObjectVariable = (variable as GameObjectVariable); + gameObjectVariable.Apply(setOperator, gameObjectData.Value); } } #region Public members + public static readonly Dictionary operatorsByVariableType = new Dictionary() { + { typeof(BooleanVariable), BooleanVariable.setOperators }, + { typeof(IntegerVariable), IntegerVariable.setOperators }, + { typeof(FloatVariable), FloatVariable.setOperators }, + { typeof(StringVariable), StringVariable.setOperators }, + { typeof(GameObjectVariable), GameObjectVariable.setOperators } + }; + /// /// The type of math operation to be performed. /// @@ -208,6 +146,10 @@ namespace Fungus { description += stringData.GetDescription(); } + else if (variable.GetType() == typeof(GameObjectVariable)) + { + description += gameObjectData.GetDescription(); + } return description; } diff --git a/Assets/Fungus/Scripts/Commands/SpawnObject.cs b/Assets/Fungus/Scripts/Commands/SpawnObject.cs index 734243f3..34954d52 100644 --- a/Assets/Fungus/Scripts/Commands/SpawnObject.cs +++ b/Assets/Fungus/Scripts/Commands/SpawnObject.cs @@ -11,7 +11,11 @@ namespace Fungus /// [CommandInfo("Scripting", "Spawn Object", - "Spawns a new object based on a reference to a scene or prefab game object.")] + "Spawns a new object based on a reference to a scene or prefab game object.", + Priority = 10)] + [CommandInfo("GameObject", + "Instantiate", + "Instantiate a game object")] [AddComponentMenu("")] [ExecuteInEditMode] public class SpawnObject : Command @@ -19,15 +23,24 @@ namespace Fungus [Tooltip("Game object to copy when spawning. Can be a scene object or a prefab.")] [SerializeField] protected GameObjectData _sourceObject; - [Tooltip("Transform to use for position of newly spawned object.")] + [Tooltip("Transform to use as parent during instantiate.")] [SerializeField] protected TransformData _parentTransform; + [Tooltip("If true, will use the Transfrom of this Flowchart for the position and rotation.")] + [SerializeField] protected BooleanData _spawnAtSelf = new BooleanData(false); + [Tooltip("Local position of newly spawned object.")] [SerializeField] protected Vector3Data _spawnPosition; [Tooltip("Local rotation of newly spawned object.")] [SerializeField] protected Vector3Data _spawnRotation; + + + [Tooltip("Optional variable to store the GameObject that was just created.")] + [SerializeField] + protected GameObjectData _newlySpawnedObject; + #region Public members public override void OnEnter() @@ -38,14 +51,28 @@ namespace Fungus return; } - GameObject newObject = GameObject.Instantiate(_sourceObject.Value); + GameObject newObject = null; + if (_parentTransform.Value != null) { - newObject.transform.parent = _parentTransform.Value; + newObject = GameObject.Instantiate(_sourceObject.Value,_parentTransform.Value); + } + else + { + newObject = GameObject.Instantiate(_sourceObject.Value); + } + + if (!_spawnAtSelf.Value) + { + newObject.transform.localPosition = _spawnPosition.Value; + newObject.transform.localRotation = Quaternion.Euler(_spawnRotation.Value); + } + else + { + newObject.transform.SetPositionAndRotation(transform.position, transform.rotation); } - newObject.transform.localPosition = _spawnPosition.Value; - newObject.transform.localRotation = Quaternion.Euler(_spawnRotation.Value); + _newlySpawnedObject.Value = newObject; Continue(); } @@ -65,6 +92,16 @@ namespace Fungus return new Color32(235, 191, 217, 255); } + public override bool HasReference(Variable variable) + { + if (_sourceObject.gameObjectRef == variable || _parentTransform.transformRef == variable || + _spawnAtSelf.booleanRef == variable || _spawnPosition.vector3Ref == variable || + _spawnRotation.vector3Ref == variable) + return true; + + return false; + } + #endregion #region Backwards compatibility diff --git a/Assets/Fungus/Scripts/Commands/Transform.meta b/Assets/Fungus/Scripts/Commands/Transform.meta new file mode 100644 index 00000000..7eb641ce --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Transform.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: f7ddb80a0487d1342b36129da32ad1f6 +folderAsset: yes +timeCreated: 1503815490 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Transform/TransformProperty.cs b/Assets/Fungus/Scripts/Commands/Transform/TransformProperty.cs new file mode 100644 index 00000000..32c2850c --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Transform/TransformProperty.cs @@ -0,0 +1,217 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Fungus +{ + // + /// Get or Set a property of a transform component + /// + [CommandInfo("Transform", + "Property", + "Get or Set a property of a transform component")] + [AddComponentMenu("")] + public class TransformProperty : Command + { + public enum GetSet + { + Get, + Set, + } + public GetSet getOrSet = GetSet.Get; + + public enum Property + { + ChildCount, + EulerAngles, + Forward, + HasChanged, + HierarchyCapacity, + HierarchyCount, + LocalEulerAngles, + LocalPosition, + LocalScale, + LossyScale, + Parent, + Position, + Right, + Root, + Up, + //no quat or mat4 yet + //LocalRotation, + //Rotation, + //LocalToWorldMatrix, + //WorldToLocalMatrix + } + [SerializeField] + protected Property property = Property.Position; + + [SerializeField] + protected TransformData transformData; + + [SerializeField] + [VariableProperty(typeof(BooleanVariable), + typeof(IntegerVariable), + typeof(Vector3Variable), + typeof(TransformVariable))] + protected Variable inOutVar; + + public override void OnEnter() + { + var iob = inOutVar as BooleanVariable; + var ioi = inOutVar as IntegerVariable; + var iov = inOutVar as Vector3Variable; + var iot = inOutVar as TransformVariable; + + var t = transformData.Value; + + switch (getOrSet) + { + case GetSet.Get: + switch (property) + { + case Property.ChildCount: + ioi.Value = t.childCount; + break; + case Property.EulerAngles: + iov.Value = t.eulerAngles; + break; + case Property.Forward: + iov.Value = t.forward; + break; + case Property.HasChanged: + iob.Value = t.hasChanged; + break; + case Property.HierarchyCapacity: + ioi.Value = t.hierarchyCapacity; + break; + case Property.HierarchyCount: + ioi.Value = t.hierarchyCount; + break; + case Property.LocalEulerAngles: + iov.Value = t.localEulerAngles; + break; + case Property.LocalPosition: + iov.Value = t.localPosition; + break; + case Property.LocalScale: + iov.Value = t.localScale; + break; + case Property.LossyScale: + iov.Value = t.lossyScale; + break; + case Property.Parent: + iot.Value = t.parent; + break; + case Property.Position: + iov.Value = t.position; + break; + case Property.Right: + iov.Value = t.right; + break; + case Property.Root: + iot.Value = t.parent; + break; + case Property.Up: + iov.Value = t.up; + break; + default: + break; + } + break; + case GetSet.Set: + switch (property) + { + case Property.ChildCount: + Debug.LogWarning("Cannot Set childCount, it is read only"); + break; + case Property.EulerAngles: + t.eulerAngles = iov.Value; + break; + case Property.Forward: + t.forward = iov.Value; + break; + case Property.HasChanged: + t.hasChanged = iob.Value; + break; + case Property.HierarchyCapacity: + t.hierarchyCapacity = ioi.Value; + break; + case Property.HierarchyCount: + Debug.LogWarning("Cannot Set HierarchyCount, it is read only"); + break; + case Property.LocalEulerAngles: + t.localEulerAngles = iov.Value; + break; + case Property.LocalPosition: + t.localPosition = iov.Value; + break; + case Property.LocalScale: + t.localScale = iov.Value; + break; + case Property.LossyScale: + Debug.LogWarning("Cannot Set LossyScale, it is read only"); + break; + case Property.Parent: + t.parent = iot.Value; + break; + case Property.Position: + t.position = iov.Value; + break; + case Property.Right: + t.right = iov.Value; + break; + case Property.Root: + Debug.LogWarning("Cannot Set Root, it is read only"); + break; + case Property.Up: + t.up = iov.Value; + break; + default: + break; + } + break; + default: + break; + } + + Continue(); + } + + public override string GetSummary() + { + if (transformData.Value == null) + { + return "Error: no transform set"; + } + + var iob = inOutVar as BooleanVariable; + var ioi = inOutVar as IntegerVariable; + var iov = inOutVar as Vector3Variable; + var iot = inOutVar as TransformVariable; + + if (iob == null && ioi == null && iov == null && iot == null) + { + return "Error: no variable set to push or pull data to or from"; + } + + //We could do further checks here, eg, you have selected childcount but set a vec3variable + + return getOrSet.ToString() + " " + property.ToString(); + } + + public override Color GetButtonColor() + { + return new Color32(235, 191, 217, 255); + } + + public override bool HasReference(Variable variable) + { + if (transformData.transformRef == variable || inOutVar == variable) + return true; + + return false; + } + + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Transform/TransformProperty.cs.meta b/Assets/Fungus/Scripts/Commands/Transform/TransformProperty.cs.meta new file mode 100644 index 00000000..a3fd7b3c --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Transform/TransformProperty.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 2fb064de1b711a449845627f19b7f7b1 +timeCreated: 1504942828 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/VariableCondition.cs b/Assets/Fungus/Scripts/Commands/VariableCondition.cs new file mode 100644 index 00000000..e5a953b4 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/VariableCondition.cs @@ -0,0 +1,141 @@ +// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus). +// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE) + +using UnityEngine; +using System.Collections.Generic; + +namespace Fungus +{ + public abstract class VariableCondition : Condition + { + [Tooltip("The type of comparison to be performed")] + [SerializeField] protected CompareOperator compareOperator; + + [Tooltip("Variable to use in expression")] + [VariableProperty(typeof(BooleanVariable), + typeof(IntegerVariable), + typeof(FloatVariable), + typeof(StringVariable), + typeof(GameObjectVariable))] + [SerializeField] protected Variable variable; + + [Tooltip("Boolean value to compare against")] + [SerializeField] protected BooleanData booleanData; + + [Tooltip("Integer value to compare against")] + [SerializeField] protected IntegerData integerData; + + [Tooltip("Float value to compare against")] + [SerializeField] protected FloatData floatData; + + [Tooltip("String value to compare against")] + [SerializeField] protected StringDataMulti stringData; + + [Tooltip("GameObject value to compare against")] + [SerializeField] protected GameObjectData gameObjectData; + + protected override bool EvaluateCondition() + { + if (variable == null) + { + return false; + } + + bool condition = false; + + if (variable.GetType() == typeof(BooleanVariable)) + { + BooleanVariable booleanVariable = (variable as BooleanVariable); + condition = booleanVariable.Evaluate(compareOperator, booleanData.Value); + } + else if (variable.GetType() == typeof(IntegerVariable)) + { + IntegerVariable integerVariable = (variable as IntegerVariable); + condition = integerVariable.Evaluate(compareOperator, integerData.Value); + } + else if (variable.GetType() == typeof(FloatVariable)) + { + FloatVariable floatVariable = (variable as FloatVariable); + condition = floatVariable.Evaluate(compareOperator, floatData.Value); + } + else if (variable.GetType() == typeof(StringVariable)) + { + StringVariable stringVariable = (variable as StringVariable); + condition = stringVariable.Evaluate(compareOperator, stringData.Value); + } + else if (variable.GetType() == typeof(GameObjectVariable)) + { + GameObjectVariable gameObjectVariable = (variable as GameObjectVariable); + condition = gameObjectVariable.Evaluate(compareOperator, gameObjectData.Value); + } + + return condition; + } + + protected override bool HasNeededProperties() + { + return (variable != null); + } + + #region Public members + + public static readonly Dictionary operatorsByVariableType = new Dictionary() { + { typeof(BooleanVariable), BooleanVariable.compareOperators }, + { typeof(IntegerVariable), IntegerVariable.compareOperators }, + { typeof(FloatVariable), FloatVariable.compareOperators }, + { typeof(StringVariable), StringVariable.compareOperators }, + { typeof(GameObjectVariable), GameObjectVariable.compareOperators } + }; + + /// + /// The type of comparison operation to be performed. + /// + public virtual CompareOperator _CompareOperator { get { return compareOperator; } } + + public override string GetSummary() + { + if (variable == null) + { + return "Error: No variable selected"; + } + + string summary = variable.Key + " "; + summary += Condition.GetOperatorDescription(compareOperator) + " "; + + if (variable.GetType() == typeof(BooleanVariable)) + { + summary += booleanData.GetDescription(); + } + else if (variable.GetType() == typeof(IntegerVariable)) + { + summary += integerData.GetDescription(); + } + else if (variable.GetType() == typeof(FloatVariable)) + { + summary += floatData.GetDescription(); + } + else if (variable.GetType() == typeof(StringVariable)) + { + summary += stringData.GetDescription(); + } + else if (variable.GetType() == typeof(GameObjectVariable)) + { + summary += gameObjectData.GetDescription(); + } + + return summary; + } + + public override bool HasReference(Variable variable) + { + return (variable == this.variable); + } + + public override Color GetButtonColor() + { + return new Color32(253, 253, 150, 255); + } + + #endregion + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/VariableCondition.cs.meta b/Assets/Fungus/Scripts/Commands/VariableCondition.cs.meta new file mode 100644 index 00000000..62776780 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/VariableCondition.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: b065f7dff8779442ab5841ccc6ae375b +timeCreated: 1493077787 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Vector3.meta b/Assets/Fungus/Scripts/Commands/Vector3.meta new file mode 100644 index 00000000..70aff798 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Vector3.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 9c57d4347eae5354b8bcf942c2b3468a +folderAsset: yes +timeCreated: 1503030603 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Vector3/Vector3Arithmetic.cs b/Assets/Fungus/Scripts/Commands/Vector3/Vector3Arithmetic.cs new file mode 100644 index 00000000..fe53a530 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Vector3/Vector3Arithmetic.cs @@ -0,0 +1,82 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Fungus +{ + /// + /// Vector3 add, sub, mul, div arithmetic + /// + [CommandInfo("Vector3", + "Arithmetic", + "Vector3 add, sub, mul, div arithmetic")] + [AddComponentMenu("")] + public class Vector3Arithmetic : Command + { + [SerializeField] + protected Vector3Data lhs, rhs, output; + + public enum Operation + { + Add, + Sub, + Mul, + Div + } + + [SerializeField] + protected Operation operation = Operation.Add; + + public override void OnEnter() + { + Vector3 tmp; + switch (operation) + { + case Operation.Add: + output.Value = lhs.Value + rhs.Value; + break; + case Operation.Sub: + output.Value = lhs.Value - rhs.Value; + break; + case Operation.Mul: + tmp = lhs.Value; + tmp.Scale(rhs.Value); + output.Value = tmp; + break; + case Operation.Div: + tmp = lhs.Value; + tmp.Scale(new Vector3(1.0f / rhs.Value.x, + 1.0f / rhs.Value.y, + 1.0f / rhs.Value.z)); + output.Value = tmp; + break; + default: + break; + } + Continue(); + } + + public override string GetSummary() + { + if (output.vector3Ref == null) + { + return "Error: no output set"; + } + + return operation.ToString() + ": stored in " + output.vector3Ref.Key; + } + + public override Color GetButtonColor() + { + return new Color32(235, 191, 217, 255); + } + + public override bool HasReference(Variable variable) + { + if (lhs.vector3Ref == variable || rhs.vector3Ref == variable || output.vector3Ref == variable) + return true; + + return false; + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Vector3/Vector3Arithmetic.cs.meta b/Assets/Fungus/Scripts/Commands/Vector3/Vector3Arithmetic.cs.meta new file mode 100644 index 00000000..c9a97be1 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Vector3/Vector3Arithmetic.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: dfc8e8d5ce363ec43815496d321b4d55 +timeCreated: 1503313996 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Vector3/Vector3Fields.cs b/Assets/Fungus/Scripts/Commands/Vector3/Vector3Fields.cs new file mode 100644 index 00000000..baafe67f --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Vector3/Vector3Fields.cs @@ -0,0 +1,74 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Fungus +{ + // + /// Get or Set the x,y,z fields of a vector3 via floatvars + /// + [CommandInfo("Vector3", + "Fields", + "Get or Set the x,y,z fields of a vector3 via floatvars")] + [AddComponentMenu("")] + public class Vector3Fields : Command + { + public enum GetSet + { + Get, + Set, + } + public GetSet getOrSet = GetSet.Get; + + [SerializeField] + protected Vector3Data vec3; + + [SerializeField] + protected FloatData x, y, z; + + public override void OnEnter() + { + switch (getOrSet) + { + case GetSet.Get: + + var v = vec3.Value; + + x.Value = v.x; + y.Value = v.y; + z.Value = v.z; + break; + case GetSet.Set: + vec3.Value = new Vector3(x.Value, y.Value, z.Value); + break; + default: + break; + } + + Continue(); + } + + public override string GetSummary() + { + if (vec3.vector3Ref == null) + { + return "Error: vec3 not set"; + } + + return getOrSet.ToString() + " (" + vec3.vector3Ref.Key + ")"; + } + + public override Color GetButtonColor() + { + return new Color32(235, 191, 217, 255); + } + + public override bool HasReference(Variable variable) + { + if (vec3.vector3Ref == variable || x.floatRef == variable || y.floatRef == variable || z.floatRef == variable) + return true; + + return false; + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Vector3/Vector3Fields.cs.meta b/Assets/Fungus/Scripts/Commands/Vector3/Vector3Fields.cs.meta new file mode 100644 index 00000000..84af4e70 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Vector3/Vector3Fields.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 96fb07b07bec30544a6c3c01df5345ee +timeCreated: 1504933522 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Vector3/Vector3Normalise.cs b/Assets/Fungus/Scripts/Commands/Vector3/Vector3Normalise.cs new file mode 100644 index 00000000..f4323e49 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Vector3/Vector3Normalise.cs @@ -0,0 +1,47 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Fungus +{ + // + /// Normalise a vector3, output can be the same as the input + /// + [CommandInfo("Vector3", + "Normalise", + "Normalise a Vector3")] + [AddComponentMenu("")] + public class Vector3Normalise : Command + { + [SerializeField] + protected Vector3Data vec3In, vec3Out; + + public override void OnEnter() + { + vec3Out.Value = vec3In.Value.normalized; + + Continue(); + } + + public override string GetSummary() + { + if (vec3Out.vector3Ref == null) + return ""; + else + return vec3Out.vector3Ref.Key; + } + + public override Color GetButtonColor() + { + return new Color32(235, 191, 217, 255); + } + + public override bool HasReference(Variable variable) + { + if (vec3In.vector3Ref == variable || vec3Out.vector3Ref == variable) + return true; + + return false; + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Vector3/Vector3Normalise.cs.meta b/Assets/Fungus/Scripts/Commands/Vector3/Vector3Normalise.cs.meta new file mode 100644 index 00000000..3088262c --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Vector3/Vector3Normalise.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: b9c975313c082cd43a310bfd62ebb893 +timeCreated: 1504171804 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Vector3/Vector3ToVector2.cs b/Assets/Fungus/Scripts/Commands/Vector3/Vector3ToVector2.cs new file mode 100644 index 00000000..9f08b761 --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Vector3/Vector3ToVector2.cs @@ -0,0 +1,54 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Fungus +{ + // + /// Convert fungus vec3 to vec2 + /// + [CommandInfo("Vector3", + "ToVector2", + "Convert Fungus Vector3 to Fungus Vector2")] + [AddComponentMenu("")] + public class Vector3ToVector2 : Command + { + [SerializeField] + protected Vector3Data vec3; + + + [SerializeField] + protected Vector2Data vec2; + + public override void OnEnter() + { + vec2.Value = vec3.Value; + + Continue(); + } + + public override string GetSummary() + { + if (vec3.vector3Ref != null && vec2.vector2Ref != null) + { + return "Converting " + vec3.vector3Ref.Key + " to " + vec2.vector2Ref.Key; + } + + return "Error: variables not set"; + } + + public override Color GetButtonColor() + { + return new Color32(235, 191, 217, 255); + } + + + public override bool HasReference(Variable variable) + { + if (variable == vec3.vector3Ref || variable == vec2.vector2Ref) + return true; + + return false; + } + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Commands/Vector3/Vector3ToVector2.cs.meta b/Assets/Fungus/Scripts/Commands/Vector3/Vector3ToVector2.cs.meta new file mode 100644 index 00000000..2f6ea5fb --- /dev/null +++ b/Assets/Fungus/Scripts/Commands/Vector3/Vector3ToVector2.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: d3b374d347ec80647b7c01956f291a84 +timeCreated: 1504171432 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Commands/Write.cs b/Assets/Fungus/Scripts/Commands/Write.cs index 5ce063f1..297df887 100644 --- a/Assets/Fungus/Scripts/Commands/Write.cs +++ b/Assets/Fungus/Scripts/Commands/Write.cs @@ -99,12 +99,12 @@ namespace Fungus if (!waitUntilFinished) { - StartCoroutine(writer.Write(newText, clearText, false, true, null, null)); + StartCoroutine(writer.Write(newText, clearText, false, true, false, null, null)); Continue(); } else { - StartCoroutine(writer.Write(newText, clearText, false, true, null, + StartCoroutine(writer.Write(newText, clearText, false, true, false, null, () => { Continue (); } )); } diff --git a/Assets/Fungus/Scripts/Components/CameraManager.cs b/Assets/Fungus/Scripts/Components/CameraManager.cs index d6c04acc..0d51528e 100644 --- a/Assets/Fungus/Scripts/Components/CameraManager.cs +++ b/Assets/Fungus/Scripts/Components/CameraManager.cs @@ -42,6 +42,10 @@ namespace Fungus protected View swipePanViewB; protected Vector3 previousMousePos; + //Coroutine handles for panning and fading commands + protected IEnumerator panCoroutine; + protected IEnumerator fadeCoroutine; + protected class CameraView { public Vector3 cameraPos; @@ -331,8 +335,7 @@ namespace Fungus view.ViewSize); pathList.Add(viewPos); } - - StartCoroutine(PanToPathInternal(camera, duration, arriveAction, pathList.ToArray())); + StartCoroutine(panCoroutine = PanToPathInternal (camera, duration, arriveAction, pathList.ToArray ())); } /// @@ -363,7 +366,7 @@ namespace Fungus /// public virtual void Fade(float targetAlpha, float fadeDuration, Action fadeAction) { - StartCoroutine(FadeInternal(targetAlpha, fadeDuration, fadeAction)); + StartCoroutine(fadeCoroutine = FadeInternal (targetAlpha, fadeDuration, fadeAction)); } /// @@ -410,6 +413,8 @@ namespace Fungus public virtual void Stop() { StopAllCoroutines(); + panCoroutine = null; + fadeCoroutine = null; } /// @@ -424,8 +429,10 @@ namespace Fungus } // Stop any pan that is currently active - StopAllCoroutines(); - + if (panCoroutine != null) { + StopCoroutine(panCoroutine); + panCoroutine = null; + } swipePanActive = false; if (Mathf.Approximately(duration, 0f)) @@ -444,7 +451,7 @@ namespace Fungus } else { - StartCoroutine(PanInternal(camera, targetPosition, targetRotation, targetSize, duration, arriveAction)); + StartCoroutine(panCoroutine = PanInternal(camera, targetPosition, targetRotation, targetSize, duration, arriveAction)); } } diff --git a/Assets/Fungus/Scripts/Components/Command.cs b/Assets/Fungus/Scripts/Components/Command.cs index 64407984..0c63df11 100644 --- a/Assets/Fungus/Scripts/Components/Command.cs +++ b/Assets/Fungus/Scripts/Components/Command.cs @@ -11,6 +11,8 @@ namespace Fungus /// /// Attribute class for Fungus commands. /// + /// + [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] public class CommandInfoAttribute : Attribute { /// diff --git a/Assets/Fungus/Scripts/Components/Flowchart.cs b/Assets/Fungus/Scripts/Components/Flowchart.cs index 1c1224d4..d56aae2e 100644 --- a/Assets/Fungus/Scripts/Components/Flowchart.cs +++ b/Assets/Fungus/Scripts/Components/Flowchart.cs @@ -87,14 +87,6 @@ namespace Fungus protected StringSubstituter stringSubstituer; #if UNITY_5_4_OR_NEWER - protected virtual void Awake() - { - CheckEventSystem(); - - UnityEngine.SceneManagement.SceneManager.activeSceneChanged += (A, B) => { - LevelWasLoaded(); - }; - } #else protected virtual void OnLevelWasLoaded(int level) { @@ -137,16 +129,38 @@ namespace Fungus eventSystemPresent = true; } + private void SceneManager_activeSceneChanged(UnityEngine.SceneManagement.Scene arg0, UnityEngine.SceneManagement.Scene arg1) + { + LevelWasLoaded(); + } + protected virtual void OnEnable() { if (!cachedFlowcharts.Contains(this)) { cachedFlowcharts.Add(this); + //TODO these pairs could be replaced by something static that manages all active flowcharts + #if UNITY_5_4_OR_NEWER + UnityEngine.SceneManagement.SceneManager.activeSceneChanged += SceneManager_activeSceneChanged; + #endif } CheckItemIds(); CleanupComponents(); UpdateVersion(); + + StringSubstituter.RegisterHandler(this); + } + + protected virtual void OnDisable() + { + cachedFlowcharts.Remove(this); + + #if UNITY_5_4_OR_NEWER + UnityEngine.SceneManagement.SceneManager.activeSceneChanged -= SceneManager_activeSceneChanged; + #endif + + StringSubstituter.UnregisterHandler(this); } protected virtual void UpdateVersion() @@ -172,11 +186,6 @@ namespace Fungus version = FungusConstants.CurrentVersion; } - protected virtual void OnDisable() - { - cachedFlowcharts.Remove(this); - } - protected virtual void CheckItemIds() { // Make sure item ids are unique and monotonically increasing. @@ -473,6 +482,31 @@ namespace Fungus return null; } + /// + /// Checks availability of the block in the Flowchart. + /// You can use this method in a UI event. e.g. to test availability block, before handle it. + public virtual bool HasBlock(string blockName) + { + var block = FindBlock(blockName); + return block != null; + } + + /// + /// Executes the block if it is available in the Flowchart. + /// You can use this method in a UI event. e.g. to try executing block without confidence in its existence. + public virtual bool ExecuteIfHasBlock(string blockName) + { + if (HasBlock(blockName)) + { + ExecuteBlock(blockName); + return true; + } + else + { + return false; + } + } + /// /// Execute a child block in the Flowchart. /// You can use this method in a UI event. e.g. to handle a button click. @@ -491,6 +525,25 @@ namespace Fungus Debug.LogWarning("Block " + blockName + "failed to execute"); } } + + /// + /// Stops an executing Block in the Flowchart. + /// + public virtual void StopBlock(string blockName) + { + var block = FindBlock(blockName); + + if (block == null) + { + Debug.LogError("Block " + blockName + "does not exist"); + return; + } + + if (block.IsExecuting()) + { + block.Stop(); + } + } /// /// Execute a child block in the flowchart. @@ -1162,7 +1215,6 @@ namespace Fungus if (stringSubstituer == null) { stringSubstituer = new StringSubstituter(); - stringSubstituer.CacheSubstitutionHandlers(); } // Use the string builder from StringSubstituter for efficiency. diff --git a/Assets/Fungus/Scripts/Components/FungusManager.cs b/Assets/Fungus/Scripts/Components/FungusManager.cs index 0ccd033f..45ebf836 100644 --- a/Assets/Fungus/Scripts/Components/FungusManager.cs +++ b/Assets/Fungus/Scripts/Components/FungusManager.cs @@ -12,7 +12,8 @@ namespace Fungus [RequireComponent(typeof(CameraManager))] [RequireComponent(typeof(MusicManager))] [RequireComponent(typeof(EventDispatcher))] - #if UNITY_5_3_OR_NEWER + [RequireComponent(typeof(GlobalVariables))] +#if UNITY_5_3_OR_NEWER [RequireComponent(typeof(SaveManager))] [RequireComponent(typeof(NarrativeLog))] #endif @@ -27,7 +28,8 @@ namespace Fungus CameraManager = GetComponent(); MusicManager = GetComponent(); EventDispatcher = GetComponent(); - #if UNITY_5_3_OR_NEWER + GlobalVariables = GetComponent(); +#if UNITY_5_3_OR_NEWER SaveManager = GetComponent(); NarrativeLog = GetComponent(); #endif @@ -63,7 +65,12 @@ namespace Fungus /// public EventDispatcher EventDispatcher { get; private set; } - #if UNITY_5_3_OR_NEWER + /// + /// Gets the global variable singleton instance. + /// + public GlobalVariables GlobalVariables { get; private set; } + +#if UNITY_5_3_OR_NEWER /// /// Gets the save manager singleton instance. /// diff --git a/Assets/Fungus/Scripts/Components/Localization.cs b/Assets/Fungus/Scripts/Components/Localization.cs index 604e107b..5a4b0d76 100644 --- a/Assets/Fungus/Scripts/Components/Localization.cs +++ b/Assets/Fungus/Scripts/Components/Localization.cs @@ -42,12 +42,6 @@ namespace Fungus protected static Dictionary localizedStrings = new Dictionary(); #if UNITY_5_4_OR_NEWER - protected virtual void Awake() - { - UnityEngine.SceneManagement.SceneManager.activeSceneChanged += (A, B) => { - LevelWasLoaded(); - }; - } #else public virtual void OnLevelWasLoaded(int level) { @@ -65,6 +59,27 @@ namespace Fungus } } + private void SceneManager_activeSceneChanged(UnityEngine.SceneManagement.Scene arg0, UnityEngine.SceneManagement.Scene arg1) + { + LevelWasLoaded(); + } + + protected virtual void OnEnable() + { + StringSubstituter.RegisterHandler(this); + #if UNITY_5_4_OR_NEWER + UnityEngine.SceneManagement.SceneManager.activeSceneChanged += SceneManager_activeSceneChanged; + #endif + } + + protected virtual void OnDisable() + { + StringSubstituter.UnregisterHandler(this); + #if UNITY_5_4_OR_NEWER + UnityEngine.SceneManagement.SceneManager.activeSceneChanged -= SceneManager_activeSceneChanged; + #endif + } + protected virtual void Start() { Init(); diff --git a/Assets/Fungus/Scripts/Components/MenuDialog.cs b/Assets/Fungus/Scripts/Components/MenuDialog.cs index 44d76085..9462276c 100644 --- a/Assets/Fungus/Scripts/Components/MenuDialog.cs +++ b/Assets/Fungus/Scripts/Components/MenuDialog.cs @@ -21,6 +21,67 @@ namespace Fungus protected Button[] cachedButtons; protected Slider cachedSlider; + private int nextOptionIndex; + + #region Public members + + /// + /// Currently active Menu Dialog used to display Menu options + /// + public static MenuDialog ActiveMenuDialog { get; set; } + + /// + /// A cached list of button objects in the menu dialog. + /// + /// The cached buttons. + public virtual Button[] CachedButtons { get { return cachedButtons; } } + + /// + /// A cached slider object used for the timer in the menu dialog. + /// + /// The cached slider. + public virtual Slider CachedSlider { get { return cachedSlider; } } + + /// + /// Sets the active state of the Menu Dialog gameobject. + /// + public virtual void SetActive(bool state) + { + gameObject.SetActive(state); + } + + + + /// + /// Returns a menu dialog by searching for one in the scene or creating one if none exists. + /// + public static MenuDialog GetMenuDialog() + { + if (ActiveMenuDialog == null) + { + // Use first Menu Dialog found in the scene (if any) + var md = GameObject.FindObjectOfType(); + if (md != null) + { + ActiveMenuDialog = md; + } + + if (ActiveMenuDialog == null) + { + // Auto spawn a menu dialog object from the prefab + GameObject prefab = Resources.Load("Prefabs/MenuDialog"); + if (prefab != null) + { + GameObject go = Instantiate(prefab) as GameObject; + go.SetActive(false); + go.name = "MenuDialog"; + ActiveMenuDialog = go.GetComponent(); + } + } + } + + return ActiveMenuDialog; + } protected virtual void Awake() { @@ -66,9 +127,9 @@ namespace Fungus protected virtual IEnumerator WaitForTimeout(float timeoutDuration, Block targetBlock) { float elapsedTime = 0; - - Slider timeoutSlider = GetComponentInChildren(); - + + Slider timeoutSlider = CachedSlider; + while (elapsedTime < timeoutDuration) { if (timeoutSlider != null) @@ -76,12 +137,12 @@ namespace Fungus float t = 1f - elapsedTime / timeoutDuration; timeoutSlider.value = t; } - + elapsedTime += Time.deltaTime; - + yield return null; } - + Clear(); gameObject.SetActive(false); @@ -108,64 +169,6 @@ namespace Fungus } } - #region Public members - - /// - /// Currently active Menu Dialog used to display Menu options - /// - public static MenuDialog ActiveMenuDialog { get; set; } - - /// - /// Returns a menu dialog by searching for one in the scene or creating one if none exists. - /// - public static MenuDialog GetMenuDialog() - { - if (ActiveMenuDialog == null) - { - // Use first Menu Dialog found in the scene (if any) - var md = GameObject.FindObjectOfType(); - if (md != null) - { - ActiveMenuDialog = md; - } - - if (ActiveMenuDialog == null) - { - // Auto spawn a menu dialog object from the prefab - GameObject prefab = Resources.Load("Prefabs/MenuDialog"); - if (prefab != null) - { - GameObject go = Instantiate(prefab) as GameObject; - go.SetActive(false); - go.name = "MenuDialog"; - ActiveMenuDialog = go.GetComponent(); - } - } - } - - return ActiveMenuDialog; - } - - /// - /// A cached list of button objects in the menu dialog. - /// - /// The cached buttons. - public virtual Button[] CachedButtons { get { return cachedButtons; } } - - /// - /// A cached slider object used for the timer in the menu dialog. - /// - /// The cached slider. - public virtual Slider CachedSlider { get { return cachedSlider; } } - - /// - /// Sets the active state of the Menu Dialog gameobject. - /// - public virtual void SetActive(bool state) - { - gameObject.SetActive(state); - } - /// /// Clear all displayed options in the Menu Dialog. /// @@ -173,7 +176,9 @@ namespace Fungus { StopAllCoroutines(); - var optionButtons = GetComponentsInChildren