请选择您的所在地
Australia
Österreich
België
Canada
Canada - Français
中国
Česká republika
Denmark
Deutschland
France
HongKong
Iceland
Ireland
Italia
日本
Korea
Latvija
Lietuva
Lëtzebuerg
Malta
المملكة العربية السعودية (Arabic)
Nederland
New Zealand
Norge
Polska
Portugal
Russia
Saudi Arabia
Southeast Asia
España
Suisse
Suomi
Sverige
台灣
Ukraine
United Kingdom
United States
请选择您的所在地
België
Česká republika
Denmark
Iceland
Ireland
Italia
Latvija
Lietuva
Lëtzebuerg
Malta
Nederland
Norge
Polska
Portugal
España
Suisse
Suomi
Sverige

如何在场景中仅显示一个操控手柄?

您可以选择在场景中仅显示一个操控手柄,同时仍保留 2 个活跃的操控手柄。

请添加以下代码:

  • WaveVR中添加新脚本。
    private GameObject ControllerLoader_DO = null; private GameObject loaderInstance_DO = null; private GameObject ControllerLoader_ND = null; private GameObject loaderInstance_ND = null;
    
    #region MonoBehaviour Overrides void OnEnable() { WaveVR_Utils.Event.Listen (WaveVR_Utils.Event.CONTROLLER_MODEL_UNLOADED, OnControllerUnloaded); } void Start () { this.ControllerLoader_DO = Instantiate(Resources.Load("‍ControllerLoader"‍, typeof(GameObject))) as GameObject; this.ControllerLoader_DO.GetComponent<WaveVR_ControllerLoader>().WhichHand = WaveVR_ControllerLoader.ControllerHand.Dominant; this.ControllerLoader_DO.SetActive(false); this.ControllerLoader_ND = Instantiate(Resources.Load("‍ControllerLoader"‍, typeof(GameObject))) as GameObject; this.ControllerLoader_ND.GetComponent<WaveVR_ControllerLoader>().WhichHand = WaveVR_ControllerLoader.ControllerHand.Non_Dominant; this.ControllerLoader_ND.SetActive(false); }
  • Update () 将监视当前操控手柄的连接状态,并仅显示一个操控手柄。
    void Update () { if (WaveVR.Instance == null|| this.ControllerLoader_DO == null || this.ControllerLoader_ND == null) return; if (this.loaderInstance_DO != null || this.loaderInstance_ND != null) return; WaveVR.Device _dev_do = WaveVR.Instance.getDeviceByType (WaveVR_Controller.EDeviceType.Dominant); if (_dev_do != null && _dev_do.connected && this.loaderInstance_ND == null) { this.loaderInstance_DO = Instantiate(ControllerLoader_DO); this.loaderInstance_DO.SetActive(true); } WaveVR.Device _dev_nd = WaveVR.Instance.getDeviceByType(WaveVR_Controller.EDeviceType.NonDominant); if (_dev_nd != null && _dev_nd.connected && this.loaderInstance_DO == null) { this.loaderInstance_ND = Instantiate(ControllerLoader_ND); this.loaderInstance_ND.SetActive(true); } }
  • 当其中一个操控手柄断开连接时,LoaderInstance 将被析构并被设置为 null。
    void OnDisable() { WaveVR_Utils.Event.Remove (WaveVR_Utils.Event.CONTROLLER_MODEL_UNLOADED, OnControllerUnloaded); } #endregion
    
    void OnControllerUnloaded(params object[] args) { WaveVR_Controller.EDeviceType _type = (WaveVR_Controller.EDeviceType)args[0]; switch (_type) { case WaveVR_Controller.EDeviceType.Dominant:if (this.loaderInstance_DO != null) { PrintDebugLog("‍OnControllerUnloaded() remove DO"‍ + this.loaderInstance_DO.name); this.loaderInstance_DO.SetActive(false); Destroy(this.loaderInstance_DO); this.loaderInstance_DO = null; } break; case WaveVR_Controller.EDeviceType.NonDominant:if (this.loaderInstance_ND != null) { PrintDebugLog("‍OnControllerUnloaded() remove ND"‍ + this.loaderInstance_ND.name); this.loaderInstance_ND.SetActive(false); Destroy(this.loaderInstance_ND); this.loaderInstance_ND = null; } break; default:break; } }
提交
谢谢!您的反馈可以帮助其他人了解最有用的信息。