From 3dc0be1b62babab88ce987e29077ec63cf4f52f2 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 1 Jul 2016 08:13:12 +0100 Subject: [PATCH] Fixed jump command properties incorrect when block duplicated #504 --- Assets/Fungus/Flowchart/Editor/JumpEditor.cs | 40 --- .../Flowchart/Editor/JumpEditor.cs.meta | 8 - .../Fungus/Flowchart/Scripts/Commands/Jump.cs | 39 ++- Assets/Tests/Flow/FlowTests.unity | 228 +++++++++++++++++- 4 files changed, 255 insertions(+), 60 deletions(-) delete mode 100644 Assets/Fungus/Flowchart/Editor/JumpEditor.cs delete mode 100644 Assets/Fungus/Flowchart/Editor/JumpEditor.cs.meta diff --git a/Assets/Fungus/Flowchart/Editor/JumpEditor.cs b/Assets/Fungus/Flowchart/Editor/JumpEditor.cs deleted file mode 100644 index 82c3e672..00000000 --- a/Assets/Fungus/Flowchart/Editor/JumpEditor.cs +++ /dev/null @@ -1,40 +0,0 @@ -/** - * 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 UnityEditor; -using UnityEngine; -using System.Collections; -using System.Collections.Generic; - -namespace Fungus -{ - [CustomEditor (typeof(Jump))] - public class JumpEditor : CommandEditor - { - protected SerializedProperty targetLabelProp; - - protected virtual void OnEnable() - { - if (NullTargetCheck()) // Check for an orphaned editor instance - return; - - targetLabelProp = serializedObject.FindProperty("targetLabel"); - } - - public override void DrawCommandGUI() - { - serializedObject.Update(); - - Jump t = target as Jump; - - LabelEditor.LabelField(targetLabelProp, - new GUIContent("Target Label", "Label to jump to"), - t.parentBlock); - - serializedObject.ApplyModifiedProperties(); - } - } - -} diff --git a/Assets/Fungus/Flowchart/Editor/JumpEditor.cs.meta b/Assets/Fungus/Flowchart/Editor/JumpEditor.cs.meta deleted file mode 100644 index 1f64861f..00000000 --- a/Assets/Fungus/Flowchart/Editor/JumpEditor.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: c1fd0ccd416054df994af1949fa6fce3 -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/Assets/Fungus/Flowchart/Scripts/Commands/Jump.cs b/Assets/Fungus/Flowchart/Scripts/Commands/Jump.cs index 608c9704..cd42a533 100644 --- a/Assets/Fungus/Flowchart/Scripts/Commands/Jump.cs +++ b/Assets/Fungus/Flowchart/Scripts/Commands/Jump.cs @@ -4,23 +4,23 @@ */ using UnityEngine; -using System.Collections; -using System.Collections.Generic; +using UnityEngine.Serialization; namespace Fungus { [CommandInfo("Flow", "Jump", - "Move execution to a specific Label command")] + "Move execution to a specific Label command in the same block")] [AddComponentMenu("")] + [ExecuteInEditMode] public class Jump : Command { - [Tooltip("Label to jump to")] - public Label targetLabel; + [Tooltip("Name of a label in this block to jump to")] + public StringData _targetLabel = new StringData(""); public override void OnEnter() { - if (targetLabel == null) + if (_targetLabel.Value == "") { Continue(); return; @@ -30,28 +30,47 @@ namespace Fungus { Label label = command as Label; if (label != null && - label == targetLabel) + label.key == _targetLabel.Value) { Continue(label.commandIndex + 1); - break; + return; } } + + // Label not found + Debug.LogWarning("Label not found: " + _targetLabel.Value); + Continue(); } public override string GetSummary() { - if (targetLabel == null) + if (_targetLabel.Value == "") { return "Error: No label selected"; } - return targetLabel.key; + return _targetLabel.Value; } public override Color GetButtonColor() { return new Color32(253, 253, 150, 255); } + + #region Backwards compatibility + + [HideInInspector] [FormerlySerializedAs("targetLabel")] public Label targetLabelOLD; + + protected virtual void OnEnable() + { + if (targetLabelOLD != null) + { + _targetLabel.Value = targetLabelOLD.key; + targetLabelOLD = null; + } + } + + #endregion } } \ No newline at end of file diff --git a/Assets/Tests/Flow/FlowTests.unity b/Assets/Tests/Flow/FlowTests.unity index 0ca9beef..68a7c6ac 100644 --- a/Assets/Tests/Flow/FlowTests.unity +++ b/Assets/Tests/Flow/FlowTests.unity @@ -229,6 +229,57 @@ RectTransform: m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0, y: 0} +--- !u!1 &730370420 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 730370422} + - 114: {fileID: 730370421} + m_Layer: 0 + m_Name: JumpTest + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &730370421 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 730370420} + 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 &730370422 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 730370420} + 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: 1253352148} + m_Father: {fileID: 0} + m_RootOrder: 6 --- !u!1 &765506376 GameObject: m_ObjectHideFlags: 0 @@ -715,6 +766,178 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_RootOrder: 0 +--- !u!1 &1253352147 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 142980, guid: 5e7fbc8d4eb714b279eeeef2262c1e1a, type: 2} + m_PrefabInternal: {fileID: 0} + serializedVersion: 4 + m_Component: + - 4: {fileID: 1253352148} + - 114: {fileID: 1253352155} + - 114: {fileID: 1253352154} + - 114: {fileID: 1253352153} + - 114: {fileID: 1253352152} + - 114: {fileID: 1253352151} + - 114: {fileID: 1253352150} + - 114: {fileID: 1253352149} + m_Layer: 0 + m_Name: Flowchart + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1253352148 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 467082, guid: 5e7fbc8d4eb714b279eeeef2262c1e1a, type: 2} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1253352147} + 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: 730370422} + m_RootOrder: 0 +--- !u!114 &1253352149 +MonoBehaviour: + m_ObjectHideFlags: 2 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1253352147} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4920f47cde1a84b11ad07b7317568494, type: 3} + m_Name: + m_EditorClassIdentifier: + itemId: 4 + errorMessage: + indentLevel: 0 +--- !u!114 &1253352150 +MonoBehaviour: + m_ObjectHideFlags: 2 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1253352147} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 2dcb71131f45b47fead560a97ef55f1c, type: 3} + m_Name: + m_EditorClassIdentifier: + itemId: 3 + errorMessage: + indentLevel: 0 + failMessage: +--- !u!114 &1253352151 +MonoBehaviour: + m_ObjectHideFlags: 2 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1253352147} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: ea4da378c47144a86979765ac5e9690c, type: 3} + m_Name: + m_EditorClassIdentifier: + itemId: 2 + errorMessage: + indentLevel: 0 + key: MyLabel +--- !u!114 &1253352152 +MonoBehaviour: + m_ObjectHideFlags: 2 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1253352147} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: ae9ac2fcbd1d542619ab0bc7549fb264, type: 3} + m_Name: + m_EditorClassIdentifier: + itemId: 1 + errorMessage: + indentLevel: 0 + _targetLabel: + stringRef: {fileID: 0} + stringVal: MyLabel + targetLabelOLD: {fileID: 0} +--- !u!114 &1253352153 +MonoBehaviour: + m_ObjectHideFlags: 2 + m_PrefabParentObject: {fileID: 11462346, guid: 5e7fbc8d4eb714b279eeeef2262c1e1a, + type: 2} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1253352147} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d2f6487d21a03404cb21b245f0242e79, type: 3} + m_Name: + m_EditorClassIdentifier: + parentBlock: {fileID: 1253352154} +--- !u!114 &1253352154 +MonoBehaviour: + m_ObjectHideFlags: 2 + m_PrefabParentObject: {fileID: 11433304, guid: 5e7fbc8d4eb714b279eeeef2262c1e1a, + type: 2} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1253352147} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3d3d73aef2cfc4f51abf34ac00241f60, type: 3} + m_Name: + m_EditorClassIdentifier: + nodeRect: + serializedVersion: 2 + x: 67 + y: 70 + width: 120 + height: 40 + itemId: 0 + blockName: Start + description: + eventHandler: {fileID: 1253352153} + commandList: + - {fileID: 1253352152} + - {fileID: 1253352150} + - {fileID: 1253352151} + - {fileID: 1253352149} +--- !u!114 &1253352155 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 11430050, guid: 5e7fbc8d4eb714b279eeeef2262c1e1a, + type: 2} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1253352147} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 7a334fe2ffb574b3583ff3b18b4792d3, type: 3} + m_Name: + m_EditorClassIdentifier: + version: 1 + scrollPos: {x: 0, y: 0} + variablesScrollPos: {x: 0, y: 0} + variablesExpanded: 1 + blockViewHeight: 400 + zoom: 1 + scrollViewRect: + serializedVersion: 2 + x: -343 + y: -340 + width: 1114 + height: 859 + selectedBlock: {fileID: 0} + selectedCommands: [] + variables: [] + description: Tests if jumping to a label works correctly + stepPause: 0 + colorCommands: 1 + hideComponents: 1 + saveSelection: 1 + localizationId: + showLineNumbers: 0 + hideCommands: [] --- !u!1 &1501994597 GameObject: m_ObjectHideFlags: 0 @@ -1003,6 +1226,7 @@ MonoBehaviour: - key: button obj: {fileID: 1501994597} component: {fileID: 1501994599} + showInherited: 0 --- !u!114 &1601427685 MonoBehaviour: m_ObjectHideFlags: 0 @@ -1069,7 +1293,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 61dddfdc5e0e44ca298d8f46f7f5a915, type: 3} m_Name: m_EditorClassIdentifier: - selectedFlowchart: {fileID: 1040991512} + selectedFlowchart: {fileID: 1253352155} --- !u!4 &1873336851 Transform: m_ObjectHideFlags: 1 @@ -1098,7 +1322,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!114 &1923342101 MonoBehaviour: m_ObjectHideFlags: 0