示例
让一个物体(头灯、名牌、跟随特效)贴着本地玩家的头部走。用 OnBeforeRender 更新位置,比 Update 更贴合当前帧,VR 里不会拖影。
using UnityEngine;
using Cilbox;
using Aeloria.Shims;
using Aeloria.Scripts.AeloriaSdk.Players;
[Cilboxable]
public class HeadLamp : MonoBehaviour
{
void Start()
{
GetComponent<AeloriaBeforeRenderShim>();
}
void OnBeforeRender()
{
IAeloriaPlayer local = AeloriaPlayersShim.Local;
if (local == null) return;
transform.position = local.GetBonePosition(HumanBodyBones.Head);
transform.rotation = local.GetBoneRotation(HumanBodyBones.Head);
}
}
AeloriaPlayersShim.Local 是本地玩家;位置/旋转都是**拷贝值**,不会把 Transform 交出去;HumanBodyBones.Head 换成 HumanBodyBones.LeftHand / RightHand;