PicoVR开发(一)

PicoVR开发和HTC vivo有区别,不过在对按钮进行点击的时候还是比较方便的,下面贴上我的开发代码

PicoVR开发(一)_第1张图片

插件包里面有个自带的Pvr_Haptics的脚本,挂在一个物体上编辑脚本即可

using System;
using UnityEngine;
using UnityEngine.UI;


public class Pvr_Haptics : MonoBehaviour
{
    /************************************    Properties  *************************************/
    #region Properties
    [Header("是否使用触觉")]
    public bool UseHaptic = true;
    [Header("持续振动时间")]
    public int vibrationDuration = 500;
    [Header("沉默持续时间")]
    public int silienceDuration = 200;
    [Header("重复次数")]
    public int repeat_times = 2;
    [Header("振动强度")]
    public int vibrationStrength = 100;
    [Header("触觉")]
    public int whichHaptic = 2;
    public Text TextTip;
    public Text Text_1;
    public Text Text_2;
    //将Head拖进
    public GameObject J_Head;
    private bool usingHaptic = false;
    #endregion


    /************************************   Public Interfaces **********************************/
    #region Public Interfaces


    #endregion


    /*************************************  Unity API ****************************************/
    #region Unity API
    void Awake()
    {
        if (Pvr_UnitySDKAPI.Haptics.UPvr_HasControllerVibrator())
        {
            if (UseHaptic)
            {
                usingHaptic = true;
                Debug.Log("This platform  supports Haptics");
            }
        }
        else
        {
            UseHaptic = false;
            Debug.Log("This platform didnot support Haptics");
        }
    }
    private float h;
    private float v;
    void Update()
    {
        //获取横轴和纵轴
        h = Input.GetAxis("Horizontal");
        v = Input.GetAxis("Vertical");
        //视野相机进行移动
        if (h != 0)
        {
            Text_1.text = h + "";
            J_Head.transform.root.Translate(J_Head.transform.right * h);
        }


        if (v != 0)
        {
            Text_2.text = v + "";
            J_Head.transform.root.Translate(J_Head.transform.forward * v);
        }








        //获取手柄上的一些按键
        if (Input.GetKeyDown(KeyCode.Joystick1Button0))
        {
            TextTip.text = "AAAAAAAAAAAAA";
        }
        if (Input.GetKeyDown(KeyCode.Joystick1Button1))
        {
            TextTip.text = "BBBBBBBBBBBBB";
        }
        if (Input.GetKeyDown(KeyCode.Joystick1Button2))
        {
            TextTip.text = "XXXXXXXXXXXXX";
        }
        if (Input.GetKeyDown(KeyCode.Joystick1Button3))
        {
            TextTip.text = "YYYYYYYYYYYYY";
        }
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();
        }
        //如果使用触觉
        if (usingHaptic)
        {
        }
    }
    public void Pvr_HasControllerVibrator()
    {
        Pvr_UnitySDKAPI.Haptics.UPvr_HasControllerVibrator();
    }
    public void Pvr_SetControllerVibrateMode()
    {
        //此函数设置每次振动的时间长度
        int[] pattern = new int[5] { vibrationDuration, silienceDuration, repeat_times, vibrationStrength, whichHaptic };
        Pvr_UnitySDKAPI.Haptics.UPvr_SetControllerVibrateMode(pattern, 5, 1);
    }


    public void Pvr_SetControllerVibrateTime()
    {
        //开始振动,并设定强度
        int milliseconds = 2000;
        Pvr_UnitySDKAPI.Haptics.UPvr_SetControllerVibrateTime(milliseconds);
    }


    public void Pvr_CancelControllerVibrate()
    {
        //停止振动
        Pvr_UnitySDKAPI.Haptics.UPvr_CancelControllerVibrate();

    }

}

然后在对按钮添加监听即可

PicoVR开发(一)_第2张图片

当头盔看向UI时,有个杏色小球出现,如无小球出现则查看下是否有小球Pvr_UnitySDK→SightPointer插件中预制体自带的,其次查看下小球尺寸是否过小。

关于手柄开发,等过两天会发布

你可能感兴趣的:(VR,Pico)