using UnityEngine; using Unity.Netcode; public class TunnelNode : NetworkBehaviour, IInteractable { public TunnelNode aboveNode; public TunnelNode belowNode; public override void OnNetworkSpawn() { // 모든 클라이언트에서 각자 장부에 등록 Vector3Int myPos = BuildManager.Instance.WorldToGrid3D(transform.position); BuildManager.Instance.RegisterTunnel(myPos, this); // 모든 노드가 등록될 시간을 벌기 위해 서버에서 약간 지연 후 연결 명령 if (IsServer) Invoke(nameof(SyncLinks), 0.2f); } private void SyncLinks() => LinkVerticalRpc(); [Rpc(SendTo.Everyone)] private void LinkVerticalRpc() => LinkVertical(); public void LinkVertical() { Vector3Int myPos = BuildManager.Instance.WorldToGrid3D(transform.position); aboveNode = BuildManager.Instance.GetTunnelAt(myPos + Vector3Int.up); belowNode = BuildManager.Instance.GetTunnelAt(myPos + Vector3Int.down); if (aboveNode != null) aboveNode.belowNode = this; if (belowNode != null) belowNode.aboveNode = this; } public void Interact(GameObject user) { var traveler = user.GetComponent(); if (traveler && !traveler.IsTraveling) traveler.StartTravel(this); } public string GetInteractionText() => "터널 이용 [E]"; }