public void PlayAnimation(string id, bool loop, float interpTime, float startTime = 0.0f) { if ((double)interpTime <= 0.0) { this.StopAll(); } if (!this.mLoadedAnimations.ContainsKey(id)) { DebugUtility.LogError("Unknown animation ID: " + id); } else { AnimDef mLoadedAnimation = this.mLoadedAnimations[id]; if (Object.op_Equality((Object)mLoadedAnimation, (Object)null) || Object.op_Equality((Object)mLoadedAnimation.animation, (Object)null)) { DebugUtility.LogError("Animation not loaded: " + id); } else { AnimationPlayer.AnimationStateSource animationStateSource = (AnimationPlayer.AnimationStateSource)null; for (int index = 0; index < this.mAnimationStates.Count; ++index) { if (this.mAnimationStates[index].Name == id) { animationStateSource = this.mAnimationStates[index]; break; } } if (animationStateSource == null) { animationStateSource = new AnimationPlayer.AnimationStateSource(); animationStateSource.Clip = mLoadedAnimation; this.mAnimationStates.Add(animationStateSource); } animationStateSource.Time = startTime; animationStateSource.Name = id; animationStateSource.WrapMode = !loop ? (WrapMode)0 : (WrapMode)2; if ((double)interpTime > 0.0) { animationStateSource.Weight = 0.0f; animationStateSource.DesiredWeight = 1f; animationStateSource.BlendRate = 1f / interpTime; for (int index = 0; index < this.mAnimationStates.Count; ++index) { if (this.mAnimationStates[index] != animationStateSource) { this.mAnimationStates[index].DesiredWeight = 0.0f; this.mAnimationStates[index].BlendRate = animationStateSource.BlendRate; } } } else { animationStateSource.Weight = 1f; animationStateSource.DesiredWeight = 1f; } } } }
public float GetNormalizedTime(string id) { AnimationPlayer.AnimationStateSource state = this.FindState(id); if (state == null) { return(0.0f); } return(state.Time / state.Clip.Length); }
public float GetTargetWeight(string id) { AnimationPlayer.AnimationStateSource state = this.FindState(id); if (state == null) { return(0.0f); } return(state.DesiredWeight); }
public float GetRemainingTime(string id) { AnimationPlayer.AnimationStateSource state = this.FindState(id); if (state == null || state.WrapMode == 2) { return(0.0f); } return(state.Clip.Length - state.Time); }
public void StopAnimation(string id) { AnimationPlayer.AnimationStateSource state = this.FindState(id); if (state == null) { return; } this.mAnimationStates.Remove(state); }
private void ProcessAnimationEvents() { for (int index1 = 0; index1 < this.mAnimationStates.Count; ++index1) { AnimationPlayer.AnimationStateSource mAnimationState = this.mAnimationStates[index1]; AnimDef clip = mAnimationState.Clip; float length = clip.Length; if ((double)mAnimationState.Weight > 0.0 && clip.events != null) { for (int index2 = 0; index2 < clip.events.Length; ++index2) { AnimEvent e = clip.events[index2]; if (!Object.op_Equality((Object)e, (Object)null) && this.IsEventAllowed(e)) { float num1 = Mathf.Min(e.Start, length); float num2 = Mathf.Min(e.End, length); float num3 = mAnimationState.WrapMode != 2 || (double)mAnimationState.Time >= (double)mAnimationState.TimeOld ? mAnimationState.TimeOld : mAnimationState.TimeOld - length; if ((double)num1 < (double)length) { if ((double)num3 <= (double)num1 && (double)num1 < (double)mAnimationState.Time) { this.OnEventStart(e, mAnimationState.Weight); e.OnStart(((Component)this).get_gameObject()); } } else if ((double)num3 < (double)num1 && (double)num1 <= (double)mAnimationState.Time) { this.OnEventStart(e, mAnimationState.Weight); e.OnStart(((Component)this).get_gameObject()); } if ((double)num1 <= (double)mAnimationState.Time && (double)mAnimationState.Time < (double)num2) { float num4 = e.End - e.Start; this.OnEvent(e, mAnimationState.Time, mAnimationState.Weight); e.OnTick(((Component)this).get_gameObject(), (double)num4 <= 0.0 ? 0.0f : (mAnimationState.Time - e.Start) / num4); } if ((double)num2 < (double)length) { if ((double)num3 <= (double)num2 && (double)num2 < (double)mAnimationState.Time) { this.OnEventEnd(e, mAnimationState.Weight); e.OnEnd(((Component)this).get_gameObject()); } } else if ((double)num3 < (double)num2 && (double)num2 <= (double)mAnimationState.Time) { this.OnEventEnd(e, mAnimationState.Weight); e.OnEnd(((Component)this).get_gameObject()); } } } } } }
public void SetSpeed(string id, float speed) { AnimationPlayer.AnimationStateSource state = this.FindState(id); if (state == null) { DebugUtility.LogError("Animation ID " + id + " not found"); } else { state.Speed = speed; } }
protected void UpdateAnimationStates(float dt, bool forceUpdate) { if (Object.op_Equality((Object)this.mAnimation, (Object)null) || this.mDetectedInifiteLoop) { return; } if ((double)dt > 0.0) { this.mResampleTimer += dt; } Vector3 vector3 = Vector3.get_zero(); Transform transform1 = ((Component)this).get_transform(); Vector3 zero = Vector3.get_zero(); int num1 = 0; bool flag; do { flag = false; ++num1; if (num1 > 100) { Debug.LogError((object)(((Object)this).get_name() + " >>> INFINITE LOOP DETECTED!!!")); this.mDetectedInifiteLoop = true; IEnumerator enumerator = this.mAnimation.GetEnumerator(); try { while (enumerator.MoveNext()) { AnimationState current = (AnimationState)enumerator.Current; Debug.LogError((object)string.Format("CLIP name:{0} clip:{1} clipname:{2} clipInstance:{3}", new object[4] { (object)current.get_name(), (object)current.get_clip(), (object)((Object)current.get_clip()).get_name(), (object)((Object)current.get_clip()).GetInstanceID() })); } return; } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } } else { IEnumerator enumerator = this.mAnimation.GetEnumerator(); try { if (enumerator.MoveNext()) { AnimationState current = (AnimationState)enumerator.Current; flag = true; this.mAnimation.RemoveClip(current.get_clip()); } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } } }while (flag); float mResampleTimer = this.mResampleTimer; this.mResampleTimer = 0.0f; float num2 = 0.0f; for (int index = 0; index < this.mAnimationStates.Count; ++index) { AnimationPlayer.AnimationStateSource mAnimationState = this.mAnimationStates[index]; mAnimationState.Weight = Mathf.MoveTowards(mAnimationState.Weight, mAnimationState.DesiredWeight, mAnimationState.BlendRate * mResampleTimer); num2 += mAnimationState.Weight; } for (int index = 0; index < this.mAnimationStates.Count; ++index) { AnimationPlayer.AnimationStateSource mAnimationState = this.mAnimationStates[index]; AnimDef clip = mAnimationState.Clip; float length = clip.Length; if ((double)mAnimationState.Weight <= 0.0 && (double)mAnimationState.DesiredWeight <= 0.0) { this.mAnimationStates.RemoveAt(index); --index; } else { float time = mAnimationState.Time; mAnimationState.TimeOld = time; mAnimationState.Time += mResampleTimer * mAnimationState.Speed; float num3 = mAnimationState.Weight / num2; if (mAnimationState.WrapMode == 2) { mAnimationState.Time %= length; } else if ((double)mAnimationState.Time > (double)length) { mAnimationState.Time = length; } if (clip.UseRootMotion && this.mRootMotionMode == AnimationPlayer.RootMotionModes.Velocity && this.RootMotionBoneName == clip.rootBoneName) { if (clip.rootTranslationX != null) { // ISSUE: explicit reference operation // ISSUE: variable of a reference type Vector3& local1 = @vector3; // ISSUE: explicit reference operation // ISSUE: explicit reference operation (^ local1).x = (__Null)((^ local1).x + (double)this.EvaluateCurveValue(clip.rootTranslationX, time, mAnimationState.Time, length) * (double)num3); // ISSUE: explicit reference operation // ISSUE: variable of a reference type Vector3& local2 = @zero; // ISSUE: explicit reference operation // ISSUE: explicit reference operation (^ local2).x = (__Null)((^ local2).x - (double)clip.rootTranslationX.Evaluate(mAnimationState.Time) * (double)num3); } if (clip.rootTranslationY != null) { // ISSUE: explicit reference operation // ISSUE: variable of a reference type Vector3& local1 = @vector3; // ISSUE: explicit reference operation // ISSUE: explicit reference operation (^ local1).y = (__Null)((^ local1).y + (double)this.EvaluateCurveValue(clip.rootTranslationY, time, mAnimationState.Time, length) * (double)num3); // ISSUE: explicit reference operation // ISSUE: variable of a reference type Vector3& local2 = @zero; // ISSUE: explicit reference operation // ISSUE: explicit reference operation (^ local2).y = (__Null)((^ local2).y - (double)clip.rootTranslationY.Evaluate(mAnimationState.Time) * (double)num3); } if (clip.rootTranslationZ != null) { // ISSUE: explicit reference operation // ISSUE: variable of a reference type Vector3& local1 = @vector3; // ISSUE: explicit reference operation // ISSUE: explicit reference operation (^ local1).z = (__Null)((^ local1).z + (double)this.EvaluateCurveValue(clip.rootTranslationZ, time, mAnimationState.Time, length) * (double)num3); // ISSUE: explicit reference operation // ISSUE: variable of a reference type Vector3& local2 = @zero; // ISSUE: explicit reference operation // ISSUE: explicit reference operation (^ local2).z = (__Null)((^ local2).z - (double)clip.rootTranslationZ.Evaluate(mAnimationState.Time) * (double)num3); } } string name = ((Object)mAnimationState.Clip.animation).get_name(); ((Object)mAnimationState.Clip.animation).set_name(mAnimationState.Name); this.mAnimation.AddClip(mAnimationState.Clip.animation, mAnimationState.Name); AnimationState animationState = this.mAnimation.get_Item(mAnimationState.Name); animationState.set_name(animationState.get_name()); animationState.set_time(mAnimationState.Time); animationState.set_weight(mAnimationState.Weight); animationState.set_enabled(true); mAnimationState.CopiedStateRef = animationState; ((Object)mAnimationState.Clip.animation).set_name(name); } } if (this.mAnimationStates.Count > 0) { this.mAnimation.Sample(); for (int index = 0; index < this.mAnimationStates.Count; ++index) { this.mAnimationStates[index].CopiedStateRef.set_enabled(false); } if (this.OnAnimationUpdate != null) { this.OnAnimationUpdate(((Component)this).get_gameObject()); } } this.RootMotionInverse = Vector3.get_zero(); if (this.mRootMotionMode == AnimationPlayer.RootMotionModes.Velocity) { // ISSUE: explicit reference operation if ((double)((Vector3)@vector3).get_sqrMagnitude() > 0.0) { vector3 = Vector3.op_Multiply(vector3, this.RootMotionScale); if ((double)Mathf.Sign((float)transform1.get_lossyScale().x) < 0.0) { // ISSUE: explicit reference operation // ISSUE: variable of a reference type Vector3& local = @vector3; // ISSUE: explicit reference operation // ISSUE: explicit reference operation (^ local).x = (__Null)((^ local).x * -1.0); } if ((double)Mathf.Sign((float)transform1.get_lossyScale().z) < 0.0) { // ISSUE: explicit reference operation // ISSUE: variable of a reference type Vector3& local = @vector3; // ISSUE: explicit reference operation // ISSUE: explicit reference operation (^ local).z = (__Null)((^ local).z * -1.0); } vector3.y = (__Null)0.0; Transform transform2 = transform1; transform2.set_position(Vector3.op_Addition(transform2.get_position(), Quaternion.op_Multiply(transform1.get_rotation(), vector3))); } Transform childRecursively = GameUtility.findChildRecursively(transform1, this.RootMotionBoneName); if (Object.op_Inequality((Object)childRecursively, (Object)null)) { Transform transform2 = childRecursively; transform2.set_localPosition(Vector3.op_Addition(transform2.get_localPosition(), zero)); this.RootMotionInverse = Quaternion.op_Multiply(childRecursively.get_parent().get_rotation(), zero); } } else if (this.mRootMotionMode == AnimationPlayer.RootMotionModes.Discard) { Transform childRecursively = GameUtility.findChildRecursively(transform1, this.RootMotionBoneName); if (Object.op_Inequality((Object)childRecursively, (Object)null)) { childRecursively.set_localPosition(new Vector3(0.0f, (float)childRecursively.get_localPosition().y, 0.0f)); } } this.ProcessAnimationEvents(); }