/// Plays the specified clip public void Play(AnimationClip anim, float speed = 1) { if (anim == null) { return; } if (m_animator.enabled == false) { m_animator.enabled = true; } // Reset animation nodes if (m_nodes != null) { m_nodes.Reset(); } #if UNITY_5_6_OR_NEWER m_clipPairList[0] = new KeyValuePair <AnimationClip, AnimationClip>(m_clipPairList[0].Key, anim); m_controller.ApplyOverrides(m_clipPairList); #else m_clipPairArray[0].overrideClip = anim; m_controller.clips = m_clipPairArray; #endif m_animator.Update(0.0f); // Update so that new clip state is reset before hitting play m_animator.Play(STATE_NAME_HASH, 0, 0); m_speed = Mathf.Max(0, speed); m_animator.speed = m_speed; m_currAnim = anim; m_animator.Update(0.0f); // Update so that normalized time is updated immediately }
/// Plays the specified clip public void Play(AnimationClip anim, float speed = 1, float time = 0, bool force = false) { if (anim == null) return; if (m_animator.enabled == false) m_animator.enabled = true; m_speed = Mathf.Max(0, speed); m_animator.speed = m_speed; if (force == false && IsPlaying(anim)) return; // Reset animation nodes so any curves are if (m_nodes != null) m_nodes.Reset(); #if UNITY_5_6_OR_NEWER m_clipPairList[0] = new KeyValuePair<AnimationClip, AnimationClip>(m_clipPairList[0].Key, anim); m_controller.ApplyOverrides(m_clipPairList); #else m_clipPairArray[0].overrideClip = anim; m_controller.clips = m_clipPairArray; #endif m_animator.Update(0.0f); // Update so that new clip state is reset before hitting play m_animator.Play(STATE_NAME, 0, time); // m_speed = Mathf.Max(0,speed); // m_animator.speed = m_speed; m_currAnim = anim; m_animator.Update(0.0f); // Update so that normalized time is updated immediately }