From 74a243ad12013407ea3492146108ffb7b331587e Mon Sep 17 00:00:00 2001 From: Christopher Date: Mon, 14 Nov 2016 16:07:27 +0000 Subject: [PATCH] Start Label property in Call command --- Assets/Fungus/Scripts/Commands/Call.cs | 18 +- Assets/Fungus/Scripts/Components/Block.cs | 23 ++ Assets/Fungus/Scripts/Editor/CallEditor.cs | 4 + Assets/FungusExamples/SaveGame/SceneA.unity | 7 +- Assets/Tests/Flow/FlowTests.unity | 351 ++++++++++++++++++-- 5 files changed, 371 insertions(+), 32 deletions(-) diff --git a/Assets/Fungus/Scripts/Commands/Call.cs b/Assets/Fungus/Scripts/Commands/Call.cs index b1c37b3f..a7ed151e 100644 --- a/Assets/Fungus/Scripts/Commands/Call.cs +++ b/Assets/Fungus/Scripts/Commands/Call.cs @@ -37,6 +37,9 @@ namespace Fungus [Tooltip("Block to start executing")] [SerializeField] protected Block targetBlock; + [Tooltip("Label to start exeuction at. Takes priority over startIndex.")] + [SerializeField] protected StringData startLabel = new StringData(); + [Tooltip("Command index to start executing")] [FormerlySerializedAs("commandIndex")] [SerializeField] protected int startIndex; @@ -70,6 +73,17 @@ namespace Fungus }; } + // Find the command index to start execution at + int index = startIndex; + if (startLabel != "") + { + int labelIndex = targetBlock.GetLabelIndex(startLabel); + if (labelIndex != -1) + { + index = labelIndex; + } + } + if (targetFlowchart == null || targetFlowchart.Equals(GetFlowchart())) { @@ -80,12 +94,12 @@ namespace Fungus flowchart.SelectedBlock = targetBlock; } - StartCoroutine(targetBlock.Execute(startIndex, onComplete)); + StartCoroutine(targetBlock.Execute(index, onComplete)); } else { // Execute block in another Flowchart - targetFlowchart.ExecuteBlock(targetBlock, startIndex, onComplete); + targetFlowchart.ExecuteBlock(targetBlock, index, onComplete); } } diff --git a/Assets/Fungus/Scripts/Components/Block.cs b/Assets/Fungus/Scripts/Components/Block.cs index b181a3f0..8fba6b91 100644 --- a/Assets/Fungus/Scripts/Components/Block.cs +++ b/Assets/Fungus/Scripts/Components/Block.cs @@ -382,6 +382,29 @@ namespace Fungus } } + /// + /// Returns the index of the Label command with matching key, or -1 if not found. + /// + public virtual int GetLabelIndex(string labelKey) + { + if (labelKey.Length == 0) + { + return -1; + } + + for (int i = 0; i < commandList.Count; i++) + { + var command = commandList[i]; + var labelCommand = command as Label; + if (labelCommand != null && String.Compare(labelCommand.Key, labelKey, true) == 0) + { + return i; + } + } + + return -1; + } + #endregion } } diff --git a/Assets/Fungus/Scripts/Editor/CallEditor.cs b/Assets/Fungus/Scripts/Editor/CallEditor.cs index d2c6c4b7..2397ff19 100644 --- a/Assets/Fungus/Scripts/Editor/CallEditor.cs +++ b/Assets/Fungus/Scripts/Editor/CallEditor.cs @@ -11,6 +11,7 @@ namespace Fungus.EditorUtils { protected SerializedProperty targetFlowchartProp; protected SerializedProperty targetBlockProp; + protected SerializedProperty startLabelProp; protected SerializedProperty startIndexProp; protected SerializedProperty callModeProp; @@ -21,6 +22,7 @@ namespace Fungus.EditorUtils targetFlowchartProp = serializedObject.FindProperty("targetFlowchart"); targetBlockProp = serializedObject.FindProperty("targetBlock"); + startLabelProp = serializedObject.FindProperty("startLabel"); startIndexProp = serializedObject.FindProperty("startIndex"); callModeProp = serializedObject.FindProperty("callMode"); } @@ -50,6 +52,8 @@ namespace Fungus.EditorUtils new GUIContent(""), flowchart); + EditorGUILayout.PropertyField(startLabelProp); + EditorGUILayout.PropertyField(startIndexProp); } diff --git a/Assets/FungusExamples/SaveGame/SceneA.unity b/Assets/FungusExamples/SaveGame/SceneA.unity index 6112856c..38191696 100644 --- a/Assets/FungusExamples/SaveGame/SceneA.unity +++ b/Assets/FungusExamples/SaveGame/SceneA.unity @@ -206,8 +206,7 @@ MonoBehaviour: height: 869 selectedBlocks: - {fileID: 27697870} - selectedCommands: - - {fileID: 27697876} + selectedCommands: [] variables: - {fileID: 27697873} description: @@ -287,8 +286,8 @@ MonoBehaviour: m_EditorClassIdentifier: nodeRect: serializedVersion: 2 - x: 224 - y: 74 + x: 246 + y: 69 width: 120 height: 40 tint: {r: 1, g: 1, b: 1, a: 1} diff --git a/Assets/Tests/Flow/FlowTests.unity b/Assets/Tests/Flow/FlowTests.unity index 68a7c6ac..213135ac 100644 --- a/Assets/Tests/Flow/FlowTests.unity +++ b/Assets/Tests/Flow/FlowTests.unity @@ -13,7 +13,7 @@ SceneSettings: --- !u!104 &2 RenderSettings: m_ObjectHideFlags: 0 - serializedVersion: 6 + serializedVersion: 7 m_Fog: 0 m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} m_FogMode: 3 @@ -37,12 +37,12 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} + m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1} --- !u!157 &3 LightmapSettings: m_ObjectHideFlags: 0 - serializedVersion: 6 + serializedVersion: 7 m_GIWorkflowMode: 1 - m_LightmapsMode: 1 m_GISettings: serializedVersion: 2 m_BounceScale: 1 @@ -53,17 +53,22 @@ LightmapSettings: m_EnableBakedLightmaps: 0 m_EnableRealtimeLightmaps: 0 m_LightmapEditorSettings: - serializedVersion: 3 + serializedVersion: 4 m_Resolution: 2 m_BakeResolution: 40 m_TextureWidth: 1024 m_TextureHeight: 1024 + m_AO: 0 m_AOMaxDistance: 1 - m_Padding: 2 m_CompAOExponent: 0 + m_CompAOExponentDirect: 0 + m_Padding: 2 m_LightmapParameters: {fileID: 0} + m_LightmapsBakeMode: 1 m_TextureCompression: 1 + m_DirectLightInLightProbes: 1 m_FinalGather: 0 + m_FinalGatherFiltering: 1 m_FinalGatherRayCount: 1024 m_ReflectionCompression: 2 m_LightingDataAsset: {fileID: 0} @@ -244,7 +249,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!114 &730370421 MonoBehaviour: m_ObjectHideFlags: 0 @@ -442,7 +447,6 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: itemId: 4 - errorMessage: indentLevel: 0 --- !u!114 &897339007 MonoBehaviour: @@ -456,7 +460,6 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: itemId: 3 - errorMessage: indentLevel: 0 failMessage: --- !u!114 &897339008 @@ -471,10 +474,12 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: itemId: 2 - errorMessage: indentLevel: 0 targetFlowchart: {fileID: 0} targetBlock: {fileID: 897339009} + startLabel: + stringRef: {fileID: 0} + stringVal: startIndex: 1 callMode: 0 --- !u!114 &897339009 @@ -494,6 +499,8 @@ MonoBehaviour: y: 70 width: 120 height: 40 + tint: {r: 1, g: 1, b: 1, a: 1} + useCustomTint: 0 itemId: 1 blockName: OtherBlock description: @@ -514,6 +521,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: parentBlock: {fileID: 897339011} + waitForFrames: 1 --- !u!114 &897339011 MonoBehaviour: m_ObjectHideFlags: 2 @@ -532,6 +540,8 @@ MonoBehaviour: y: 70 width: 120 height: 40 + tint: {r: 1, g: 1, b: 1, a: 1} + useCustomTint: 0 itemId: 0 blockName: Start description: @@ -562,7 +572,7 @@ MonoBehaviour: y: -350 width: 1121 height: 869 - selectedBlock: {fileID: 0} + selectedBlocks: [] selectedCommands: [] variables: [] description: "Test using the call index property to call \na specific command in @@ -574,6 +584,59 @@ MonoBehaviour: localizationId: showLineNumbers: 0 hideCommands: [] + luaEnvironment: {fileID: 0} + luaBindingName: flowchart +--- !u!1 &919683558 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 919683560} + - 114: {fileID: 919683559} + m_Layer: 0 + m_Name: CallWithLabelTest + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 0 +--- !u!114 &919683559 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 919683558} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: b1dba0b27b0864740a8720e920aa88c0, type: 3} + m_Name: + m_EditorClassIdentifier: + timeout: 5 + ignored: 0 + succeedAfterAllAssertionsAreExecuted: 0 + expectException: 0 + expectedExceptionList: + succeedWhenExceptionIsThrown: 0 + includedPlatforms: -1 + platformsToIgnore: [] + dynamic: 0 + dynamicTypeName: +--- !u!4 &919683560 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 919683558} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_Children: + - {fileID: 2121984966} + m_Father: {fileID: 0} + m_RootOrder: 7 --- !u!1 &1040991508 GameObject: m_ObjectHideFlags: 0 @@ -617,7 +680,6 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: itemId: 1 - errorMessage: indentLevel: 0 --- !u!114 &1040991511 MonoBehaviour: @@ -637,6 +699,8 @@ MonoBehaviour: y: 70 width: 120 height: 40 + tint: {r: 1, g: 1, b: 1, a: 1} + useCustomTint: 0 itemId: 0 blockName: DoTest description: @@ -667,7 +731,7 @@ MonoBehaviour: y: -340 width: 1114 height: 859 - selectedBlock: {fileID: 1040991511} + selectedBlocks: [] selectedCommands: - {fileID: 1040991510} variables: [] @@ -679,6 +743,8 @@ MonoBehaviour: localizationId: showLineNumbers: 0 hideCommands: [] + luaEnvironment: {fileID: 0} + luaBindingName: flowchart --- !u!1 &1220080381 GameObject: m_ObjectHideFlags: 0 @@ -813,7 +879,6 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: itemId: 4 - errorMessage: indentLevel: 0 --- !u!114 &1253352150 MonoBehaviour: @@ -827,7 +892,6 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: itemId: 3 - errorMessage: indentLevel: 0 failMessage: --- !u!114 &1253352151 @@ -842,7 +906,6 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: itemId: 2 - errorMessage: indentLevel: 0 key: MyLabel --- !u!114 &1253352152 @@ -857,7 +920,6 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: itemId: 1 - errorMessage: indentLevel: 0 _targetLabel: stringRef: {fileID: 0} @@ -876,6 +938,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: parentBlock: {fileID: 1253352154} + waitForFrames: 1 --- !u!114 &1253352154 MonoBehaviour: m_ObjectHideFlags: 2 @@ -894,6 +957,8 @@ MonoBehaviour: y: 70 width: 120 height: 40 + tint: {r: 1, g: 1, b: 1, a: 1} + useCustomTint: 0 itemId: 0 blockName: Start description: @@ -916,18 +981,18 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: version: 1 - scrollPos: {x: 0, y: 0} + scrollPos: {x: 3.562703, y: 1.8540598} variablesScrollPos: {x: 0, y: 0} variablesExpanded: 1 blockViewHeight: 400 - zoom: 1 + zoom: 0.98802704 scrollViewRect: serializedVersion: 2 - x: -343 - y: -340 - width: 1114 - height: 859 - selectedBlock: {fileID: 0} + x: -350 + y: -350 + width: 1121 + height: 869 + selectedBlocks: [] selectedCommands: [] variables: [] description: Tests if jumping to a label works correctly @@ -938,6 +1003,8 @@ MonoBehaviour: localizationId: showLineNumbers: 0 hideCommands: [] + luaEnvironment: {fileID: 0} + luaBindingName: flowchart --- !u!1 &1501994597 GameObject: m_ObjectHideFlags: 0 @@ -1185,7 +1252,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: ba19c26c1ba7243d2b57ebc4329cc7c6, type: 3} m_Name: m_EditorClassIdentifier: - remoteDebugger: 0 --- !u!114 &1601427684 MonoBehaviour: m_ObjectHideFlags: 0 @@ -1263,7 +1329,6 @@ MonoBehaviour: executeAfterFrames: 1 repeatExecuteFrame: 1 repeatEveryFrame: 1 - hasFailed: 0 executeMethods: 2 executeMethodName: OnExecute --- !u!1 &1873336849 @@ -1293,7 +1358,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 61dddfdc5e0e44ca298d8f46f7f5a915, type: 3} m_Name: m_EditorClassIdentifier: - selectedFlowchart: {fileID: 1253352155} + selectedFlowchart: {fileID: 2121984976} --- !u!4 &1873336851 Transform: m_ObjectHideFlags: 1 @@ -1360,3 +1425,237 @@ Transform: - {fileID: 1601427681} m_Father: {fileID: 0} m_RootOrder: 3 +--- !u!1 &2121984965 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 142980, guid: 5e7fbc8d4eb714b279eeeef2262c1e1a, type: 2} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 2121984966} + - 114: {fileID: 2121984976} + - 114: {fileID: 2121984975} + - 114: {fileID: 2121984974} + - 114: {fileID: 2121984973} + - 114: {fileID: 2121984972} + - 114: {fileID: 2121984971} + - 114: {fileID: 2121984970} + - 114: {fileID: 2121984969} + - 114: {fileID: 2121984968} + - 114: {fileID: 2121984967} + m_Layer: 0 + m_Name: Flowchart + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2121984966 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 467082, guid: 5e7fbc8d4eb714b279eeeef2262c1e1a, type: 2} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2121984965} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_Children: [] + m_Father: {fileID: 919683560} + m_RootOrder: 0 +--- !u!114 &2121984967 +MonoBehaviour: + m_ObjectHideFlags: 2 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2121984965} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5f1ca510a57aa47568a5e4ee558ff41f, type: 3} + m_Name: + m_EditorClassIdentifier: + itemId: 7 + indentLevel: 0 +--- !u!114 &2121984968 +MonoBehaviour: + m_ObjectHideFlags: 2 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2121984965} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4920f47cde1a84b11ad07b7317568494, type: 3} + m_Name: + m_EditorClassIdentifier: + itemId: 6 + indentLevel: 0 +--- !u!114 &2121984969 +MonoBehaviour: + m_ObjectHideFlags: 2 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2121984965} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 2dcb71131f45b47fead560a97ef55f1c, type: 3} + m_Name: + m_EditorClassIdentifier: + itemId: 5 + indentLevel: 0 + failMessage: +--- !u!114 &2121984970 +MonoBehaviour: + m_ObjectHideFlags: 2 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2121984965} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: ea4da378c47144a86979765ac5e9690c, type: 3} + m_Name: + m_EditorClassIdentifier: + itemId: 4 + indentLevel: 0 + key: LabelB +--- !u!114 &2121984971 +MonoBehaviour: + m_ObjectHideFlags: 2 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2121984965} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: ea4da378c47144a86979765ac5e9690c, type: 3} + m_Name: + m_EditorClassIdentifier: + itemId: 3 + indentLevel: 0 + key: LabelA +--- !u!114 &2121984972 +MonoBehaviour: + m_ObjectHideFlags: 2 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2121984965} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 050fb9e6e72f442b3b883da8a965bdeb, type: 3} + m_Name: + m_EditorClassIdentifier: + itemId: 2 + indentLevel: 0 + targetFlowchart: {fileID: 0} + targetBlock: {fileID: 2121984973} + startLabel: + stringRef: {fileID: 0} + stringVal: LabelB + startIndex: 0 + callMode: 0 +--- !u!114 &2121984973 +MonoBehaviour: + m_ObjectHideFlags: 2 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2121984965} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3d3d73aef2cfc4f51abf34ac00241f60, type: 3} + m_Name: + m_EditorClassIdentifier: + nodeRect: + serializedVersion: 2 + x: 258 + y: 69 + width: 120 + height: 40 + tint: {r: 1, g: 1, b: 1, a: 1} + useCustomTint: 0 + itemId: 1 + blockName: CallTarget + description: + eventHandler: {fileID: 0} + commandList: + - {fileID: 2121984971} + - {fileID: 2121984969} + - {fileID: 2121984967} + - {fileID: 2121984970} + - {fileID: 2121984968} +--- !u!114 &2121984974 +MonoBehaviour: + m_ObjectHideFlags: 2 + m_PrefabParentObject: {fileID: 11462346, guid: 5e7fbc8d4eb714b279eeeef2262c1e1a, + type: 2} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2121984965} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d2f6487d21a03404cb21b245f0242e79, type: 3} + m_Name: + m_EditorClassIdentifier: + parentBlock: {fileID: 2121984975} + waitForFrames: 1 +--- !u!114 &2121984975 +MonoBehaviour: + m_ObjectHideFlags: 2 + m_PrefabParentObject: {fileID: 11433304, guid: 5e7fbc8d4eb714b279eeeef2262c1e1a, + type: 2} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2121984965} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3d3d73aef2cfc4f51abf34ac00241f60, type: 3} + m_Name: + m_EditorClassIdentifier: + nodeRect: + serializedVersion: 2 + x: 68 + y: 70 + width: 120 + height: 40 + tint: {r: 1, g: 1, b: 1, a: 1} + useCustomTint: 0 + itemId: 0 + blockName: Start + description: + eventHandler: {fileID: 2121984974} + commandList: + - {fileID: 2121984972} +--- !u!114 &2121984976 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 11430050, guid: 5e7fbc8d4eb714b279eeeef2262c1e1a, + type: 2} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2121984965} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 7a334fe2ffb574b3583ff3b18b4792d3, type: 3} + m_Name: + m_EditorClassIdentifier: + version: 1 + scrollPos: {x: 1.7744522, y: -1.1711906} + variablesScrollPos: {x: 0, y: 0} + variablesExpanded: 1 + blockViewHeight: 400 + zoom: 1 + scrollViewRect: + serializedVersion: 2 + x: -350 + y: -350 + width: 1131 + height: 869 + selectedBlocks: + - {fileID: 2121984973} + selectedCommands: + - {fileID: 2121984971} + variables: [] + description: + stepPause: 0 + colorCommands: 1 + hideComponents: 1 + saveSelection: 1 + localizationId: + showLineNumbers: 0 + hideCommands: [] + luaEnvironment: {fileID: 0} + luaBindingName: flowchart