SteamVR 设置进入UI 射线显示, 出了UI 射线不显示

 

SteamVR  设置进入UI 直 射线显示, teleporting不显示

出了UI 射线不显示, teleporting显示

我是直接在之前, 封装射线检测信息里面加的代码

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using Valve.VR.Extras;
using Valve.VR;
using Valve.VR.InteractionSystem;
public class SteamVRLaserWrapper : MonoBehaviour
{
    private SteamVR_LaserPointer steamVrLaserPointer;

    //sxc
    private Hand hand;

    private void Awake()
    {
        steamVrLaserPointer = gameObject.GetComponent<SteamVR_LaserPointer>();
        steamVrLaserPointer.PointerIn += OnPointerIn;
        steamVrLaserPointer.PointerOut += OnPointerOut;
        steamVrLaserPointer.PointerClick += OnPointerClick;
        //sxc
        steamVrLaserPointer.thickness = 0f;

        if (hand == null)
        {
            hand = this.GetComponent<Hand>();
        }
    }

    void Update()
    {
        //TouchPress按下的时候是瞬移射线, 不显示UI直射线
        if (SteamVR_Input.GetState("default", "Teleport", hand.handType))
        {
            Debug.Log("Teleport");
            steamVrLaserPointer.thickness = 0f;
        }
    }
    private void OnPointerClick(object sender, PointerEventArgs e)
    {
        IPointerClickHandler clickHandler = e.target.GetComponent<IPointerClickHandler>();
        if (clickHandler == null)
        {
            return;
        }
        clickHandler.OnPointerClick(new PointerEventData(EventSystem.current));
    }

    private void OnPointerOut(object sender, PointerEventArgs e)
    {
        //sxc
        steamVrLaserPointer.thickness = 0f;

        IPointerExitHandler pointerExitHandler = e.target.GetComponent<IPointerExitHandler>();
        if (pointerExitHandler == null)
        {
            return;
        }

        pointerExitHandler.OnPointerExit(new PointerEventData(EventSystem.current));
    }

    private void OnPointerIn(object sender, PointerEventArgs e)
    {
        //sxc
        steamVrLaserPointer.thickness = 0.002f;
   
        IPointerEnterHandler pointerEnterHandler = e.target.GetComponent<IPointerEnterHandler>();
        if (pointerEnterHandler == null)
        {
            return;
        }
        pointerEnterHandler.OnPointerEnter(new PointerEventData(EventSystem.current));
    }

}

原来代码的作用: https://blog.csdn.net/chuan403082010/article/details/95166998

 

©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页