示例
VR 里用手指去按的按钮。用一个带碰撞体的物体挂上 AeloriaInteractableShim,脚本订阅 ButtonDown 即可。
Aeloria Interactable Shim 组件;using UnityEngine;
using Cilbox;
using Aeloria.Shims;
[Cilboxable]
public class TouchButton : MonoBehaviour
{
public AeloriaInteractableShim buttonShim;
public GameObject lamp;
void Start()
{
buttonShim.ButtonDown += OnPress;
}
void OnDestroy()
{
if (buttonShim != null) buttonShim.ButtonDown -= OnPress;
}
void OnPress()
{
lamp.SetActive(!lamp.activeSelf);
}
}
需要区分”按下”和”松开”时,再订阅 ButtonUp;两个都是无参数的回调。
交互 shim 只在世界 / 道具沙盒里允许,虚拟形象脚本用不了。