Exemplo n.º 1
0
        /// <summary> Teleporting initialized by an Unity UI Event </summary>
        public override void OnPointerDown(PointerEventData eventData)
        {
            Vector3 pointingPosition = eventData.pointerCurrentRaycast.worldPosition;

            if (IsValid(pointingPosition) && eventData.currentInputModule != null)
            {
                GameObject originator = eventData.currentInputModule.gameObject;

                Transform       teleportingTransform = originator.transform;
                HumanoidControl humanoid             = originator.transform.GetComponentInParent <HumanoidControl>();
                if (humanoid != null)
                {
                    teleportingTransform = humanoid.transform;

                    humanoid.hipsTarget.animator.enabled      = enableAnimators;
                    humanoid.leftFootTarget.animator.enabled  = enableAnimators;
                    humanoid.rightFootTarget.animator.enabled = enableAnimators;
                }

                if (targetPosRot == TargetPosRot.Pointer)
                {
                    Teleport(teleportingTransform, pointingPosition, originator.transform.rotation, movementType, null);
                }
                else if (targetTransform != null)
                {
                    Teleport(teleportingTransform, targetTransform.position, targetTransform.rotation, movementType, targetTransform);
                }
                else
                {
                    Teleport(teleportingTransform, transform.position, transform.rotation, movementType, targetTransform);
                }

                if (humanoid != null)
                {
                    humanoid.pose = pose;
                    if (pose != null)
                    {
                        float oldNeckHeight = humanoid.headTarget.head.target.transform.position.y;
                        humanoid.pose.Show(humanoid);
                        float deltaNeckHeight = humanoid.headTarget.head.target.transform.position.y - oldNeckHeight;
                        humanoid.AdjustTracking(new Vector3(0, deltaNeckHeight, 0));
                        humanoid.CopyRigToTargets();
                    }
                }
            }

            base.OnPointerDown(eventData);
        }