ClientSyncAjustmentSystem.cs 905 B

12345678910111213141516171819202122232425262728293031
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using KairoEngine.Core;
  5. using Sirenix.OdinInspector;
  6. namespace KairoEngine.Multiplayer
  7. {
  8. [HideMonoScript]
  9. public class ClientSyncAjustmentSystem : MonoBehaviour
  10. {
  11. public ClientBehaviour client;
  12. private void OnEnable()
  13. {
  14. NetMsgEvents.StartListening($"{client.eventStreamName}_PingReceived", OnPingReceived);
  15. }
  16. private void OnDisable()
  17. {
  18. NetMsgEvents.StopListening($"{client.eventStreamName}_PingReceived", OnPingReceived);
  19. }
  20. private void OnPingReceived(string text, int clientId, uint code, NetMsg netMsg)
  21. {
  22. NetPingMsg pingMsg = (NetPingMsg)netMsg;
  23. NetPongMsg pongMsg = new NetPongMsg(pingMsg.pingId);
  24. client.SendNetMsgToServer((uint)NetOpCode.Pong, pongMsg);
  25. }
  26. }
  27. }