ClientHandshakeController.cs 915 B

1234567891011121314151617181920212223242526272829303132
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using KairoEngine.Core;
  5. namespace KairoEngine.Multiplayer
  6. {
  7. public class ClientHandshakeController : MonoBehaviour
  8. {
  9. public ClientBehaviour client;
  10. private void Awake()
  11. {
  12. GenericEvents.StartListening($"{client.eventStreamName}_Connected", OnEvent);
  13. }
  14. private void OnDestroy()
  15. {
  16. GenericEvents.StopListening($"{client.eventStreamName}_Connected", OnEvent);
  17. }
  18. private void OnEvent(string text)
  19. {
  20. if(client == null) return;
  21. NetHandshakeMsg handshakeMsg = new NetHandshakeMsg();
  22. handshakeMsg.playerName = client.playerName;
  23. Timer.ExecuteRealTime(100, ()=> {
  24. client.SendNetMsgToServer(((uint)NetOpCode.Handshake), handshakeMsg);
  25. });
  26. }
  27. }
  28. }