private Vector3[] GetPivotVectors(Timeline.PivotSample[] samples, float width, Rect rect, float height, bool loop) { Vector3[] result; if (samples.Length == 0 || width < 0.33f) { result = new Vector3[0]; } else { List <Vector3> list = new List <Vector3>(); for (int i = 0; i < samples.Length; i++) { Timeline.PivotSample pivotSample = samples[i]; Vector3 zero = Vector3.zero; zero.x = this.m_TimeArea.TimeToPixel(pivotSample.m_Time, rect); zero.y = height / 16f + pivotSample.m_Weight * 12f * height / 16f; list.Add(zero); } if (loop && list[list.Count - 1].x <= rect.width) { float x = list[list.Count - 1].x; int num = 0; int num2 = 1; List <Vector3> list2 = new List <Vector3>(); while (x < rect.width) { if (num > list.Count - 1) { num = 0; num2++; } Vector3 item = list[num]; item.x += (float)num2 * width; x = item.x; list2.Add(item); num++; } list.AddRange(list2); } List <Vector3> controls = this.GetControls(list, 0.5f); list.Clear(); for (int j = 0; j < controls.Count - 3; j += 3) { Vector3 p = controls[j]; Vector3 p2 = controls[j + 1]; Vector3 p3 = controls[j + 2]; Vector3 p4 = controls[j + 3]; if (j == 0) { list.Add(this.CalculatePoint(0f, p, p2, p3, p4)); } for (int k = 1; k <= 10; k++) { list.Add(this.CalculatePoint((float)k / 10f, p, p2, p3, p4)); } } result = list.ToArray(); } return(result); }
private Vector3[] GetPivotVectors(Timeline.PivotSample[] samples, float width, Rect rect, float height, bool loop) { if (samples.Length == 0 || (double)width < 0.330000013113022) { return(new Vector3[0]); } List <Vector3> segmentPoints = new List <Vector3>(); for (int index = 0; index < samples.Length; ++index) { Timeline.PivotSample sample = samples[index]; Vector3 zero = Vector3.zero; zero.x = this.m_TimeArea.TimeToPixel(sample.m_Time, rect); zero.y = (float)((double)height / 16.0 + (double)sample.m_Weight * 12.0 * (double)height / 16.0); segmentPoints.Add(zero); } if (loop && (double)segmentPoints[segmentPoints.Count - 1].x <= (double)rect.width) { float x = segmentPoints[segmentPoints.Count - 1].x; int index = 0; int num = 1; List <Vector3> vector3List = new List <Vector3>(); while ((double)x < (double)rect.width) { if (index > segmentPoints.Count - 1) { index = 0; ++num; } Vector3 vector3 = segmentPoints[index]; vector3.x += (float)num * width; x = vector3.x; vector3List.Add(vector3); ++index; } segmentPoints.AddRange((IEnumerable <Vector3>)vector3List); } List <Vector3> controls = this.GetControls(segmentPoints, 0.5f); segmentPoints.Clear(); int index1 = 0; while (index1 < controls.Count - 3) { Vector3 p0 = controls[index1]; Vector3 p1 = controls[index1 + 1]; Vector3 p2 = controls[index1 + 2]; Vector3 p3 = controls[index1 + 3]; if (index1 == 0) { segmentPoints.Add(this.CalculatePoint(0.0f, p0, p1, p2, p3)); } for (int index2 = 1; index2 <= 10; ++index2) { segmentPoints.Add(this.CalculatePoint((float)index2 / 10f, p0, p1, p2, p3)); } index1 += 3; } return(segmentPoints.ToArray()); }
private void ResampleTransition(AnimatorStateTransition transition, AvatarMask layerMask, 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) { 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 num2 = this.m_AvatarPreview.Animator.GetCurrentAnimatorStateInfo(this.m_LayerIndex).length; if (this.m_LayerIndex > 0) { this.m_AvatarPreview.Animator.stabilizeFeet = false; } float num3 = ((num2 * this.m_RefTransition.exitTime) + (this.m_Transition.duration * (!this.m_RefTransition.hasFixedDuration ? num2 : 1f))) + length; if (num3 > 2000f) { Debug.LogWarning("Transition duration is longer than 2000 second, Disabling previewer."); this.m_ValidTransition = false; } else { float num4 = (this.m_RefTransition.exitTime <= 0f) ? num2 : (num2 * this.m_RefTransition.exitTime); float a = (num4 <= 0f) ? 0.03333334f : Mathf.Min(Mathf.Max((float)(num4 / 300f), (float)0.03333334f), num4 / 5f); float num6 = (length <= 0f) ? 0.03333334f : Mathf.Min(Mathf.Max((float)(length / 300f), (float)0.03333334f), length / 5f); a = Mathf.Max(a, num3 / 300f); num6 = Mathf.Max(num6, num3 / 300f); float deltaTime = a; float num8 = 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 num9 = 0; while (!flag4) { num9++; this.m_AvatarPreview.Animator.Update(deltaTime); AnimatorStateInfo currentAnimatorStateInfo = this.m_AvatarPreview.Animator.GetCurrentAnimatorStateInfo(this.m_LayerIndex); num8 += deltaTime; if (!flag2) { this.m_LeftStateWeightA = currentAnimatorStateInfo.normalizedTime; this.m_LeftStateTimeA = num8; flag2 = true; } if (flag3 && (num8 >= num3)) { flag4 = true; } if (!flag3 && currentAnimatorStateInfo.IsName(this.m_DstState.name)) { this.m_RightStateWeightA = currentAnimatorStateInfo.normalizedTime; this.m_RightStateTimeA = num8; flag3 = true; } if (!flag3) { this.m_LeftStateWeightB = currentAnimatorStateInfo.normalizedTime; this.m_LeftStateTimeB = num8; } if (flag3) { this.m_RightStateWeightB = currentAnimatorStateInfo.normalizedTime; this.m_RightStateTimeB = num8; } if (this.m_AvatarPreview.Animator.IsInTransition(this.m_LayerIndex)) { deltaTime = num6; } } float num10 = num8; 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; } else { float num11 = (this.m_LeftStateTimeB - this.m_LeftStateTimeA) / (this.m_LeftStateWeightB - this.m_LeftStateWeightA); float num12 = (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(); deltaTime = num6; 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(0f); this.m_AvatarPreview.Animator.SetLayerWeight(this.m_LayerIndex, 1f); this.m_AvatarPreview.Animator.Update(1E-07f); this.WriteParametersInController(); for (num8 = 0f; num8 <= num12; num8 += deltaTime * 2f) { Timeline.PivotSample item = new Timeline.PivotSample { m_Time = num8, m_Weight = this.m_AvatarPreview.Animator.pivotWeight }; this.m_DstPivotList.Add(item); this.m_AvatarPreview.Animator.Update(deltaTime * 2f); } deltaTime = a; 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); for (num8 = 0f; num8 <= num11; num8 += deltaTime * 2f) { Timeline.PivotSample sample2 = new Timeline.PivotSample { m_Time = num8, m_Weight = this.m_AvatarPreview.Animator.pivotWeight }; this.m_SrcPivotList.Add(sample2); this.m_AvatarPreview.Animator.Update(deltaTime * 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 = num10; this.m_AvatarPreview.timeControl.currentTime = this.m_Timeline.Time; if (flag) { float num13; this.m_AvatarPreview.timeControl.currentTime = num13 = this.m_AvatarPreview.timeControl.startTime = 0f; this.m_Timeline.StartTime = num13; this.m_Timeline.Time = num13; 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 + this.m_Transition.duration * ((!this.m_RefTransition.hasFixedDuration) ? length2 : 1f) + 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 / 600f); num4 = Mathf.Max(num4, num / 600f); 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); while (!flag4) { this.m_AvatarPreview.Animator.Update(num5); AnimatorStateInfo currentAnimatorStateInfo = this.m_AvatarPreview.Animator.GetCurrentAnimatorStateInfo(this.m_LayerIndex); num6 += num5; if (!flag2) { this.m_LeftStateWeightA = (this.m_LeftStateWeightB = currentAnimatorStateInfo.normalizedTime); this.m_LeftStateTimeA = (this.m_LeftStateTimeB = 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("Difference in effective length between states is too big. Transition preview will be disabled."); this.m_ValidTransition = false; return; } float num7 = (this.m_LeftStateTimeB - this.m_LeftStateTimeA) / (this.m_LeftStateWeightB - this.m_LeftStateWeightA); float num8 = (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.Update(0f); this.m_AvatarPreview.Animator.SetLayerWeight(this.m_LayerIndex, 1f); this.m_AvatarPreview.Animator.Update(1E-07f); this.WriteParametersInController(); for (num6 = 0f; num6 <= num8; 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); this.m_AvatarPreview.Animator.Update(num5 * 2f); } 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); for (num6 = 0f; num6 <= num7; 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_AvatarPreview.Animator.Update(num5 * 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 = stopTime); this.m_AvatarPreview.timeControl.currentTime = this.m_Timeline.Time; if (flag) { Timeline arg_78B_0 = this.m_Timeline; float num9 = this.m_AvatarPreview.timeControl.currentTime = (this.m_AvatarPreview.timeControl.startTime = 0f); this.m_Timeline.StartTime = num9; arg_78B_0.Time = num9; this.m_Timeline.ResetRange(); } this.m_AvatarPreview.Animator.StartPlayback(); this.m_IsResampling = false; }
private void ResampleTransition(AnimatorStateTransition transition, AvatarMask layerMask, 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) { 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 num2 = this.m_AvatarPreview.Animator.GetCurrentAnimatorStateInfo(this.m_LayerIndex).length; if (this.m_LayerIndex > 0) { this.m_AvatarPreview.Animator.stabilizeFeet = false; } float num3 = ((num2 * this.m_RefTransition.exitTime) + (this.m_Transition.duration * (!this.m_RefTransition.hasFixedDuration ? num2 : 1f))) + length; if (num3 > 2000f) { Debug.LogWarning("Transition duration is longer than 2000 second, Disabling previewer."); this.m_ValidTransition = false; } else { float num4 = (this.m_RefTransition.exitTime <= 0f) ? num2 : (num2 * this.m_RefTransition.exitTime); float a = (num4 <= 0f) ? 0.03333334f : Mathf.Min(Mathf.Max((float) (num4 / 300f), (float) 0.03333334f), num4 / 5f); float num6 = (length <= 0f) ? 0.03333334f : Mathf.Min(Mathf.Max((float) (length / 300f), (float) 0.03333334f), length / 5f); a = Mathf.Max(a, num3 / 300f); num6 = Mathf.Max(num6, num3 / 300f); float deltaTime = a; float num8 = 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 num9 = 0; while (!flag4) { num9++; this.m_AvatarPreview.Animator.Update(deltaTime); AnimatorStateInfo currentAnimatorStateInfo = this.m_AvatarPreview.Animator.GetCurrentAnimatorStateInfo(this.m_LayerIndex); num8 += deltaTime; if (!flag2) { this.m_LeftStateWeightA = currentAnimatorStateInfo.normalizedTime; this.m_LeftStateTimeA = num8; flag2 = true; } if (flag3 && (num8 >= num3)) { flag4 = true; } if (!flag3 && currentAnimatorStateInfo.IsName(this.m_DstState.name)) { this.m_RightStateWeightA = currentAnimatorStateInfo.normalizedTime; this.m_RightStateTimeA = num8; flag3 = true; } if (!flag3) { this.m_LeftStateWeightB = currentAnimatorStateInfo.normalizedTime; this.m_LeftStateTimeB = num8; } if (flag3) { this.m_RightStateWeightB = currentAnimatorStateInfo.normalizedTime; this.m_RightStateTimeB = num8; } if (this.m_AvatarPreview.Animator.IsInTransition(this.m_LayerIndex)) { deltaTime = num6; } } float num10 = num8; 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; } else { float num11 = (this.m_LeftStateTimeB - this.m_LeftStateTimeA) / (this.m_LeftStateWeightB - this.m_LeftStateWeightA); float num12 = (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(); deltaTime = num6; 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(0f); this.m_AvatarPreview.Animator.SetLayerWeight(this.m_LayerIndex, 1f); this.m_AvatarPreview.Animator.Update(1E-07f); this.WriteParametersInController(); for (num8 = 0f; num8 <= num12; num8 += deltaTime * 2f) { Timeline.PivotSample item = new Timeline.PivotSample { m_Time = num8, m_Weight = this.m_AvatarPreview.Animator.pivotWeight }; this.m_DstPivotList.Add(item); this.m_AvatarPreview.Animator.Update(deltaTime * 2f); } deltaTime = a; 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); for (num8 = 0f; num8 <= num11; num8 += deltaTime * 2f) { Timeline.PivotSample sample2 = new Timeline.PivotSample { m_Time = num8, m_Weight = this.m_AvatarPreview.Animator.pivotWeight }; this.m_SrcPivotList.Add(sample2); this.m_AvatarPreview.Animator.Update(deltaTime * 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 = num10; this.m_AvatarPreview.timeControl.currentTime = this.m_Timeline.Time; if (flag) { float num13; this.m_AvatarPreview.timeControl.currentTime = num13 = this.m_AvatarPreview.timeControl.startTime = 0f; this.m_Timeline.StartTime = num13; this.m_Timeline.Time = num13; 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; }