private static void CreateAnimationClips(int animationId) { FightAnimation animationDef = DefinitionStore.Instance.GetFightAnimation(animationId); CreateAnimationClip(animationId, AnimationType.Idle, animationDef.IdleFrameCount); CreateAnimationClip(animationId, AnimationType.Attack, animationDef.AttackFrameCount); if (animationDef.HasSkillAnimation) { CreateAnimationClip(animationId, AnimationType.Skill, animationDef.SkillFrameCount); } }
void Start() { Debug.Log("FightAniEvent Start."); // Invoke("TestChangeAnimation", 1.5f); animator = this.gameObject.GetComponent <Animator>(); if (animator == null) { throw new MissingComponentException("animator is missing"); } /// var clip = UnityEditor.Animations.AnimationClip.CreateAnimatorControllerAtPath("Assets/Resources/Fights/001/auto001.controller"); FightAnimation fightAnimation = DefinitionStore.Instance.GetFightAnimation(animationId); AnimationClip idleClip = animator.runtimeAnimatorController.animationClips[0]; idleClip.wrapMode = WrapMode.Loop; AnimationClip attackClip = animator.runtimeAnimatorController.animationClips[1]; foreach (int frame in fightAnimation.AttackPercentageByFrame.Keys) { int percentage = fightAnimation.AttackPercentageByFrame[frame]; if (percentage < 0 || percentage > 100) { continue; } AnimationEvent evt = new AnimationEvent(); evt.intParameter = percentage; evt.time = 0.15f * frame; evt.functionName = "OnAttackHitting"; attackClip.AddEvent(evt); } AnimationEvent evt2 = new AnimationEvent(); evt2.time = attackClip.length; evt2.functionName = "OnAttackComplete"; attackClip.AddEvent(evt2); }