Unity 3d转2d再转3d

我是用daydream平台测试的,目前别的平台还没有测试

大概思路是playerSettings 中设置勾选Virtual Reality Supported 后选着对应的平台这里选的是Daydream 

然后在转换平台时用下面的方法加载到对应的平台,

UnityEngine.XR.XRSettings.LoadDeviceByName("None")

UnityEngine.XR.XRSettings.LoadDeviceByName("daydream");

并设置UnityEngine.XR.XRSettings.enabled = true;就可以切换到vr模式了


在同一个场景中增加两个MainCamera,


下面把脚本附上

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.XR;


public class Manger3dTo2d : MonoBehaviour
{
    private bool is3d = true;


    public GameObject canvas;


    public GameObject mainCamare;


    public GameObject camare;


    //public GameObject evenSystem;


    public TextMesh tm;


    //public GameObject hand;
// Use this for initialization
void Start ()
{
    tm.text = XRSettings.loadedDeviceName;
    Debug.Log(XRSettings.loadedDeviceName + "333");
    is3d = true;
canvas.SetActive(false);
    camare.SetActive(false);
}

// Update is called once per frame
void Update () {
        if ((GvrControllerInput.AppButtonUp || Input.GetKeyUp(KeyCode.A)) && is3d)
    {
        canvas.SetActive(true);
        is3d = false;
            
        //UnityEngine.XR.XRSettings.enabled = false;
        XRSettings.LoadDeviceByName("None");
            Debug.Log(XRSettings.loadedDeviceName);
        tm.text = XRSettings.loadedDeviceName;
        //evenSystem.GetComponent<GvrPointerInputModule>().enabled = false;
        //evenSystem.GetComponent<StandaloneInputModule>().enabled = true;
            mainCamare.SetActive(false);
            camare.SetActive(true);
            //hand.SetActive(false);
    }
        if (GvrControllerInput.ClickButtonDown || Input.GetKeyUp(KeyCode.B))
        {
            To3d();
        }
}


    public void To3d()
    {        
        StartCoroutine(VrOn());    
    }


    IEnumerator VrOn()
    {
        XRSettings.LoadDeviceByName("daydream");
        Debug.Log(XRSettings.loadedDeviceName + "1111");
#if UNITY_EDITOR


#endif
#if UNITY_ANDROID
        yield return new WaitUntil(() => XRSettings.loadedDeviceName == "daydream");//到这一步pc不能测试了
#endif
        Debug.Log(XRSettings.loadedDeviceName + "222");
        yield return null;
        XRSettings.enabled = true;
        Debug.Log(XRSettings.loadedDeviceName);
        tm.text = XRSettings.loadedDeviceName;
        canvas.SetActive(false);
        is3d = true;
        mainCamare.SetActive(true);
        camare.SetActive(false);
        //hand.SetActive(true);
        //evenSystem.GetComponent<GvrPointerInputModule>().enabled = true;
        //evenSystem.GetComponent<StandaloneInputModule>().enabled = false;
    }


    public void ButtonClick()
    {
        Debug.Log("这是2d场景");
    }


}



  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值