using System.Collections.Generic;
using Animancer;
using Animancer.TransitionLibraries;
using Fort23.UTool;
using UnityEngine;
using Utility;

namespace GameLogic.Combat.Hero
{
    public class CombatHeroAnimtion
    {
        public AnimancerComponent AnimancerComponent;

        protected Map<string, TransitionAsset> _transitionMap = new Map<string, TransitionAsset>();

        public void Init(AnimancerComponent animancer)
        {
            AnimancerComponent = animancer;
            if (AnimancerComponent != null)
            {
                // AnimancerComponent.GetAnimationClips();
                // List<AnimationClip> results = new List<AnimationClip>();
                // AnimancerComponent.Transitions.GetAnimationClips(results);
                int max = AnimancerComponent.Transitions.Library.Count;
                for (int i = 0; i < max; i++)
                {
                    if (AnimancerComponent.Transitions.Library.TryGetTransition(i,
                            out TransitionModifierGroup transition))
                    {
                        TransitionAsset clipTransition2= transition.Transition as TransitionAsset;
                        _transitionMap[clipTransition2.name] = clipTransition2;
                    }
                }
            }
        }

        public void Play(string name, float speed = 1)
        {
            if (!_transitionMap.TryGetValue(name, out TransitionAsset clipTransition))
            {
                LogTool.Log("没有找到要播放的动画");
                return;
            }

            clipTransition.Speed = speed;
            // clipTransition. = isLoop;
            AnimancerComponent.Play(clipTransition);
        }
    }
}