/// <summary> /// Add amimation clip index to pending animation list, will be played one by one. /// </summary> /// <param name="animations">Animation clips added.</param> /// <param name="audios">If not null, audio clips will be played with animation in samoe order.</param> /// <param name="queued">If true, new animations will be played after current animations.</param> public void AddAnimations(int[] animations, int[] audios = null, bool queued = true) { if (!queued) { CleanPendingAnimations(); } if (currentAnimationList.Count > 0) { // Set last animation end blending time if existed. currentAnimationList[currentAnimationList.Count - 1].SetEndBlendingTime(); } for (int index = 0; index < animations.Length; index++) { int animationIndex = animations[index]; int audioIndex = -1; if (audios != null && index < audios.Length) { audioIndex = audios[index]; } AnimationComponent component = new AnimationComponent( animationMixer, audioMixer, animationIndex, audioIndex); if (currentAnimationList.Count > 0) { // Set animation start blending time. component.SetStartBlendingTime(); } if (index < animations.Length - 1) { // Set animation end blending time. component.SetEndBlendingTime(); } currentAnimationList.Add(component); } }
/// <summary> /// Update is called once per frame /// </summary> private void Update() { if (animationMixer.GetInputCount() == 0 || currentAnimationList.Count == 0) { // No valid clip input. return; } AnimationComponent firstAnimation = currentAnimationList[0]; AnimationComponent secondAnimation = null; if (currentAnimationList.Count >= 2) { secondAnimation = currentAnimationList[1]; } if (firstAnimation != null) { switch (firstAnimation.CurrentStatus) { case AnimationComponent.Status.Pending: firstAnimation.Start(); break; case AnimationComponent.Status.Processing: firstAnimation.Tick(); break; case AnimationComponent.Status.Done: if (currentAnimationList.Count == 1) { firstAnimation .SetStartBlendingTime(-1.0f) .SetEndBlendingTime(99999.0f) .Reset(); } else if (currentAnimationList.Count >= 2) { currentAnimationList.Remove(firstAnimation); } break; } // We can start blend next clip. if (firstAnimation.CanStartNextClip) { switch (secondAnimation.CurrentStatus) { case AnimationComponent.Status.Pending: secondAnimation.Start(); break; case AnimationComponent.Status.Processing: secondAnimation.Tick(); break; case AnimationComponent.Status.Done: // Impossibile break; } } } }