private bool MustResample(TransitionPreview.TransitionInfo info)
 {
   if (!this.mustResample)
     return !info.IsEqual(this.m_RefTransitionInfo);
   return true;
 }
예제 #2
0
 public bool IsEqual(TransitionPreview.TransitionInfo info)
 {
     return ((((this.m_SrcState == info.m_SrcState) && (this.m_DstState == info.m_DstState)) && (Mathf.Approximately(this.m_TransitionDuration, info.m_TransitionDuration) && Mathf.Approximately(this.m_TransitionOffset, info.m_TransitionOffset))) && Mathf.Approximately(this.m_ExitTime, info.m_ExitTime));
 }
 public bool IsEqual(TransitionPreview.TransitionInfo info)
 {
   if ((UnityEngine.Object) this.m_SrcState == (UnityEngine.Object) info.m_SrcState && (UnityEngine.Object) this.m_DstState == (UnityEngine.Object) info.m_DstState && (Mathf.Approximately(this.m_TransitionDuration, info.m_TransitionDuration) && Mathf.Approximately(this.m_TransitionOffset, info.m_TransitionOffset)))
     return Mathf.Approximately(this.m_ExitTime, info.m_ExitTime);
   return false;
 }
 private void ResampleTransition(AnimatorStateTransition transition, AvatarMask layerMask, TransitionPreview.TransitionInfo info, Animator previewObject)
 {
   this.m_IsResampling = true;
   this.m_MustResample = false;
   bool flag1 = (UnityEngine.Object) this.m_RefTransition != (UnityEngine.Object) transition;
   this.m_RefTransition = transition;
   this.m_RefTransitionInfo = info;
   this.m_LayerMask = layerMask;
   if (this.m_AvatarPreview != null)
   {
     this.m_AvatarPreview.OnDestroy();
     this.m_AvatarPreview = (AvatarPreview) null;
   }
   this.ClearController();
   Motion motion = this.m_RefSrcState.motion;
   this.Init(previewObject, !((UnityEngine.Object) motion != (UnityEngine.Object) null) ? this.m_RefDstState.motion : motion);
   if ((UnityEngine.Object) this.m_Controller == (UnityEngine.Object) null)
     return;
   this.m_AvatarPreview.Animator.allowConstantClipSamplingOptimization = false;
   this.m_StateMachine.defaultState = this.m_DstState;
   this.m_Transition.mute = true;
   AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, this.m_Controller);
   this.m_AvatarPreview.Animator.Update(1E-05f);
   this.WriteParametersInController();
   this.m_AvatarPreview.Animator.SetLayerWeight(this.m_LayerIndex, 1f);
   float length1 = this.m_AvatarPreview.Animator.GetCurrentAnimatorStateInfo(this.m_LayerIndex).length;
   this.m_StateMachine.defaultState = this.m_SrcState;
   this.m_Transition.mute = false;
   AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, this.m_Controller);
   this.m_AvatarPreview.Animator.Update(1E-05f);
   this.WriteParametersInController();
   this.m_AvatarPreview.Animator.SetLayerWeight(this.m_LayerIndex, 1f);
   float length2 = this.m_AvatarPreview.Animator.GetCurrentAnimatorStateInfo(this.m_LayerIndex).length;
   if (this.m_LayerIndex > 0)
     this.m_AvatarPreview.Animator.stabilizeFeet = false;
   float num1 = (float) ((double) length2 * (double) this.m_RefTransition.exitTime + (double) this.m_Transition.duration * (!this.m_RefTransition.hasFixedDuration ? (double) length2 : 1.0)) + length1;
   if ((double) num1 > 2000.0)
   {
     Debug.LogWarning((object) "Transition duration is longer than 2000 second, Disabling previewer.");
     this.m_ValidTransition = false;
   }
   else
   {
     float num2 = (double) this.m_RefTransition.exitTime <= 0.0 ? length2 : length2 * this.m_RefTransition.exitTime;
     float a1 = (double) num2 <= 0.0 ? 0.03333334f : Mathf.Min(Mathf.Max(num2 / 300f, 0.03333334f), num2 / 5f);
     float a2 = (double) length1 <= 0.0 ? 0.03333334f : Mathf.Min(Mathf.Max(length1 / 300f, 0.03333334f), length1 / 5f);
     float num3 = Mathf.Max(a1, num1 / 600f);
     float num4 = Mathf.Max(a2, num1 / 600f);
     float deltaTime = num3;
     float num5 = 0.0f;
     bool flag2 = false;
     bool flag3 = false;
     bool flag4 = false;
     this.m_AvatarPreview.Animator.StartRecording(-1);
     this.m_LeftStateWeightA = 0.0f;
     this.m_LeftStateTimeA = 0.0f;
     this.m_AvatarPreview.Animator.Update(0.0f);
     while (!flag4)
     {
       this.m_AvatarPreview.Animator.Update(deltaTime);
       AnimatorStateInfo animatorStateInfo = this.m_AvatarPreview.Animator.GetCurrentAnimatorStateInfo(this.m_LayerIndex);
       num5 += deltaTime;
       if (!flag2)
       {
         this.m_LeftStateWeightA = this.m_LeftStateWeightB = animatorStateInfo.normalizedTime;
         this.m_LeftStateTimeA = this.m_LeftStateTimeB = num5;
         flag2 = true;
       }
       if (flag3 && (double) num5 >= (double) num1)
         flag4 = true;
       if (!flag3 && animatorStateInfo.IsName(this.m_DstState.name))
       {
         this.m_RightStateWeightA = animatorStateInfo.normalizedTime;
         this.m_RightStateTimeA = num5;
         flag3 = true;
       }
       if (!flag3)
       {
         this.m_LeftStateWeightB = animatorStateInfo.normalizedTime;
         this.m_LeftStateTimeB = num5;
       }
       if (flag3)
       {
         this.m_RightStateWeightB = animatorStateInfo.normalizedTime;
         this.m_RightStateTimeB = num5;
       }
       if (this.m_AvatarPreview.Animator.IsInTransition(this.m_LayerIndex))
         deltaTime = num4;
     }
     float num6 = num5;
     this.m_AvatarPreview.Animator.StopRecording();
     if (Mathf.Approximately(this.m_LeftStateWeightB, this.m_LeftStateWeightA) || Mathf.Approximately(this.m_RightStateWeightB, this.m_RightStateWeightA))
     {
       Debug.LogWarning((object) "Difference in effective length between states is too big. Transition preview will be disabled.");
       this.m_ValidTransition = false;
     }
     else
     {
       float num7 = (float) (((double) this.m_LeftStateTimeB - (double) this.m_LeftStateTimeA) / ((double) this.m_LeftStateWeightB - (double) this.m_LeftStateWeightA));
       float num8 = (float) (((double) this.m_RightStateTimeB - (double) this.m_RightStateTimeA) / ((double) this.m_RightStateWeightB - (double) this.m_RightStateWeightA));
       if (this.m_MustSampleMotions)
       {
         this.m_MustSampleMotions = false;
         this.m_SrcPivotList.Clear();
         this.m_DstPivotList.Clear();
         float num9 = num4;
         this.m_StateMachine.defaultState = this.m_DstState;
         this.m_Transition.mute = true;
         AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, this.m_Controller);
         this.m_AvatarPreview.Animator.Update(0.0f);
         this.m_AvatarPreview.Animator.SetLayerWeight(this.m_LayerIndex, 1f);
         this.m_AvatarPreview.Animator.Update(1E-07f);
         this.WriteParametersInController();
         float num10 = 0.0f;
         while ((double) num10 <= (double) num8)
         {
           this.m_DstPivotList.Add(new Timeline.PivotSample()
           {
             m_Time = num10,
             m_Weight = this.m_AvatarPreview.Animator.pivotWeight
           });
           this.m_AvatarPreview.Animator.Update(num9 * 2f);
           num10 += num9 * 2f;
         }
         float num11 = num3;
         this.m_StateMachine.defaultState = this.m_SrcState;
         this.m_Transition.mute = true;
         AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, this.m_Controller);
         this.m_AvatarPreview.Animator.Update(1E-07f);
         this.WriteParametersInController();
         this.m_AvatarPreview.Animator.SetLayerWeight(this.m_LayerIndex, 1f);
         float num12 = 0.0f;
         while ((double) num12 <= (double) num7)
         {
           this.m_SrcPivotList.Add(new Timeline.PivotSample()
           {
             m_Time = num12,
             m_Weight = this.m_AvatarPreview.Animator.pivotWeight
           });
           this.m_AvatarPreview.Animator.Update(num11 * 2f);
           num12 += num11 * 2f;
         }
         this.m_Transition.mute = false;
         AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, this.m_Controller);
         this.m_AvatarPreview.Animator.Update(1E-07f);
         this.WriteParametersInController();
       }
       this.m_Timeline.StopTime = this.m_AvatarPreview.timeControl.stopTime = num6;
       this.m_AvatarPreview.timeControl.currentTime = this.m_Timeline.Time;
       if (flag1)
       {
         Timeline timeline = this.m_Timeline;
         float num9 = this.m_AvatarPreview.timeControl.currentTime = this.m_AvatarPreview.timeControl.startTime = 0.0f;
         this.m_Timeline.StartTime = num9;
         double num10 = (double) num9;
         timeline.Time = (float) num10;
         this.m_Timeline.ResetRange();
       }
       this.m_AvatarPreview.Animator.StartPlayback();
       this.m_IsResampling = false;
     }
   }
 }
		private void ResampleTransition(AnimatorStateTransition transition, AvatarMask layerMask, TransitionPreview.TransitionInfo info, Animator previewObject)
		{
			this.m_IsResampling = true;
			this.m_MustResample = false;
			bool flag = this.m_RefTransition != transition;
			this.m_RefTransition = transition;
			this.m_RefTransitionInfo = info;
			this.m_LayerMask = layerMask;
			if (this.m_AvatarPreview != null)
			{
				this.m_AvatarPreview.OnDestroy();
				this.m_AvatarPreview = null;
			}
			this.ClearController();
			Motion motion = this.m_RefSrcState.motion;
			this.Init(previewObject, (!(motion != null)) ? this.m_RefDstState.motion : motion);
			if (this.m_Controller == null)
			{
				return;
			}
			this.m_AvatarPreview.Animator.allowConstantClipSamplingOptimization = false;
			this.m_StateMachine.defaultState = this.m_DstState;
			this.m_Transition.mute = true;
			AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, this.m_Controller);
			this.m_AvatarPreview.Animator.Update(1E-05f);
			this.WriteParametersInController();
			this.m_AvatarPreview.Animator.SetLayerWeight(this.m_LayerIndex, 1f);
			float length = this.m_AvatarPreview.Animator.GetCurrentAnimatorStateInfo(this.m_LayerIndex).length;
			this.m_StateMachine.defaultState = this.m_SrcState;
			this.m_Transition.mute = false;
			AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, this.m_Controller);
			this.m_AvatarPreview.Animator.Update(1E-05f);
			this.WriteParametersInController();
			this.m_AvatarPreview.Animator.SetLayerWeight(this.m_LayerIndex, 1f);
			float length2 = this.m_AvatarPreview.Animator.GetCurrentAnimatorStateInfo(this.m_LayerIndex).length;
			if (this.m_LayerIndex > 0)
			{
				this.m_AvatarPreview.Animator.stabilizeFeet = false;
			}
			float num = length2 * this.m_RefTransition.exitTime + length2 * this.m_Transition.duration + length;
			if (num > 2000f)
			{
				Debug.LogWarning("Transition duration is longer than 2000 second, Disabling previewer.");
				this.m_ValidTransition = false;
				return;
			}
			float num2 = (this.m_RefTransition.exitTime <= 0f) ? length2 : (length2 * this.m_RefTransition.exitTime);
			float num3 = (num2 <= 0f) ? 0.0333333351f : Mathf.Min(Mathf.Max(num2 / 300f, 0.0333333351f), num2 / 5f);
			float num4 = (length <= 0f) ? 0.0333333351f : Mathf.Min(Mathf.Max(length / 300f, 0.0333333351f), length / 5f);
			num3 = Mathf.Max(num3, num / 300f);
			num4 = Mathf.Max(num4, num / 300f);
			float num5 = num3;
			float num6 = 0f;
			bool flag2 = false;
			bool flag3 = false;
			bool flag4 = false;
			this.m_AvatarPreview.Animator.StartRecording(-1);
			this.m_LeftStateWeightA = 0f;
			this.m_LeftStateTimeA = 0f;
			this.m_AvatarPreview.Animator.Update(0f);
			int num7 = 0;
			while (!flag4)
			{
				num7++;
				this.m_AvatarPreview.Animator.Update(num5);
				AnimatorStateInfo currentAnimatorStateInfo = this.m_AvatarPreview.Animator.GetCurrentAnimatorStateInfo(this.m_LayerIndex);
				num6 += num5;
				if (!flag2)
				{
					this.m_LeftStateWeightA = currentAnimatorStateInfo.normalizedTime;
					this.m_LeftStateTimeA = num6;
					flag2 = true;
				}
				if (flag3 && num6 >= num)
				{
					flag4 = true;
				}
				if (!flag3 && currentAnimatorStateInfo.IsName(this.m_DstState.name))
				{
					this.m_RightStateWeightA = currentAnimatorStateInfo.normalizedTime;
					this.m_RightStateTimeA = num6;
					flag3 = true;
				}
				if (!flag3)
				{
					this.m_LeftStateWeightB = currentAnimatorStateInfo.normalizedTime;
					this.m_LeftStateTimeB = num6;
				}
				if (flag3)
				{
					this.m_RightStateWeightB = currentAnimatorStateInfo.normalizedTime;
					this.m_RightStateTimeB = num6;
				}
				if (this.m_AvatarPreview.Animator.IsInTransition(this.m_LayerIndex))
				{
					num5 = num4;
				}
			}
			float stopTime = num6;
			this.m_AvatarPreview.Animator.StopRecording();
			if (Mathf.Approximately(this.m_LeftStateWeightB, this.m_LeftStateWeightA) || Mathf.Approximately(this.m_RightStateWeightB, this.m_RightStateWeightA))
			{
				Debug.LogWarning("Speed difference between states is too big. Transition preview will be disabled.");
				this.m_ValidTransition = false;
				return;
			}
			float num8 = (this.m_LeftStateTimeB - this.m_LeftStateTimeA) / (this.m_LeftStateWeightB - this.m_LeftStateWeightA);
			float num9 = (this.m_RightStateTimeB - this.m_RightStateTimeA) / (this.m_RightStateWeightB - this.m_RightStateWeightA);
			if (this.m_MustSampleMotions)
			{
				this.m_MustSampleMotions = false;
				this.m_SrcPivotList.Clear();
				this.m_DstPivotList.Clear();
				num5 = num4;
				this.m_StateMachine.defaultState = this.m_DstState;
				this.m_Transition.mute = true;
				AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, this.m_Controller);
				this.m_AvatarPreview.Animator.SetLayerWeight(this.m_LayerIndex, 1f);
				this.m_AvatarPreview.Animator.Update(1E-07f);
				this.WriteParametersInController();
				num6 = 0f;
				while (num6 <= num9)
				{
					this.m_AvatarPreview.Animator.Update(num5 * 2f);
					num6 += num5 * 2f;
					Timeline.PivotSample pivotSample = new Timeline.PivotSample();
					pivotSample.m_Time = num6;
					pivotSample.m_Weight = this.m_AvatarPreview.Animator.pivotWeight;
					this.m_DstPivotList.Add(pivotSample);
				}
				num5 = num3;
				this.m_StateMachine.defaultState = this.m_SrcState;
				this.m_Transition.mute = true;
				AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, this.m_Controller);
				this.m_AvatarPreview.Animator.Update(1E-07f);
				this.WriteParametersInController();
				this.m_AvatarPreview.Animator.SetLayerWeight(this.m_LayerIndex, 1f);
				num6 = 0f;
				while (num6 <= num8)
				{
					this.m_AvatarPreview.Animator.Update(num5 * 2f);
					num6 += num5 * 2f;
					Timeline.PivotSample pivotSample2 = new Timeline.PivotSample();
					pivotSample2.m_Time = num6;
					pivotSample2.m_Weight = this.m_AvatarPreview.Animator.pivotWeight;
					this.m_SrcPivotList.Add(pivotSample2);
				}
				this.m_Transition.mute = false;
				AnimatorController.SetAnimatorController(this.m_AvatarPreview.Animator, this.m_Controller);
				this.m_AvatarPreview.Animator.Update(1E-07f);
				this.WriteParametersInController();
			}
			this.m_Timeline.StopTime = (this.m_AvatarPreview.timeControl.stopTime = stopTime);
			this.m_AvatarPreview.timeControl.currentTime = this.m_Timeline.Time;
			if (flag)
			{
				Timeline arg_74F_0 = this.m_Timeline;
				float num10 = this.m_AvatarPreview.timeControl.currentTime = (this.m_AvatarPreview.timeControl.startTime = 0f);
				this.m_Timeline.StartTime = num10;
				arg_74F_0.Time = num10;
				this.m_Timeline.ResetRange();
			}
			this.m_AvatarPreview.Animator.StartPlayback();
			this.m_IsResampling = false;
		}
		private bool MustResample(TransitionPreview.TransitionInfo info)
		{
			return this.mustResample || !info.IsEqual(this.m_RefTransitionInfo);
		}
 public override void OnEnable()
 {
     base.OnEnable();
     this.m_TransitionPreview = new TransitionPreview();
 }