void DisposeMyLocalMessageHandler() { if (localMessageProcessor != null) { localMessageProcessor.Release(); localMessageProcessor = null; } }
void GenerateMyLocalMessageHandler() { object[] attributes = GetType().GetCustomAttributes(messageProcessUnitAttributeType, true); if (attributes.Length >= 1) { #if UNITY_EDITOR if (attributes.Length > 1) { if (LogUtil.ShowError != null) { LogUtil.ShowError(string.Format("模块[{0}]注册了多个消息处理器,只有第一个会生效", GetType().Name)); } } #endif MessageProcessUnitAttribute attribute = attributes[0] as MessageProcessUnitAttribute; Type handlerType = attribute.define; if (handlerType != null && handlerType.IsSubclassOf(messageProcessUnitType)) { localMessageProcessor = (LogicMessageProcessUnit)Activator.CreateInstance(handlerType); //localMessageProcessor = handlerType.GetConstructor(Type.EmptyTypes).Invoke(null) as LogicMessageProcessUnit; FieldInfo fieldHost = messageProcessUnitType.GetField("host", BindingFlags.NonPublic | BindingFlags.Instance); fieldHost.SetValue(localMessageProcessor, this); MethodInfo method = messageProcessUnitType.GetMethod("OnMessageProcessUnitInitialized", BindingFlags.NonPublic | BindingFlags.Instance); method.Invoke(localMessageProcessor, null); } #if UNITY_EDITOR else { if (LogUtil.ShowError != null) { LogUtil.ShowError(string.Format("模块[{0}]注册的消息处理器类型定义错误,消息处理器类型需要从MessageProcessUnit派生", GetType().Name)); } } #endif } }