示例#1
0
 void DisposeMyNetworkMessageHandler()
 {
     if (networkMessageProcessor != null)
     {
         networkMessageProcessor.Release();
         networkMessageProcessor = null;
     }
 }
示例#2
0
        void GenerateMyNetworkMessageHandler()
        {
            object[] attributes = GetType().GetCustomAttributes(networkMessageProcessUnitAttributeType, true);
            if (attributes.Length >= 1)
            {
#if UNITY_EDITOR
                if (attributes.Length > 1)
                {
                    if (LogUtil.ShowError != null)
                    {
                        LogUtil.ShowError(string.Format("模块[{0}]注册了多个远程消息处理器,只有第一个会生效", GetType().Name));
                    }
                }
#endif
                NetworkMessageProcessUnitAttribute attribute = attributes[0] as NetworkMessageProcessUnitAttribute;
                Type handlerType = attribute.define;
                if (handlerType != null && handlerType.IsSubclassOf(networkMessageProcessUnitType))
                {
                    networkMessageProcessor = (LogicNetworkMessageProcessUnit)Activator.CreateInstance(handlerType);
                    //networkMessageProcessor = handlerType.GetConstructor(Type.EmptyTypes).Invoke(null) as LogicNetworkMessageProcessUnit;
                    FieldInfo fieldHost = networkMessageProcessUnitType.GetField("host", BindingFlags.NonPublic | BindingFlags.Instance);
                    fieldHost.SetValue(networkMessageProcessor, this);
                    MethodInfo method = networkMessageProcessUnitType.GetMethod("OnNetworkMessageProcessUnitInitialized", BindingFlags.NonPublic | BindingFlags.Instance);
                    method.Invoke(networkMessageProcessor, null);
                }
#if UNITY_EDITOR
                else
                {
                    if (LogUtil.ShowError != null)
                    {
                        LogUtil.ShowError(string.Format("模块[{0}]注册的远程消息处理器类型定义错误,远程消息处理器类型需要从NetworkMessageProcessUnit派生", GetType().Name));
                    }
                }
#endif
            }
        }