You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.7 KiB
92 lines
2.7 KiB
9 years ago
|
// 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)
|
||
9 years ago
|
|
||
10 years ago
|
using UnityEngine;
|
||
9 years ago
|
using UnityEngine.Serialization;
|
||
10 years ago
|
|
||
|
namespace Fungus
|
||
|
{
|
||
9 years ago
|
/// <summary>
|
||
|
/// 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.
|
||
|
/// </summary>
|
||
9 years ago
|
[CommandInfo("Flow",
|
||
|
"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("")]
|
||
|
[ExecuteInEditMode]
|
||
|
public class SendMessage : Command
|
||
|
{
|
||
|
public enum MessageTarget
|
||
|
{
|
||
|
SameFlowchart,
|
||
|
AllFlowcharts
|
||
|
}
|
||
10 years ago
|
|
||
9 years ago
|
[Tooltip("Target flowchart(s) to send the message to")]
|
||
9 years ago
|
[SerializeField] protected MessageTarget messageTarget;
|
||
10 years ago
|
|
||
9 years ago
|
[Tooltip("Name of the message to send")]
|
||
9 years ago
|
[SerializeField] protected StringData _message = new StringData("");
|
||
10 years ago
|
|
||
9 years ago
|
public override void OnEnter()
|
||
|
{
|
||
|
if (_message.Value.Length == 0)
|
||
|
{
|
||
|
Continue();
|
||
|
return;
|
||
|
}
|
||
10 years ago
|
|
||
9 years ago
|
Flowchart flowchart = GetFlowchart();
|
||
10 years ago
|
|
||
9 years ago
|
MessageReceived[] receivers = null;
|
||
|
if (messageTarget == MessageTarget.SameFlowchart)
|
||
|
{
|
||
|
receivers = flowchart.GetComponents<MessageReceived>();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
receivers = GameObject.FindObjectsOfType<MessageReceived>();
|
||
|
}
|
||
10 years ago
|
|
||
9 years ago
|
if (receivers != null)
|
||
|
{
|
||
|
foreach (MessageReceived receiver in receivers)
|
||
|
{
|
||
|
receiver.OnSendFungusMessage(_message.Value);
|
||
|
}
|
||
|
}
|
||
10 years ago
|
|
||
9 years ago
|
Continue();
|
||
|
}
|
||
10 years ago
|
|
||
9 years ago
|
public override string GetSummary()
|
||
|
{
|
||
|
if (_message.Value.Length == 0)
|
||
|
{
|
||
|
return "Error: No message specified";
|
||
|
}
|
||
|
|
||
|
return _message.Value;
|
||
|
}
|
||
|
|
||
|
public override Color GetButtonColor()
|
||
|
{
|
||
|
return new Color32(235, 191, 217, 255);
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
#region Backwards compatibility
|
||
9 years ago
|
|
||
9 years ago
|
[HideInInspector] [FormerlySerializedAs("message")] public string messageOLD = "";
|
||
9 years ago
|
|
||
9 years ago
|
protected virtual void OnEnable()
|
||
|
{
|
||
|
if (messageOLD != "")
|
||
|
{
|
||
|
_message.Value = messageOLD;
|
||
|
messageOLD = "";
|
||
|
}
|
||
|
}
|
||
9 years ago
|
|
||
9 years ago
|
#endregion
|
||
|
}
|
||
10 years ago
|
}
|