using Unity.Entities; using UnityEngine; using UnityEngine.XR.Interaction.Toolkit; using UnityEngine.XR.Interaction.Toolkit.Interactables; namespace jeanf.universalplayer { /// /// A plain GameObject stand-in for a baked seat: an ordinary PhysX /// the desktop raycast can hit, an a VR controller ray can /// select, plus the seat's so treats it /// exactly like a classic . There is no ECS collider anywhere — the entity is /// pure data and this proxy is what physics/XRI actually see. Placed by . /// [RequireComponent(typeof(BoxCollider))] public class SeatProxy : MonoBehaviour, ISeatSource { public Entity SeatEntity { get; private set; } private SeatData _data; private XRSimpleInteractable _interactable; private bool _occupied; public bool IsOccupied => _occupied; public void SetOccupied(bool occupied) => _occupied = occupied; /// Seats are static, so the pose is captured once at placement. public void Bind(Entity entity, in SeatData data) { SeatEntity = entity; _data = data; } public SeatData GetSeatData() => _data; // VR parity (Universal Player: every action works in MKB/gamepad/VR): a controller-ray // select sits, mirroring how the classic Seat auto-wires an XRSimpleInteractable. Desktop // and gamepad still sit through SitController's own raycast on the BoxCollider below. private void Awake() { _interactable = gameObject.AddComponent(); _interactable.selectEntered.AddListener(OnSelectEntered); _interactable.hoverEntered.AddListener(OnHoverEntered); _interactable.hoverExited.AddListener(OnHoverExited); } private void OnDestroy() { if (_interactable == null) return; _interactable.selectEntered.RemoveListener(OnSelectEntered); _interactable.hoverEntered.RemoveListener(OnHoverEntered); _interactable.hoverExited.RemoveListener(OnHoverExited); } // Sit-only (mirrors the classic Seat): grab/trigger only sits. Standing is the stick (VR) / jump+move (desktop). private void OnSelectEntered(SelectEnterEventArgs _) { if (SitController.Instance != null) SitController.Instance.SitOn(this); } private void OnHoverEntered(HoverEnterEventArgs _) => SitController.Instance?.NotifySeatHoverEntered(this); private void OnHoverExited(HoverExitEventArgs _) => SitController.Instance?.NotifySeatHoverExited(this); } }