using System;
using System.Collections.Generic;
using UnityEngine;
namespace coa4u
{
///
/// Sends the message to the current target. First, it checks the Actor's methods cache.
/// If the receiving method found in cache, it will be called directly without passing the message to the GameObject.
/// If there's no listener in cache, message will be sent GameObject (and Unity does it VERY slow).
///
class ActionSendMessage : ActionInstant
{
protected string message;
protected object param;
protected SendMessageOptions options = SendMessageOptions.DontRequireReceiver;
public ActionSendMessage(string tgtMessage)
: base()
{
message = tgtMessage;
}
public ActionSendMessage(string tgtMessage, object tgtParam)
: base()
{
message = tgtMessage;
param = tgtParam;
}
public ActionSendMessage(string tgtMessage, object tgtParam, SendMessageOptions tgtOptions)
: base()
{
message = tgtMessage;
param = tgtParam;
options = tgtOptions;
}
///
/// Returns a copy of the action.
///
public override ActionInstant clone()
{
return new ActionSendMessage(message, param, options);
}
///
/// Returns the reversed version of the action, if it is possible.
///
public override ActionInstant reverse()
{
return new ActionSendMessage(message, param, options);
}
///
/// This method is called at the action start.
///
public override void start()
{
base.start();
if (param != null)
{
target.ReceiveMessage(message, param, options);
}
else
{
target.ReceiveMessage(message, options);
}
}
}
}