public static Unit Create(Entity domain, UnitInfo unitInfo) { UnitComponent unitComponent = domain.GetComponent <UnitComponent>(); Unit unit = Entity.CreateWithId <Unit, int>(unitComponent, unitInfo.UnitId, unitInfo.ConfigId); unitComponent.Add(unit); unit.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z); unit.AddComponent <MoveComponent>(); NumericComponent numericComponent = unit.AddComponent <NumericComponent>(); for (int i = 0; i < unitInfo.Ks.Count; ++i) { numericComponent.Set((NumericType)unitInfo.Ks[i], unitInfo.Vs[i]); } unit.AddComponent <ObjectWait>(); unit.AddComponent <XunLuoPathComponent>(); Game.EventSystem.Publish(new EventType.AfterUnitCreate() { Unit = unit }); return(unit); }
// 这个channelId是由CreateAcceptChannelId生成的 public static void OnAccept(this NetInnerComponent self, long channelId, IPEndPoint ipEndPoint) { Session session = Entity.CreateWithId <Session, AService>(self, channelId, self.Service); session.RemoteAddress = ipEndPoint; //session.AddComponent<SessionIdleCheckerComponent, int, int, int>(NetThreadComponent.checkInteral, NetThreadComponent.recvMaxIdleTime, NetThreadComponent.sendMaxIdleTime); }
public override void Awake(CoroutineLockComponent self) { CoroutineLockComponent.Instance = self; for (int i = 0; i < self.list.Capacity; ++i) { self.list.Add(Entity.CreateWithId <CoroutineLockQueueType>(self, ++self.idGenerator)); } }
// 这个channelId是由CreateAcceptChannelId生成的 public static void OnAccept(this NetKcpComponent self, long channelId, IPEndPoint ipEndPoint) { Session session = Entity.CreateWithId <Session, AService>(self, channelId, self.Service); session.RemoteAddress = ipEndPoint; session.AddComponent <SessionAcceptTimeoutComponent>(); // 客户端连接,2秒检查一次recv消息,10秒没有消息则断开 session.AddComponent <SessionIdleCheckerComponent, int>(NetThreadComponent.checkInteral); }
public static CoroutineLock CreateCoroutineLock(this CoroutineLockComponent self, CoroutineLockType coroutineLockType, long key, int time, int count) { CoroutineLock coroutineLock = Entity.CreateWithId <CoroutineLock, CoroutineLockType, long, int>(self, ++self.idGenerator, coroutineLockType, key, count, true); if (time > 0) { self.AddTimer(TimeHelper.ClientFrameTime() + time, coroutineLock); } return(coroutineLock); }
public static Session Create(this NetKcpComponent self, IPEndPoint realIPEndPoint) { long channelId = RandomHelper.RandInt64(); Session session = Entity.CreateWithId <Session, AService>(self, channelId, self.Service); session.RemoteAddress = realIPEndPoint; session.AddComponent <SessionIdleCheckerComponent, int>(NetThreadComponent.checkInteral); self.Service.GetOrCreate(session.Id, realIPEndPoint); return(session); }
private static Session CreateInner(this NetInnerComponent self, long channelId, IPEndPoint ipEndPoint) { Session session = Entity.CreateWithId <Session, AService>(self, channelId, self.Service); session.RemoteAddress = ipEndPoint; self.Service.GetOrCreate(channelId, ipEndPoint); //session.AddComponent<InnerPingComponent>(); //session.AddComponent<SessionIdleCheckerComponent, int, int, int>(NetThreadComponent.checkInteral, NetThreadComponent.recvMaxIdleTime, NetThreadComponent.sendMaxIdleTime); return(session); }
private static ActorLocationSender GetOrCreate(this ActorLocationSenderComponent self, long id) { if (id == 0) { throw new Exception($"actor id is 0"); } if (self.Children.TryGetValue(id, out Entity actorLocationSender)) { return((ActorLocationSender)actorLocationSender); } actorLocationSender = Entity.CreateWithId <ActorLocationSender>(self, id); return((ActorLocationSender)actorLocationSender); }
public static async ETTask <CoroutineLock> Wait(this CoroutineLockComponent self, CoroutineLockType coroutineLockType, long key, int time = 60000) { CoroutineLockQueueType coroutineLockQueueType = self.list[(int)coroutineLockType]; if (!coroutineLockQueueType.TryGetValue(key, out CoroutineLockQueue queue)) { coroutineLockQueueType.Add(key, Entity.CreateWithId <CoroutineLockQueue>(self, ++self.idGenerator, true)); return(self.CreateCoroutineLock(coroutineLockType, key, time, 1)); } ETTask <CoroutineLock> tcs = ETTask <CoroutineLock> .Create(true); queue.Add(tcs, time); return(await tcs); }
protected override async ETTask Run(Scene scene, G2M_CreateUnit request, M2G_CreateUnit response, Action reply) { UnitComponent unitComponent = scene.GetComponent <UnitComponent>(); Unit unit = Entity.CreateWithId <Unit, int>(unitComponent, IdGenerater.Instance.GenerateId(), 1001); unit.AddComponent <MoveComponent>(); unit.Position = new Vector3(-10, 0, -10); NumericComponent numericComponent = unit.AddComponent <NumericComponent>(); numericComponent.Set(NumericType.Speed, 6f); // 速度是6米每秒 unit.AddComponent <MailBoxComponent>(); await unit.AddLocation(); unit.AddComponent <UnitGateComponent, long>(request.GateSessionId); unitComponent.Add(unit); response.UnitId = unit.Id; // 把自己广播给周围的人 M2C_CreateUnits createUnits = new M2C_CreateUnits(); createUnits.Units.Add(UnitHelper.CreateUnitInfo(unit)); MessageHelper.Broadcast(unit, createUnits); // 把周围的人通知给自己 createUnits.Units.Clear(); Unit[] units = scene.GetComponent <UnitComponent>().GetAll(); foreach (Unit u in units) { createUnits.Units.Add(UnitHelper.CreateUnitInfo(u)); } MessageHelper.SendActor(unit.GetComponent <UnitGateComponent>().GateSessionActorId, createUnits); reply(); }