public override void Awake() { var types = ObjectTypeStorage.GetTypes <BaseActor>(); foreach (var type in types) { using (var component = ObjectStorage.Fetch(type) as BaseActorComponent) { ActorTypes[component.ActorType] = type; } } this.Distributions = Game.Scene.AddComponent <NetDistributionsComponent>(); this.Distributions.OnDisconnected += network => { if (!NetIdActors.TryGetValue(network.Id, out Dictionary <int, BaseActorComponent> dicVal)) { return; } this.OnDisconnected?.Invoke(network); var acotrs = dicVal.Values.ToList(); foreach (var acotr in acotrs) { acotr.Dispose(); } }; this.Distributions.OnConnected += network => { this.OnConnected?.Invoke(network); network.Send((ushort)MSGCommand.SyncActorInfoCmd); }; }
private void AddComponent(Type type, DBConfigEntity sysConfig, DBConfigEntity logConfig, MongoClient sysDbClient, MongoClient logDbClient, IMongoDatabase sysDb, IMongoDatabase logDb) { if (!typeof(IRpository).IsAssignableFrom(type)) { return; } var isSingle = ObjectStorage.IsSingleType(type); if (!isSingle) { throw new ComponentException("规定Rpository类型组件只能定义成单例(SingleCase)组件。"); } var component = ObjectStorage.Fetch(type); var rpository = component as IRpository; if (rpository.DBType == DBType.SysDb) { rpository.SetDBContext(sysDb, sysConfig.DatabaseName, sysDbClient); Game.Scene.AddComponent(component); } else if (rpository.DBType == DBType.LoggerDb) { rpository.SetDBContext(logDb, logConfig.DatabaseName, logDbClient); Game.Scene.AddComponent(component); } }