diff --git a/Runtime/Network/Network/ProtoMessageIdHandler.cs b/Runtime/Network/Network/ProtoMessageIdHandler.cs index 1ad18b9..85bf4b0 100644 --- a/Runtime/Network/Network/ProtoMessageIdHandler.cs +++ b/Runtime/Network/Network/ProtoMessageIdHandler.cs @@ -24,6 +24,12 @@ public static class ProtoMessageIdHandler /// 请求的类型 public static Type GetReqTypeById(int messageId) { + if (ReqDictionary.Count <= 0) + { + Log.Warning("请先确认是否初始化 调用 ProtoMessageIdHandler.Init()"); + return null; + } + ReqDictionary.TryGetValue(messageId, out var value); return value; } @@ -35,6 +41,12 @@ public static Type GetReqTypeById(int messageId) /// 请求消息ID public static int GetReqMessageIdByType(Type type) { + if (ReqDictionary.Count <= 0) + { + Log.Warning("请先确认是否初始化 调用 ProtoMessageIdHandler.Init()"); + return 0; + } + ReqDictionary.TryGetKey(type, out var value); return value; } @@ -46,6 +58,12 @@ public static int GetReqMessageIdByType(Type type) /// 响应的类型 public static Type GetRespTypeById(int messageId) { + if (RespDictionary.Count <= 0) + { + Log.Warning("请先确认是否初始化 调用 ProtoMessageIdHandler.Init()"); + return null; + } + RespDictionary.TryGetValue(messageId, out var value); return value; } @@ -57,6 +75,12 @@ public static Type GetRespTypeById(int messageId) /// 响应消息ID public static int GetRespMessageIdByType(Type type) { + if (RespDictionary.Count <= 0) + { + Log.Warning("请先确认是否初始化 调用 ProtoMessageIdHandler.Init()"); + return 0; + } + RespDictionary.TryGetKey(type, out var value); return value; }