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.
74 lines
2.3 KiB
74 lines
2.3 KiB
8 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;
|
||
|
|
||
|
namespace Fungus
|
||
|
{
|
||
8 years ago
|
/// <summary>
|
||
|
/// Calls a named method on a GameObject using the GameObject.SendMessage() system.
|
||
|
/// This command is called "Call Method" because a) it's more descriptive than Send Message and we're already have
|
||
|
/// a Send Message command for sending messages to trigger block execution.
|
||
|
/// </summary>
|
||
8 years ago
|
[CommandInfo("Scripting",
|
||
|
"Call Method",
|
||
|
"Calls a named method on a GameObject using the GameObject.SendMessage() system.")]
|
||
|
[AddComponentMenu("")]
|
||
|
public class CallMethod : Command
|
||
|
{
|
||
|
[Tooltip("Target monobehavior which contains the method we want to call")]
|
||
8 years ago
|
[SerializeField] protected GameObject targetObject;
|
||
10 years ago
|
|
||
8 years ago
|
[Tooltip("Name of the method to call")]
|
||
8 years ago
|
[SerializeField] protected string methodName = "";
|
||
10 years ago
|
|
||
8 years ago
|
[Tooltip("Delay (in seconds) before the method will be called")]
|
||
8 years ago
|
[SerializeField] protected float delay;
|
||
10 years ago
|
|
||
8 years ago
|
public override void OnEnter()
|
||
|
{
|
||
|
if (targetObject == null ||
|
||
|
methodName.Length == 0)
|
||
|
{
|
||
|
Continue();
|
||
|
return;
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
if (delay == 0f)
|
||
|
{
|
||
|
CallTheMethod();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Invoke("CallTheMethod", delay);
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
Continue();
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
protected virtual void CallTheMethod()
|
||
|
{
|
||
|
targetObject.SendMessage(methodName, SendMessageOptions.DontRequireReceiver);
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
public override string GetSummary()
|
||
|
{
|
||
|
if (targetObject == null)
|
||
|
{
|
||
|
return "Error: No target GameObject specified";
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
if (methodName.Length == 0)
|
||
|
{
|
||
|
return "Error: No named method specified";
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
return targetObject.name + " : " + methodName;
|
||
|
}
|
||
|
|
||
|
public override Color GetButtonColor()
|
||
|
{
|
||
|
return new Color32(235, 191, 217, 255);
|
||
|
}
|
||
|
}
|
||
10 years ago
|
}
|