using System;
using UnityEngine;
namespace Assets.HeroEditor4D.Common.Scripts.CharacterScripts
{
	/// 
	/// Animation events. If you want to get animation callback, use it.
	/// For example, if you want to know exact hit moment for attack animation, use custom event 'Hit' that is fired in most attack animations.
	/// 
	public class AnimationEvents : MonoBehaviour
    {
		/// 
		/// Subscribe it to get animation callback.
		/// 
		public event Action OnEvent = s => { };
        /// 
        /// Set trigger.
        /// 
        public void SetTrigger(string triggerName)
        {
            GetComponent().SetTrigger(triggerName);
        }
        /// 
        /// Set bool param, usage example: Idle=false
        /// 
        public void SetBool(string value)
        {
            var parts = value.Split('=');
            GetComponent().SetBool(parts[0], bool.Parse(parts[1]));
        }
		/// 
		/// Set integer param, usage example: WeaponType=2
		/// 
		public void SetInteger(string value)
        {
            var parts = value.Split('=');
            GetComponent().SetInteger(parts[0], int.Parse(parts[1]));
        }
	    /// 
	    /// Called from animation.
	    /// 
	    public void CustomEvent(string eventName)
	    {
		    OnEvent(eventName);
	    }
	    /// 
	    /// Set characters' expression. Called from animation.
	    /// 
		public void SetExpression(string expression)
	    {
		    GetComponent().Parts.ForEach(i => i.SetExpression(expression));
		}
	}
}