using UnityEngine;

// Sends a message to the remote object when an animation action occurs
// Can also fire events
// Can also trigger sounds
namespace com.deeperbeige.lib.components
{
	public class AnimationMessage : MonoBehaviour
	{
		public GameObject target;
		
		// Wire the animation event to call this with
		// the function name that you want to invoke
		// on the remote object
		// 
		// Implement a method in one of the target object's monobehaviours
		// that has either zero or one parameters. The parameter is set to
		// the gameobject that sent the message
		void Invoke(string functionName)
		{
			if (string.IsNullOrEmpty(functionName)) return;
			if (target == null)                     return;
	
			target.SendMessage(functionName, gameObject, SendMessageOptions.DontRequireReceiver);
		}
		
		// Wire the animation event to call this with the
		// event name to be fired, and it will broadcast
		// it through the Events system. No need to set
		// a target inlet connector if you are using
		// this method
		void SendEvent(string eventName)
		{
			Events.Send(eventName);
		}
		
		// Wire the animation event to call this with the
		// sound ID to be played, and it will trigger it
		// at the appropriate moment. Plays once, at a
		// default volume. You can use a group ID if you
		// want to pick a random sound from the group.
		// No need to set a target inlet connector if
		// you are using this method
		void PlaySound(string soundID)
		{
			Sounds.Play(soundID);
		}
	}
}
