From 4fbd677820a56afb89a381436203eadcadf1f700 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Sat, 19 Mar 2016 02:27:14 -0700 Subject: [PATCH] Wait command can use a variable --- .../Fungus/Flowchart/Scripts/Commands/Wait.cs | 30 +++++++++++++++---- Assets/UpdatePropTest.unity | 19 +++++++++++- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/Assets/Fungus/Flowchart/Scripts/Commands/Wait.cs b/Assets/Fungus/Flowchart/Scripts/Commands/Wait.cs index 35989a7b..6b906e46 100644 --- a/Assets/Fungus/Flowchart/Scripts/Commands/Wait.cs +++ b/Assets/Fungus/Flowchart/Scripts/Commands/Wait.cs @@ -1,4 +1,5 @@ using UnityEngine; +using UnityEngine.Serialization; using System; using System.Collections; @@ -7,16 +8,19 @@ namespace Fungus [CommandInfo("Flow", "Wait", "Waits for period of time before executing the next command in the block.")] - [AddComponentMenu("")] - public class Wait : Command + public class Wait : Command, ISerializationCallbackReceiver { + #region Obsolete Properties + [HideInInspector] [FormerlySerializedAs("duration")] public float durationOLD; + #endregion + [Tooltip("Duration to wait for")] - public float duration = 1; + public FloatData _duration = new FloatData(1); public override void OnEnter() { - Invoke ("OnWaitComplete", duration); + Invoke ("OnWaitComplete", _duration.Value); } void OnWaitComplete() @@ -26,13 +30,29 @@ namespace Fungus public override string GetSummary() { - return duration.ToString() + " seconds"; + return _duration.Value.ToString() + " seconds"; } public override Color GetButtonColor() { return new Color32(235, 191, 217, 255); } + + // + // ISerializationCallbackReceiver implementation + // + + public virtual void OnBeforeSerialize() + {} + + public virtual void OnAfterDeserialize() + { + if (durationOLD != default(float)) + { + _duration.Value = durationOLD; + durationOLD = default(float); + } + } } } \ No newline at end of file diff --git a/Assets/UpdatePropTest.unity b/Assets/UpdatePropTest.unity index e2fda5f3..ab3c9b74 100644 --- a/Assets/UpdatePropTest.unity +++ b/Assets/UpdatePropTest.unity @@ -310,6 +310,7 @@ GameObject: - 114: {fileID: 979963254} - 114: {fileID: 979963253} - 114: {fileID: 979963256} + - 114: {fileID: 979963257} m_Layer: 0 m_Name: Flowchart m_TagString: Untagged @@ -343,7 +344,7 @@ MonoBehaviour: height: 859 selectedBlock: {fileID: 979963241} selectedCommands: - - {fileID: 979963256} + - {fileID: 979963257} variables: - {fileID: 979963244} - {fileID: 979963252} @@ -414,6 +415,7 @@ MonoBehaviour: - {fileID: 979963254} - {fileID: 979963253} - {fileID: 979963256} + - {fileID: 979963257} --- !u!114 &979963242 MonoBehaviour: m_ObjectHideFlags: 2 @@ -705,6 +707,21 @@ MonoBehaviour: _spawnRotation: vector3Ref: {fileID: 0} vector3Val: {x: 3, y: 2, z: 4} +--- !u!114 &979963257 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 979963238} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3315ad2ebb85443909a1203d56d9344e, type: 3} + m_Name: + m_EditorClassIdentifier: + itemId: 13 + errorMessage: + indentLevel: 0 + duration: 5 --- !u!1 &1197120973 GameObject: m_ObjectHideFlags: 0