diff --git a/Assets/Fungus/Flowchart/Scripts/Commands/SendMessage.cs b/Assets/Fungus/Flowchart/Scripts/Commands/SendMessage.cs index 976db87f..cbb8e0fb 100644 --- a/Assets/Fungus/Flowchart/Scripts/Commands/SendMessage.cs +++ b/Assets/Fungus/Flowchart/Scripts/Commands/SendMessage.cs @@ -1,4 +1,5 @@ using UnityEngine; +using UnityEngine.Serialization; using System.Collections; namespace Fungus @@ -7,8 +8,12 @@ namespace Fungus "Send Message", "Sends a message to either the owner Flowchart or all Flowcharts in the scene. Blocks can listen for this message using a Message Received event handler.")] [AddComponentMenu("")] - public class SendMessage : Command + public class SendMessage : Command, ISerializationCallbackReceiver { + #region Obsolete Properties + [HideInInspector] [FormerlySerializedAs("message")] public string messageOLD; + #endregion + public enum MessageTarget { SameFlowchart, @@ -19,11 +24,11 @@ namespace Fungus public MessageTarget messageTarget; [Tooltip("Name of the message to send")] - public string message = ""; + public StringData _message = new StringData(""); public override void OnEnter() { - if (message.Length == 0) + if (_message.Value.Length == 0) { Continue(); return; @@ -45,7 +50,7 @@ namespace Fungus { foreach (MessageReceived receiver in receivers) { - receiver.OnSendFungusMessage(message); + receiver.OnSendFungusMessage(_message); } } @@ -54,18 +59,34 @@ namespace Fungus public override string GetSummary() { - if (message.Length == 0) + if (_message.Value.Length == 0) { return "Error: No message specified"; } - return message; + return _message; } public override Color GetButtonColor() { return new Color32(235, 191, 217, 255); } + + // + // ISerializationCallbackReceiver implementation + // + + public virtual void OnBeforeSerialize() + {} + + public virtual void OnAfterDeserialize() + { + if (messageOLD != default(string)) + { + _message.Value = messageOLD; + messageOLD = default(string); + } + } } } \ No newline at end of file