Пример #1
0
    public void DoTeleport()
    {
        Quaternion?rotation = null;

        if (rotate)
        {
            var rotationY = rotationAbsolute ? transform.rotation.eulerAngles.y : VectorUtils.AngleOffAroundAxis(transform.forward, VRTK_DeviceFinder.HeadsetTransform().forward, Vector3.up);
            rotationY += VRTK_SDKManager.instance.transform.rotation.eulerAngles.y;
            rotation   = Quaternion.Euler(0, rotationY, 0);
        }

        var  playAreaTeleport           = teleport as PlayAreaLimitedTeleport;
        bool originalCheckForCollisions = false;

        if (playAreaTeleport)
        {
            originalCheckForCollisions          = playAreaTeleport.checkForCollisions;
            playAreaTeleport.checkForCollisions = false;
        }

        teleport.skipBlink = true;
        teleport.Teleport(transform, transform.position, rotation);
        teleport.skipBlink = false;

        headsetEat.enabled = true;

        Destroy(gameObject);

        if (playAreaTeleport)
        {
            playAreaTeleport.checkForCollisions = originalCheckForCollisions;
        }
    }
Пример #2
0
    public void DoTeleport()
    {
        if (teleported)
        {
            return;
        }

        teleported = true;

        if (!targetRotation)
        {
            targetRotation = target;
        }

        // Force enabling the teleport
        target.tag = "IncludeTeleport";

        bool scaleRoom = sceneObjects && newSceneScale > 0;

        var teleportPosition = (target.position * (scaleRoom && scalePosition ? newSceneScale : 1)) + offset;

        var teleporter = this.teleporter ?? FindObjectOfType <VRTK_BasicTeleport>();

        var  playAreaTeleport           = teleporter as PlayAreaLimitedTeleport;
        bool originalCheckForCollisiosn = false;

        if (playAreaTeleport)
        {
            originalCheckForCollisiosn          = playAreaTeleport.checkForCollisions;
            playAreaTeleport.checkForCollisions = false;
        }

        var originalBlinkDelay      = teleporter.distanceBlinkDelay;
        var originalBlinkTransition = teleporter.blinkTransitionSpeed;

        teleporter.distanceBlinkDelay   = blinkDistance;
        teleporter.blinkTransitionSpeed = blinkTransition;

        if (scaleRoom)
        {
            sceneObjects.localScale = new Vector3(newSceneScale, newSceneScale, newSceneScale);
        }

        Quaternion?rotation = null;

        if (doRotate)
        {
            float rotationY;

            if (VRTK_DeviceFinder.GetHeadsetTypeAsString() == "simulator")
            {
                // The simulator Y rotation is done by the play area and not the headset transform...
                rotationY = Vector3.SignedAngle(Vector3.forward, targetRotation.forward, Vector3.up);
            }
            else
            {
                rotationY = VectorUtils.AngleOffAroundAxis(targetRotation.forward, VRTK_DeviceFinder.HeadsetTransform().forward, Vector3.up) + VRTK_SDKManager.instance.transform.rotation.eulerAngles.y;
            }

            rotation = Quaternion.Euler(0, rotationY, 0);
        }

        beforeTeleport?.Invoke();

        if (scaleCamera && resizeFirst)
        {
            VRTK_SDKManager.instance.transform.localScale = new Vector3(newSceneScale, newSceneScale, newSceneScale);
        }

        if (doTeleport)
        {
            teleporter.Teleport(target, teleportPosition, rotation);
        }
        else
        {
            VRTK_SDK_Bridge.HeadsetFade(Color.black, 0);
            teleporter.Invoke("ReleaseBlink", 1.0f);
        }

        if (scaleCamera && !resizeFirst)
        {
            VRTK_SDKManager.instance.transform.localScale = new Vector3(newSceneScale, newSceneScale, newSceneScale);
        }

        afterTeleport?.Invoke();

        if (deleteTarget)
        {
            Destroy(target.gameObject);
        }

        teleporter.distanceBlinkDelay   = originalBlinkDelay;
        teleporter.blinkTransitionSpeed = originalBlinkTransition;

        if (playAreaTeleport)
        {
            playAreaTeleport.checkForCollisions = originalCheckForCollisiosn;
        }
    }