public void OnDestroy() { this.ClearController(); if (this.m_Timeline != null) { this.m_Timeline = null; } if (this.m_AvatarPreview != null) { this.m_AvatarPreview.OnDestroy(); this.m_AvatarPreview = null; } }
public void OnDisable() { ClearController(); if (m_Timeline != null) { m_Timeline = null; } if (m_AvatarPreview != null) { m_AvatarPreview.OnDisable(); m_AvatarPreview = null; } }
private void Init(Animator scenePreviewObject, Motion motion) { if (this.m_AvatarPreview == null) { this.m_AvatarPreview = new AvatarPreview(scenePreviewObject, motion); this.m_AvatarPreview.OnAvatarChangeFunc = new AvatarPreview.OnAvatarChange(this.OnPreviewAvatarChanged); this.m_AvatarPreview.ShowIKOnFeetButton = false; } if (this.m_Timeline == null) { this.m_Timeline = new TimelineControl(); this.m_MustSampleMotions = true; } this.CreateController(); if (this.m_ParameterInfoList == null) { this.CreateParameterInfoList(); } }
private void Init(Animator scenePreviewObject, Motion motion) { if (m_AvatarPreview == null) { m_AvatarPreview = new AvatarPreview(scenePreviewObject, motion); m_AvatarPreview.OnAvatarChangeFunc = OnPreviewAvatarChanged; m_AvatarPreview.ShowIKOnFeetButton = false; m_AvatarPreview.ResetPreviewFocus(); } if (m_Timeline == null) { m_Timeline = new TimelineControl(); m_MustSampleMotions = true; } CreateController(); CreateParameterInfoList(); }
private void ResampleTransition(AnimatorStateTransition transition, AvatarMask layerMask, TransitionPreview.TransitionInfo info, Animator previewObject) { this.m_IsResampling = true; this.m_MustResample = false; this.m_ValidTransition = true; 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_IsResampling = false; } else { 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; this.m_IsResampling = false; } else { 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; if (this.m_RefTransition.exitTime == 0f) { this.m_AvatarPreview.Animator.CrossFade(0, 0f, 0, 0.9999f); } this.m_AvatarPreview.Animator.StartRecording(-1); this.m_LeftStateWeightA = 0f; this.m_LeftStateTimeA = 0f; this.m_AvatarPreview.Animator.Update(0f); while (!flag4 && num6 < num) { 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; this.m_IsResampling = false; } else { 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) { TimelineControl.PivotSample pivotSample = new TimelineControl.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) { TimelineControl.PivotSample pivotSample2 = new TimelineControl.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) { TimelineControl arg_80E_0 = this.m_Timeline; float num9 = this.m_AvatarPreview.timeControl.currentTime = (this.m_AvatarPreview.timeControl.startTime = 0f); this.m_Timeline.StartTime = num9; arg_80E_0.Time = num9; this.m_Timeline.ResetRange(); } this.m_AvatarPreview.Animator.StartPlayback(); this.m_IsResampling = false; } } } }