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.
66 lines
1.2 KiB
66 lines
1.2 KiB
10 years ago
|
using UnityEngine;
|
||
|
using System.Collections;
|
||
|
|
||
|
namespace Fungus
|
||
|
{
|
||
|
[CommandInfo("Scripting",
|
||
|
"Send Message",
|
||
|
"Sends a message to either the owner Fungus Script or all Fungus Scripts in the scene. Sequences can listen for this message to start execution.")]
|
||
|
public class SendMessage : Command
|
||
|
{
|
||
|
public enum MessageTarget
|
||
|
{
|
||
|
SameScript,
|
||
|
AllScripts
|
||
|
}
|
||
|
|
||
|
public MessageTarget messageTarget;
|
||
|
public string message;
|
||
|
|
||
|
public override void OnEnter()
|
||
|
{
|
||
|
if (message.Length == 0)
|
||
|
{
|
||
|
Continue();
|
||
|
}
|
||
|
|
||
|
FungusScript fungusScript = GetFungusScript();
|
||
|
|
||
10 years ago
|
MessageReceived[] receivers = null;
|
||
10 years ago
|
if (messageTarget == MessageTarget.SameScript)
|
||
|
{
|
||
10 years ago
|
receivers = fungusScript.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);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|