DemoHandlers.cs 703 B

123456789101112131415161718192021222324252627282930
  1. using System;
  2. using UnityEngine;
  3. using ZSocket;
  4. /// <summary>
  5. /// 监听消息, MsgType监听消息类型
  6. /// </summary>
  7. [MessageHandler(MsgType = "DEMO_MSG_REQ")]
  8. public class DemoMessageHandler : AMessageHandler
  9. {
  10. protected override void Handle(string msg)
  11. {
  12. Debug.Log($"Demo Handle Msg: {msg}");
  13. }
  14. }
  15. /// <summary>
  16. /// 监听RPC消息,RecvMsgType为监听的消息类型,ReplyMsgType为回复的消息类型
  17. /// </summary>
  18. [RpcHandler(RecvMsgType = "DEMO_RPC_REQ", ReplyMsgType = "DEMO_RPC_RESP")]
  19. public class DemoRpcHandler : ARpcHandler
  20. {
  21. protected override void Handle(string inMsg, Action<string> reply)
  22. {
  23. Debug.Log($"Demo Handle Rpc: {inMsg}");
  24. reply.Invoke(inMsg);
  25. }
  26. }