//--------------------------------------------------------- public void StopAnim(Animation animation) { if (animation) { animation.Stop(); animation.Sample(); for (int idx = 0; idx < m_PlayingAnims.Count; ++idx) { S_AnimDscr anim = (S_AnimDscr)m_PlayingAnims[idx]; if (anim.m_Animation == animation) { ProcessAnim(anim, 1, idx); //Debug.Log("Remove anim"); if (anim.m_Widget) { anim.m_Widget.SetModify(); } m_PlayingAnims.RemoveAt(idx); return; } } } }
//--------------------------------------------------------- public void PlayAnim(Animation animation, GUIBase_Widget widget, GUIBase_Platform.AnimFinishedDelegate finishDelegate = null, int customIdx = -1) { S_AnimDscr animDscr = new S_AnimDscr(); animDscr.m_Animation = animation; animDscr.m_StartTime = Time.realtimeSinceStartup; //animDscr.m_StartTime = Time.time; animDscr.m_Length = animation.clip.length; animDscr.m_CustomIdx = customIdx; animDscr.m_AnimFinishedDelegate = finishDelegate; animDscr.m_Widget = widget; animDscr.m_Animation.wrapMode = animDscr.m_Animation.clip.wrapMode; int idx = m_PlayingAnims.Count; m_PlayingAnims.Add(animDscr); ProcessAnim(animDscr, 0.0f, idx); //Debug.Log("anim "+ animDscr.m_Animation.name +", Start time = "+ animDscr.m_StartTime +", Length = "+ animDscr.m_Length); }
//--------------------------------------------------------- void ProcessAnimations() { // Process playing animations if (m_PlayingAnims != null && m_PlayingAnims.Count > 0) { float currTime = Time.realtimeSinceStartup; //float currTime = Time.time; for (int idx = 0; idx < m_PlayingAnims.Count; ++idx) { S_AnimDscr anim = (S_AnimDscr)m_PlayingAnims[idx]; float deltaTime = currTime - anim.m_StartTime; ProcessAnim(anim, deltaTime, idx); } } // Process animations to remove if (m_AnimsToRemove != null && m_AnimsToRemove.Count > 0) { for (int idx = m_AnimsToRemove.Count - 1; idx >= 0; --idx) { S_AnimDscr anim = (S_AnimDscr)m_PlayingAnims[(int)m_AnimsToRemove[idx]]; // signalize remove of some special animation if (anim.m_CustomIdx != -1) { AnimationRemoved(anim.m_CustomIdx, anim.m_AnimFinishedDelegate); } m_PlayingAnims.RemoveAt((int)m_AnimsToRemove[idx]); } m_AnimsToRemove.RemoveRange(0, m_AnimsToRemove.Count); } }
//--------------------------------------------------------- void ProcessAnim(S_AnimDscr anim, float deltaTime, int idx) { anim.m_Animation.Play(); foreach (AnimationState state in anim.m_Animation) { state.enabled = true; state.time = deltaTime; } anim.m_Animation.Sample(); foreach (AnimationState state in anim.m_Animation) { state.enabled = false; } //Debug.Log("Delta Time = " + deltaTime); //anim.m_Animation.Stop(); //anim.m_Animation.Sample(); if ((anim.m_Animation.wrapMode == WrapMode.Once || anim.m_Animation.wrapMode == WrapMode.Default) && (deltaTime > anim.m_Length)) { //Debug.Log("anim.m_Animation = " + anim.m_Animation.name + ", Remove time = "+ Time.realtimeSinceStartup); m_AnimsToRemove.Add(idx); } // Signalize modification to widget if (anim.m_Widget) { anim.m_Widget.SetModify(); } }