Esempio n. 1
0
 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();
 }
Esempio n. 2
0
 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;
     }
 }
Esempio n. 3
0
 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 Timeline();
         this.m_MustSampleMotions = true;
     }
     this.CreateController();
     if (this.m_ParameterInfoList == null)
     {
         this.CreateParameterInfoList();
     }
 }
Esempio n. 4
0
		private Vector3[] GetPivotVectors(Timeline.PivotSample[] samples, float motionStart, float motionStop, Rect rect, bool loop)
		{
			if (samples.Length == 0 || motionStop - motionStart < 0.33f)
			{
				return new Vector3[0];
			}
			float num = motionStop - motionStart;
			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 = rect.height / 16f + pivotSample.m_Weight * 12f * rect.height / 16f;
				list.Add(zero);
			}
			if (loop && list[list.Count - 1].x <= rect.width)
			{
				float x = list[list.Count - 1].x;
				int num2 = 0;
				int num3 = 1;
				List<Vector3> list2 = new List<Vector3>();
				list2.Add(list[list.Count - 1]);
				while (x < rect.width)
				{
					if (num2 > list.Count - 1)
					{
						num2 = 0;
						num3++;
					}
					Vector3 item = list[num2];
					item.x += (float)num3 * num;
					x = item.x;
					list2.Add(item);
					num2++;
				}
				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));
				}
			}
			return list.ToArray();
		}
 public void OnDestroy()
 {
   this.ClearController();
   if (this.m_Timeline != null)
     this.m_Timeline = (Timeline) null;
   if (this.m_AvatarPreview == null)
     return;
   this.m_AvatarPreview.OnDestroy();
   this.m_AvatarPreview = (AvatarPreview) null;
 }
Esempio n. 6
0
        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;
        }