当前位置:   article > 正文

Unity 3d转2d再转3d_unityscenc变成2d转3d

unityscenc变成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场景");
    }


}



声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/792940
推荐阅读
相关标签
  

闽ICP备14008679号