🟥 开发的注意事项
1️⃣ 选用的Unity版本
建议2019的Unity版本,之后的版本会取消一些API,导致SDK报错。
2️⃣ 打包的注意事项
该插件打包时应只选用该Graphics API的设定,否则apk会闪退。
🟧 项目基本配置
复制 HelloVR 场景的如下内容到新场景,便完成了基础配置。
后面我们进行交互逻辑的编写即可。
🟨 凝视事件系统
以下是我写的凝视脚本,简化了原有的凝视方式。
将该脚本挂载在带有Collider的物体上,往该脚本公开的Event注册事件即可。
using UnityEngine; using UnityEngine.Events; using UnityEngine.EventSystems; public class SkodeGazeEvent : MonoBehaviour { private EventTrigger myEventTrigger; [Header("长凝视时长")] public float longGazeTime = 2; private float tempGazeTime; public UnityEvent pointerEnterEvent; public UnityEvent pointerExitEvent; public UnityEvent longGazeEvent; private void Awake() { myEventTrigger = GetComponent<EventTrigger>() ?? gameObject.AddComponent<EventTrigger>(); } private void Start() { EventTrigger.Entry entryEnter = new EventTrigger.Entry { eventID = EventTriggerType.PointerEnter, callback = new EventTrigger.TriggerEvent() }; entryEnter.callback.AddListener(PointerEnter); myEventTrigger.triggers.Add(entryEnter); EventTrigger.Entry entryExit = new EventTrigger.Entry { eventID = EventTriggerType.PointerExit, callback = new EventTrigger.TriggerEvent() }; entryExit.callback.AddListener(PointerExit); myEventTrigger.triggers.Add(entryExit); } private void PointerEnter(BaseEventData arg0) { tempGazeTime = longGazeTime; pointerEnterEvent?.Invoke(); } private void PointerExit(BaseEventData arg0) { tempGazeTime = 0; pointerExitEvent?.Invoke(); } private void Update() { if (tempGazeTime <= 0) return; tempGazeTime -= Time.deltaTime; if (tempGazeTime <= 0) { longGazeEvent?.Invoke(); } } }