承接ARVR外包项目 史小川QQ: 2118590660
ARVR行业交流QQ群:750656715
公众号: ARVR行业领跑者
B站: ARVRinChina
1. 直接将Player 预制件拖到场景里
2.在LeftHand/ RightHand 上添加脚本
Steam VR_Laser Pointe (插件里自带)
Steam VR Laser Wrapper(自己写的,封装一层,让按钮事件按原来Untiy的交互方式执行)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using Valve.VR.Extras;
public class SteamVRLaserWrapper : MonoBehaviour
{
private SteamVR_LaserPointer steamVrLaserPointer;
private void Awake()
{
steamVrLaserPointer = gameObject.GetComponent();
steamVrLaserPointer.PointerIn += OnPointerIn;
steamVrLaserPointer.PointerOut += OnPointerOut;
steamVrLaserPointer.PointerClick += OnPointerClick;
}
private void OnPointerClick(object sender, PointerEventArgs e)
{
IPointerClickHandler clickHandler = e.target.GetComponent();
if (clickHandler == null)
{
return;
}
clickHandler.OnPointerClick(new PointerEventData(EventSystem.current));
}
private void OnPointerOut(object sender, PointerEventArgs e)
{
IPointerExitHandler pointerExitHandler = e.target.GetComponent();
if (pointerExitHandler == null)
{
return;
}
pointerExitHandler.OnPointerExit(new PointerEventData(EventSystem.current));
}
private void OnPointerIn(object sender, PointerEventArgs e)
{
IPointerEnterHandler pointerEnterHandler = e.target.GetComponent();
if (pointerEnterHandler == null)
{
return;
}
pointerEnterHandler.OnPointerEnter(new PointerEventData(EventSystem.current));
}
}
3. 按钮高亮, 事件了, 自己设置,就是正常的button设置,正常的关联方法