44 lines
1.4 KiB
C#
44 lines
1.4 KiB
C#
using UnityEngine;
|
|
|
|
namespace Invector.vCharacterController.AI.FSMBehaviour
|
|
{
|
|
#if UNITY_EDITOR
|
|
[vFSMHelpbox("Requires a vMessageReceiver attached to your AI Controller - This will send a message to your Controller, so you can trigger custom Events", UnityEditor.MessageType.Info)]
|
|
#endif
|
|
public class vAISendMessage : vStateAction
|
|
{
|
|
public override string categoryName
|
|
{
|
|
get { return "Controller/"; }
|
|
}
|
|
public override string defaultName
|
|
{
|
|
get { return "SendMessage"; }
|
|
}
|
|
|
|
public vAISendMessage()
|
|
{
|
|
executionType = vFSMComponentExecutionType.OnStateEnter;
|
|
}
|
|
|
|
public string listenerName;
|
|
public string message;
|
|
|
|
public override void DoAction(vIFSMBehaviourController fsmBehaviour, vFSMComponentExecutionType executionType = vFSMComponentExecutionType.OnStateUpdate)
|
|
{
|
|
// Pobranie komponentu vMessageReceiver
|
|
var receiver = fsmBehaviour.gameObject.GetComponent<vMessageReceiver>();
|
|
|
|
// Jeśli komponent istnieje, wysyła wiadomość
|
|
if (receiver != null)
|
|
{
|
|
receiver.Send(listenerName, message);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogWarning($"vMessageReceiver not found on {fsmBehaviour.gameObject.name}. Cannot send message.");
|
|
}
|
|
}
|
|
}
|
|
}
|