Пример #1
0
        // Token: 0x0600442B RID: 17451 RVA: 0x00169E80 File Offset: 0x00168280
        public void Step(Quaternion target)
        {
            Vector4 vector = CritDampTweenQuaternion.q2v(target);

            if (Vector4.Dot(this._rotation.v, vector) < 0f)
            {
                vector = -vector;
            }
            float   deltaTime = Time.deltaTime;
            Vector4 a         = this.velocity - (this._rotation.v - vector) * (this.omega * this.omega * deltaTime);
            float   num       = 1f + this.omega * deltaTime;

            this.velocity = a / (num * num);
            float magnitude = this.velocity.magnitude;

            this.velocity    = Mathf.Min(magnitude, this.maxSpeed) / magnitude * this.velocity;
            this._rotation.v = (this._rotation.v + this.velocity * deltaTime).normalized;
        }
		public void Initialize()
		{
			if ( isInitialized )
				return;

			if ( controlData == null )
				return;

			eyeDistance = 0.064f;
			animator = GetComponentInChildren<Animator>();
			#if USE_FINAL_IK
				lookAtIK = GetComponentInChildren<RootMotion.FinalIK.LookAtIK>();
			#endif

			controlData.CheckConsistency( animator, this );
			controlData.Initialize( );

			if ( createdTargetXforms[0] == null )
			{
				createdTargetXforms[0] = new GameObject(name + "_createdEyeTarget_1").transform;
				DestroyNotifier destroyNotifer = createdTargetXforms[0].gameObject.AddComponent<DestroyNotifier>();
				destroyNotifer.OnDestroyedEvent += OnCreatedXformDestroyed;
				DontDestroyOnLoad(createdTargetXforms[0].gameObject);
				createdTargetXforms[0].gameObject.hideFlags = HideFlags.HideInHierarchy;
			}

			if ( createdTargetXforms[1] == null )
			{
				createdTargetXforms[1] = new GameObject(name + "_createdEyeTarget_2").transform;
				DestroyNotifier destroyNotifer = createdTargetXforms[1].gameObject.AddComponent<DestroyNotifier>();
				destroyNotifer.OnDestroyedEvent += OnCreatedXformDestroyed;
				DontDestroyOnLoad(createdTargetXforms[1].gameObject);
				createdTargetXforms[1].gameObject.hideFlags = HideFlags.HideInHierarchy;
			}


			Transform headXform=null;
			if (animator != null)
				headXform = animator.GetBoneTransform(HumanBodyBones.Head);
			#if USE_FINAL_IK
				if ( headXform == null && lookAtIK != null )
					headXform = lookAtIK.solver.head.transform;
			#endif
			if ( headXform == null )
				headXform = transform;

			Transform spineXform = null;
			if ( animator != null )
			{
				spineXform = animator.GetBoneTransform(HumanBodyBones.Chest);
				if ( spineXform == null )
					spineXform = animator.GetBoneTransform(HumanBodyBones.Spine);
			}
			if ( spineXform == null )
				spineXform = transform;

			if ( headParentXform == null )
			{
				headParentXform = new GameObject(name + " head parent").transform;
				headParentXform.gameObject.hideFlags = HideFlags.HideInHierarchy;
				headParentXform.parent = spineXform;
				headParentXform.position = headXform.position;
				headParentXform.rotation = transform.rotation;
			}

			if ( headTargetPivotXform == null )
			{
				headTargetPivotXform = new GameObject(name + " head target").transform;
				headTargetPivotXform.gameObject.hideFlags = HideFlags.HideInHierarchy;
				headTargetPivotXform.parent = headParentXform;
				headTargetPivotXform.localPosition = Vector3.zero;
				headTargetPivotXform.localRotation = Quaternion.identity;

				critDampTween = new CritDampTweenQuaternion(headTargetPivotXform.localRotation, kHeadOmega, kMaxHeadVelocity);
 				lastHeadEuler = headTargetPivotXform.localEulerAngles;
			}

			//*** Eyes
			{
				if ( controlData.eyeControl == ControlData.EyeControl.MecanimEyeBones || controlData.eyeControl == ControlData.EyeControl.SelectedObjects )
				{
					if ( controlData.eyeControl == ControlData.EyeControl.MecanimEyeBones )
					{
						Transform leftEyeBoneXform = animator.GetBoneTransform(HumanBodyBones.LeftEye);
						Transform rightEyeBoneXform = animator.GetBoneTransform(HumanBodyBones.RightEye);
						leftEyeAnchor = leftEyeBoneXform;
						rightEyeAnchor = rightEyeBoneXform;
						if ( leftEyeAnchor == null )
							Debug.LogError("Left eye bone not found in Mecanim rig");
						if ( rightEyeAnchor == null )
							Debug.LogError("Right eye bone not found in Mecanim rig");
					}
					else if ( controlData.eyeControl == ControlData.EyeControl.SelectedObjects )
					{
						leftEyeAnchor = controlData.leftEye;
						rightEyeAnchor = controlData.rightEye;
					}
				}

				if ( eyesRootXform == null )
				{
					eyesRootXform = new GameObject(name + "_eyesRoot").transform;
					eyesRootXform.gameObject.hideFlags = HideFlags.HideInHierarchy;
					eyesRootXform.rotation = transform.rotation;
				}

				if ( leftEyeAnchor != null && rightEyeAnchor != null )
				{
					eyeDistance = Vector3.Distance( leftEyeAnchor.position, rightEyeAnchor.position );
					eyeDistanceScale = eyeDistance/0.064f;
					controlData.RestoreDefault();
					Quaternion inverse = Quaternion.Inverse(eyesRootXform.rotation);
					leftEyeRootFromAnchorQ = inverse * leftEyeAnchor.rotation;
					rightEyeRootFromAnchorQ = inverse * rightEyeAnchor.rotation;
					leftAnchorFromEyeRootQ = Quaternion.Inverse(leftEyeRootFromAnchorQ);
					rightAnchorFromEyeRootQ = Quaternion.Inverse(rightEyeRootFromAnchorQ);

					originalLeftEyeLocalQ = leftEyeAnchor.localRotation;
					originalRightEyeLocalQ = rightEyeAnchor.localRotation;

					eyesRootXform.position = 0.5f * (leftEyeAnchor.position + rightEyeAnchor.position);
					Transform commonAncestorXform = Utils.GetCommonAncestor( leftEyeAnchor, rightEyeAnchor );
					eyesRootXform.parent =  (commonAncestorXform != null) ? commonAncestorXform : leftEyeAnchor.parent;
				}
				else if ( animator != null )
				{
					if ( headXform != null )
					{
						eyesRootXform.position = headXform.position;
						eyesRootXform.parent = headXform;
					}
					else
					{
						eyesRootXform.position = transform.position;
						eyesRootXform.parent = transform;
					}
				}
				else
				{
					eyesRootXform.position = transform.position;
					eyesRootXform.parent = transform;
				}
			}


			//*** Eye lids
			{
				if ( controlData.eyelidControl == ControlData.EyelidControl.Bones )
				{
					if ( controlData.upperEyeLidLeft != null && controlData.upperEyeLidRight != null )
						useUpperEyelids = true;

					if ( controlData.lowerEyeLidLeft != null && controlData.lowerEyeLidRight != null )
						useLowerEyelids = true;
				}

				blink01 = 0;
				timeOfNextBlink = Time.time + Random.Range(3f, 6f);
				ikWeight = headWeight;
			}

			isInitialized = true;
		}