Пример #1
0
    IEnumerator MovePlayer(StereoRenderer stereoRenderer)
    {
        isColliding = true;

        Debug.Log(stereoRenderer.gameObject.transform.parent.name);

        stereoRenderer.shouldRender = false;

        // adjust rotation
        Quaternion rotEntryToExit = stereoRenderer.anchorRot * Quaternion.Inverse(stereoRenderer.canvasOriginRot);

        hmdRig.transform.rotation = rotEntryToExit * hmdRig.transform.rotation;

        // adjust position
        Vector3 posDiff = new Vector3(stereoRenderer.stereoCameraHead.transform.position.x - hmdEye.transform.position.x,
                                      stereoRenderer.stereoCameraHead.transform.position.y - hmdEye.transform.position.y,
                                      stereoRenderer.stereoCameraHead.transform.position.z - hmdEye.transform.position.z);
        Vector3 offset = stereoRenderer.anchorRot * Vector3.forward;

        offset.Normalize();

        Vector3 camRigTargetPos = hmdRig.transform.position + posDiff;

        // assign the target position to camera rig
        hmdRig.transform.position = camRigTargetPos;

        stereoRenderer.shouldRender = true;

        yield return(new WaitForSeconds(0.1f));

        isColliding = false;
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        teleportPointerObject.SetActive(true);
        if (Controller.GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu))
        {
            showPortalPlacer = !showPortalPlacer;
        }

        if (showPortalPlacer)
        {
            UpdatePortalPlacer();
        }
        else
        {
            portalPlacer.SetActive(false);
            teleportPointerObject.SetActive(false);
        }

        if (Controller.GetHairTriggerDown() && showPortalPlacer && teleportPointerObject.activeSelf)
        {
            showPortalPlacer = false;
            if (portal != null)
            {
                Destroy(portal);
            }

            portal         = Instantiate(portalPrefab, portalPlacer.transform.position, portalPlacer.transform.rotation);
            stereoRenderer = portal.GetComponentInChildren <StereoRenderer>();
            stereoRenderer.canvasOriginPos = portal.transform.position;
            stereoRenderer.canvasOriginRot = portal.transform.rotation;
        }
    }
Пример #3
0
 public void OnPlayerEnter(StereoRenderer stereoRenderer)
 {
     if (!isColliding)
     {
         StartCoroutine(MovePlayer(stereoRenderer));
     }
 }
Пример #4
0
    void CreateStereoRendererPair(PortalPair pp)
    {
        StereoRenderer srA = CreateStereoRenderer(pp.portalA);
        StereoRenderer srB = CreateStereoRenderer(pp.portalB);

        srA.canvasOrigin    = pp.portalA.transform;
        srA.anchorTransform = pp.portalB.transform;

        srB.canvasOrigin    = pp.portalB.transform;
        srB.anchorTransform = pp.portalA.transform;

        GetRenderPlane(pp.portalA).AddComponent <DisableOutOfView>();
        GetRenderPlane(pp.portalB).AddComponent <DisableOutOfView>();
    }
Пример #5
0
    void Update()
    {
        StereoRenderer r = target.GetComponent <StereoRenderer>();

        if (r == null && Input.GetKeyDown(KeyCode.Space))
        {
            StereoRenderer stereoRenderer = target.AddComponent <StereoRenderer>();

            stereoRenderer.anchorPos   = new Vector3(-0.22f, 0.0f, -2.39f);
            stereoRenderer.anchorEuler = new Vector3(0, 180.0f, 0);

            stereoRenderer.canvasOriginPos = new Vector3(0, 0, 6.57f);
        }
    }
Пример #6
0
    public void EnablePortalRendering()
    {
        StereoRenderer stereoRend = GetComponent <StereoRenderer>();

        if (stereoRend == null)
        {
            return;
        }

        stereoRend.enabled = true;

        foreach (Transform child in transform)
        {
            child.gameObject.SetActive(true);
        }
    }
Пример #7
0
    StereoRenderer CreateStereoRenderer(GameObject portal)
    {
        GameObject renderPlane = GetRenderPlane(portal);

        StereoRenderer sr = renderPlane.GetComponent <StereoRenderer>();

        if (sr == null)
        {
            sr = renderPlane.AddComponent <StereoRenderer>();
        }

        sr.isUnlit        = true;
        sr.shouldRender   = true;
        sr.useScissor     = false;
        sr.useObliqueClip = false;
        return(sr);
    }
Пример #8
0
    /////////////////////////////////////////////////////////////////////////////////

    private void OnEnable()
    {
        stereoRenderer = GetComponent <StereoRenderer>();
    }
Пример #9
0
 public void SetRenderer(StereoRenderer renderer)
 {
     SetRenderer(renderer != null ? new StereoRendererHelper(this, renderer) : null);
 }
        IEnumerator <AsyncOperation> SpawnMirror()
        {
            AssetBundleCreateRequest shadersBundleCreateRequest = AssetBundle.LoadFromFileAsync("CustomAvatars/Shaders/customavatars.assetbundle");

            yield return(shadersBundleCreateRequest);

            if (!shadersBundleCreateRequest.isDone || shadersBundleCreateRequest.assetBundle == null)
            {
                Plugin.logger.Error("Failed to load stereo mirror shader");
                yield break;
            }

            AssetBundleRequest assetBundleRequest = shadersBundleCreateRequest.assetBundle.LoadAssetAsync <Shader>("Assets/Shaders/StereoRenderShader-Unlit.shader");

            yield return(assetBundleRequest);

            shadersBundleCreateRequest.assetBundle.Unload(false);

            if (!assetBundleRequest.isDone || assetBundleRequest.asset == null)
            {
                Plugin.logger.Error("Failed to load stereo mirror shader");
                yield break;
            }

            Shader stereoRenderShader = assetBundleRequest.asset as Shader;

            _mirrorPlane      = GameObject.CreatePrimitive(PrimitiveType.Plane);
            _mirrorPlane.name = "Stereo Mirror";
            _mirrorPlane.transform.localScale = kMirrorScale;
            _mirrorPlane.transform.position   = kMirrorPosition + new Vector3(0, kMirrorScale.z * 5, 0); // plane is 10 units in size at scale 1
            _mirrorPlane.transform.rotation   = kMirrorRotation;

            Material material = new Material(stereoRenderShader);

            material.SetFloat("_Cutout", 0.01f);

            Renderer renderer = _mirrorPlane.GetComponent <Renderer>();

            renderer.sharedMaterial = material;

            GameObject stereoCameraHead = new GameObject("Stereo Camera Head [Stereo Mirror]");

            stereoCameraHead.transform.SetParent(_mirrorPlane.transform, false);
            stereoCameraHead.transform.localScale = new Vector3(1 / kMirrorScale.x, 1 / kMirrorScale.y, 1 / kMirrorScale.z);

            GameObject stereoCameraEyeObject = new GameObject("Stereo Camera Eye [Stereo Mirror]");

            stereoCameraEyeObject.transform.SetParent(_mirrorPlane.transform, false);

            Camera stereoCameraEye = stereoCameraEyeObject.AddComponent <Camera>();

            stereoCameraEye.enabled         = false;
            stereoCameraEye.cullingMask     = (1 << AvatarLayers.AlwaysVisible) | (1 << AvatarLayers.OnlyInThirdPerson);
            stereoCameraEye.clearFlags      = CameraClearFlags.SolidColor;
            stereoCameraEye.backgroundColor = new Color(0, 0, 0, 1f);

            StereoRenderer stereoRenderer = _mirrorPlane.AddComponent <StereoRenderer>();

            stereoRenderer.stereoCameraHead = stereoCameraHead;
            stereoRenderer.stereoCameraEye  = stereoCameraEye;
            stereoRenderer.isMirror         = true;
            stereoRenderer.useScissor       = false;
            stereoRenderer.canvasOriginPos  = _mirrorPlane.transform.position + new Vector3(-10f, 0, 0);
            stereoRenderer.canvasOriginRot  = _mirrorPlane.transform.rotation;
        }