public void OnEnable() { if (manager != null) { Destroy(gameObject); } else { manager = this; Enable(); } }
// Send packet again or disconnect player which does not respond public void ResendPacket() { resendTimes++; timeoutTime = 0; if (resendTimes >= MAX_TIMES_SEND) { Debug.LogError("Message never got confirmed, dropping packet: " + packetId + " -=- Type: " + packet.type); fail?.Invoke(this); // Ping peer to check if still connected Peer peerToPing = null; if (packet != null) { peerToPing = MultiplayerManager.peerManager?.GetPeerWithIp(packet.ip, packet.port); } if (peerToPing != null) { // Delete player if (packet.type == PacketType.ping) { MultiplayerManager.InvokeDisconnect(peerToPing.id); MultiplayerManager.SendDisconnection(peerToPing, false); // Ping again } else { peerToPing.Ping(); } } // Remove the packet from the waiting line MultiplayerManager.sender.RemoveWaitingPacket(this); } else { Debug.LogError("Resending packet: " + packetId + " -=- Times send: " + resendTimes); MultiplayerManager.sender.QueuePacket(packet, null, null, false); } }