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.
67 lines
1.3 KiB
67 lines
1.3 KiB
10 years ago
|
using UnityEngine;
|
||
10 years ago
|
using System.Collections;
|
||
|
|
||
|
namespace Fungus
|
||
|
{
|
||
|
[CommandInfo("Scripting",
|
||
|
"Send Message",
|
||
10 years ago
|
"Sends a message to either the owner Flowchart or all Flowcharts in the scene. Blocks can listen for this message to start execution.")]
|
||
10 years ago
|
[AddComponentMenu("")]
|
||
10 years ago
|
public class SendMessage : Command
|
||
|
{
|
||
|
public enum MessageTarget
|
||
|
{
|
||
10 years ago
|
SameFlowchart,
|
||
|
AllFlowcharts
|
||
10 years ago
|
}
|
||
|
|
||
|
public MessageTarget messageTarget;
|
||
10 years ago
|
public string message = "";
|
||
10 years ago
|
|
||
|
public override void OnEnter()
|
||
|
{
|
||
|
if (message.Length == 0)
|
||
|
{
|
||
|
Continue();
|
||
|
}
|
||
|
|
||
10 years ago
|
Flowchart flowchart = GetFlowchart();
|
||
10 years ago
|
|
||
10 years ago
|
MessageReceived[] receivers = null;
|
||
10 years ago
|
if (messageTarget == MessageTarget.SameFlowchart)
|
||
10 years ago
|
{
|
||
10 years ago
|
receivers = flowchart.GetComponentsInChildren<MessageReceived>();
|
||
10 years ago
|
}
|
||
|
else
|
||
|
{
|
||
10 years ago
|
receivers = GameObject.FindObjectsOfType<MessageReceived>();
|
||
10 years ago
|
}
|
||
|
|
||
|
if (receivers != null)
|
||
|
{
|
||
10 years ago
|
foreach (MessageReceived receiver in receivers)
|
||
10 years ago
|
{
|
||
|
receiver.OnSendFungusMessage(message);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Continue();
|
||
|
}
|
||
|
|
||
|
public override string GetSummary()
|
||
|
{
|
||
|
if (message.Length == 0)
|
||
|
{
|
||
|
return "Error: No message specified";
|
||
|
}
|
||
|
|
||
|
return message;
|
||
|
}
|
||
|
|
||
|
public override Color GetButtonColor()
|
||
|
{
|
||
|
return new Color32(235, 191, 217, 255);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|