示例
一把可拾取的工具:拿在手上、按下使用键出光束、松手收起。适合做”手电筒/枪/喷壶”这类东西。
Aeloria Pickup Interactable(可拾取);using UnityEngine;
using Cilbox;
using Aeloria.Scripts.AeloriaSdk.Interactions;
using Aeloria.Scripts.Device_Management.Devices;
[Cilboxable]
public class PickupTool : MonoBehaviour
{
public AeloriaPickupInteractable pickup;
public GameObject beam;
void Start()
{
pickup.OnPickupUse.AddListener(OnUse);
pickup.OnInteractStartEvent.AddListener(OnGrab);
pickup.OnInteractEndEvent.AddListener(OnRelease);
}
void OnDestroy()
{
pickup.OnPickupUse.RemoveAllListeners();
pickup.OnInteractStartEvent.RemoveAllListeners();
pickup.OnInteractEndEvent.RemoveAllListeners();
}
void OnGrab(AeloriaInput input) { }
void OnRelease(AeloriaInput input) { beam.SetActive(false); }
void OnUse(AeloriaPickUpUseMode mode)
{
if (mode == AeloriaPickUpUseMode.OnPickUpUseDown) beam.SetActive(true);
else if (mode == AeloriaPickUpUseMode.OnPickUpUseUp) beam.SetActive(false);
}
}
OnPickupUse 会给出三种模式:按下 OnPickUpUseDown、松开 OnPickUpUseUp、持续按住 OnPickUpStillDown;OnInteractStartEvent / OnInteractEndEvent,回调参数是 AeloriaInput;