public void Awake() { this.opcodeTypes.Clear(); this.typeOpcodes.Clear(); this.requestResponse.Clear(); HashSet <Type> types = Game.EventSystem.GetTypes(typeof(MessageAttribute)); foreach (Type type in types) { object[] attrs = type.GetCustomAttributes(typeof(MessageAttribute), false); if (attrs.Length == 0) { continue; } MessageAttribute messageAttribute = attrs[0] as MessageAttribute; if (messageAttribute == null) { continue; } this.opcodeTypes.Add(messageAttribute.Opcode, type); this.typeOpcodes.Add(type, messageAttribute.Opcode); if (OpcodeHelper.IsOuterMessage(messageAttribute.Opcode) && typeof(IActorMessage).IsAssignableFrom(type)) { this.outrActorMessage.Add(messageAttribute.Opcode); } // 检查request response if (typeof(IRequest).IsAssignableFrom(type)) { if (typeof(IActorLocationMessage).IsAssignableFrom(type)) { this.requestResponse.Add(type, typeof(ActorResponse)); continue; } attrs = type.GetCustomAttributes(typeof(ResponseTypeAttribute), false); if (attrs.Length == 0) { Log.Error($"not found responseType: {type}"); continue; } ResponseTypeAttribute responseTypeAttribute = attrs[0] as ResponseTypeAttribute; #if SERVER this.requestResponse.Add(type, responseTypeAttribute.Type); #else this.requestResponse.Add(type, Type.GetType(responseTypeAttribute.Type)); #endif } } }
public override void Awake(OpcodeTypeComponent self) { OpcodeTypeComponent.Instance = self; self.opcodeTypes.Clear(); self.typeOpcodes.Clear(); self.requestResponse.Clear(); List <Type> types = Game.EventSystem.GetTypes(typeof(MessageAttribute)); foreach (Type type in types) { object[] attrs = type.GetCustomAttributes(typeof(MessageAttribute), false); if (attrs.Length == 0) { continue; } MessageAttribute messageAttribute = attrs[0] as MessageAttribute; if (messageAttribute == null) { continue; } self.opcodeTypes.Add(messageAttribute.Opcode, type); self.typeOpcodes.Add(type, messageAttribute.Opcode); if (OpcodeHelper.IsOuterMessage(messageAttribute.Opcode) && typeof(IActorMessage).IsAssignableFrom(type)) { self.outrActorMessage.Add(messageAttribute.Opcode); } // 检查request response if (typeof(IRequest).IsAssignableFrom(type)) { if (typeof(IActorLocationMessage).IsAssignableFrom(type)) { self.requestResponse.Add(type, typeof(ActorResponse)); continue; } attrs = type.GetCustomAttributes(typeof(ResponseTypeAttribute), false); if (attrs.Length == 0) { Log.Error($"not found responseType: {type}"); continue; } ResponseTypeAttribute responseTypeAttribute = attrs[0] as ResponseTypeAttribute; self.requestResponse.Add(type, Game.EventSystem.GetType($"ET.{responseTypeAttribute.Type}")); } } }