From 2f97ab7ff6589baf31a6ef469e548109e3abf78e Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Tue, 31 Mar 2015 17:46:15 +0100 Subject: [PATCH] Added itemId to Blocks --- .../Flowchart/Resources/Flowchart.prefab | 42 ++++++++++++------- Assets/Fungus/Flowchart/Scripts/Block.cs | 3 ++ Assets/Fungus/Flowchart/Scripts/Flowchart.cs | 15 ++++++- 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/Assets/Fungus/Flowchart/Resources/Flowchart.prefab b/Assets/Fungus/Flowchart/Resources/Flowchart.prefab index a81ed6c0..bab4a9e4 100644 --- a/Assets/Fungus/Flowchart/Resources/Flowchart.prefab +++ b/Assets/Fungus/Flowchart/Resources/Flowchart.prefab @@ -9,8 +9,9 @@ GameObject: m_Component: - 4: {fileID: 467082} - 114: {fileID: 11430050} - - 114: {fileID: 11467182} - 114: {fileID: 11417010} + - 114: {fileID: 11433304} + - 114: {fileID: 11462346} m_Layer: 0 m_Name: Flowchart m_TagString: Untagged @@ -41,7 +42,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: d2f6487d21a03404cb21b245f0242e79, type: 3} m_Name: m_EditorClassIdentifier: - parentSequence: {fileID: 11467182} + parentBlock: {fileID: 0} --- !u!114 &11430050 MonoBehaviour: m_ObjectHideFlags: 1 @@ -56,15 +57,15 @@ MonoBehaviour: scrollPos: {x: 0, y: 0} variablesScrollPos: {x: 0, y: 0} variablesExpanded: 1 - sequenceViewHeight: 400 + blockViewHeight: 400 zoom: 1 scrollViewRect: serializedVersion: 2 - x: -340 + x: -343 y: -340 - width: 926 - height: 840 - selectedSequence: {fileID: 0} + width: 1114 + height: 859 + selectedBlock: {fileID: 11433304} selectedCommands: [] variables: [] description: @@ -72,8 +73,8 @@ MonoBehaviour: colorCommands: 1 hideComponents: 1 saveSelection: 1 - nextCommandId: 0 ---- !u!114 &11467182 + nextItemId: 1 +--- !u!114 &11433304 MonoBehaviour: m_ObjectHideFlags: 1 m_PrefabParentObject: {fileID: 0} @@ -86,15 +87,28 @@ MonoBehaviour: m_EditorClassIdentifier: nodeRect: serializedVersion: 2 - x: 60 - y: 60 - width: 126 + x: 67 + y: 69 + width: 120 height: 40 - sequenceName: New Sequence + itemId: 0 + blockName: New Block description: runSlowInEditor: 1 - eventHandler: {fileID: 11417010} + eventHandler: {fileID: 11462346} commandList: [] +--- !u!114 &11462346 +MonoBehaviour: + m_ObjectHideFlags: 1 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 100100000} + m_GameObject: {fileID: 142980} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d2f6487d21a03404cb21b245f0242e79, type: 3} + m_Name: + m_EditorClassIdentifier: + parentBlock: {fileID: 11433304} --- !u!1001 &100100000 Prefab: m_ObjectHideFlags: 1 diff --git a/Assets/Fungus/Flowchart/Scripts/Block.cs b/Assets/Fungus/Flowchart/Scripts/Block.cs index 021e1fec..0c3d316e 100644 --- a/Assets/Fungus/Flowchart/Scripts/Block.cs +++ b/Assets/Fungus/Flowchart/Scripts/Block.cs @@ -21,6 +21,9 @@ namespace Fungus [AddComponentMenu("")] public class Block : Node { + [HideInInspector] + public int itemId = -1; // Invalid flowchart item id + [FormerlySerializedAs("sequenceName")] public string blockName = "New Block"; diff --git a/Assets/Fungus/Flowchart/Scripts/Flowchart.cs b/Assets/Fungus/Flowchart/Scripts/Flowchart.cs index e441484a..efd3bb55 100644 --- a/Assets/Fungus/Flowchart/Scripts/Flowchart.cs +++ b/Assets/Fungus/Flowchart/Scripts/Flowchart.cs @@ -129,10 +129,19 @@ namespace Fungus public virtual void OnEnable() { - // Assign an item id to any command that doesn't have one yet. + // Assign an item id to any block or command that doesn't have one yet. // This should only happen after loading a legacy Flowchart + Block[] blocks = GetComponentsInChildren(); + foreach (Block block in blocks) + { + if (block.itemId == -1) + { + block.itemId = NextItemId(); + } + } + Command[] commands = GetComponentsInChildren(); - foreach (Command command in commands) + foreach (Command command in commands) { if (command.itemId == -1) { @@ -156,6 +165,8 @@ namespace Fungus b.nodeRect.x = position.x; b.nodeRect.y = position.y; b.blockName = GetUniqueBlockKey(b.blockName, b); + b.itemId = NextItemId(); + return b; }