public static void NoticeUnitAdd(Unit unit, Unit sendUnit) { M2C_CreateUnits createUnits = new M2C_CreateUnits(); createUnits.Units.Add(CreateUnitInfo(sendUnit)); MessageHelper.SendToClient(unit, createUnits); }
protected override async ETTask Run(Scene scene, G2M_CreateUnit request, M2G_CreateUnit response, Action reply) { Unit unit = EntityFactory.CreateWithId <Unit>(scene, IdGenerater.GenerateId()); unit.AddComponent <MoveComponent>(); unit.AddComponent <UnitPathComponent>(); unit.Position = new Vector3(-10, 0, -10); unit.AddComponent <MailBoxComponent>(); await unit.AddLocation(); unit.AddComponent <UnitGateComponent, long>(request.GateSessionId); scene.GetComponent <UnitComponent>().Add(unit); response.UnitId = unit.Id; // 广播创建的unit M2C_CreateUnits createUnits = new M2C_CreateUnits(); Unit[] units = scene.GetComponent <UnitComponent>().GetAll(); foreach (Unit u in units) { UnitInfo unitInfo = new UnitInfo(); unitInfo.X = u.Position.x; unitInfo.Y = u.Position.y; unitInfo.Z = u.Position.z; unitInfo.UnitId = u.Id; createUnits.Units.Add(unitInfo); } MessageHelper.Broadcast(unit, createUnits); reply(); }
protected override async ETTask Run(Scene scene, G2M_CreateUnit request, M2G_CreateUnit response, Action reply) { Unit unit = EntityFactory.CreateWithId <Unit, int>(scene, 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); scene.GetComponent <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(); }
protected override async ETTask Run(Scene scene, G2M_CreateUnit request, M2G_CreateUnit response, Action reply) { UnitComponent unitComponent = scene.GetComponent <UnitComponent>(); Unit unit = unitComponent.AddChildWithId <Unit, int>(IdGenerater.Instance.GenerateId(), 1001); unit.AddComponent <MoveComponent>(); unit.AddComponent <PathfindingComponent, string>("solo"); unit.Position = new Vector3(-10, 0, -10); NumericComponent numericComponent = unit.AddComponent <NumericComponent>(); numericComponent.Set(NumericType.Speed, 6f); // 速度是6米每秒 numericComponent.Set(NumericType.AOI, 15000); // 视野15米 unit.AddComponent <MailBoxComponent>(); await unit.AddLocation(); unit.AddComponent <UnitGateComponent, long>(request.GateSessionId); unitComponent.Add(unit); // 加入aoi unit.AddComponent <AOIEntity, int, Vector3>(9 * 1000, unit.Position); M2C_CreateUnits m2CCreateUnits = new M2C_CreateUnits(); m2CCreateUnits.Units.Add(UnitHelper.CreateUnitInfo(unit)); MessageHelper.SendToClient(unit, m2CCreateUnits); response.MyId = unit.Id; reply(); }