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, M2M_UnitTransferRequest request, M2M_UnitTransferResponse response, Action reply) { await ETTask.CompletedTask; UnitComponent unitComponent = scene.GetComponent <UnitComponent>(); Unit unit = request.Unit; unitComponent.AddChild(unit); unitComponent.Add(unit); foreach (Entity entity in request.Entitys) { unit.AddComponent(entity); } unit.AddComponent <MoveComponent>(); unit.AddComponent <PathfindingComponent, string>(scene.Name); unit.Position = new Vector3(-10, 0, -10); unit.AddComponent <MailBoxComponent>(); // 通知客户端创建My Unit M2C_CreateMyUnit m2CCreateUnits = new M2C_CreateMyUnit(); m2CCreateUnits.Unit = UnitHelper.CreateUnitInfo(unit); MessageHelper.SendToClient(unit, m2CCreateUnits); // 加入aoi unit.AddComponent <AOIEntity, int, Vector3>(9 * 1000, unit.Position); response.NewInstanceId = unit.InstanceId; 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(); }
protected override async ETTask Run(Scene scene, M2M_UnitTransferRequest request, M2M_UnitTransferResponse response, Action reply) { await ETTask.CompletedTask; UnitComponent unitComponent = scene.GetComponent <UnitComponent>(); Unit unit = request.Unit; unitComponent.AddChild(unit); unitComponent.Add(unit); foreach (var item in request.Map) { var entity = request.Entitys[item.ChildIndex]; Entity parent; if (item.ParentIndex == -1) //父组件为自己 { parent = unit; } else { parent = request.Entitys[item.ParentIndex]; } if (item.IsChild == 0) { parent.AddComponent(entity); } else { parent.AddChild(entity); } } unit.AddComponent <MoveComponent>(); unit.AddComponent <PathfindingComponent, string>(scene.Name); unit.Position = new Vector3(-10, 0, -10); unit.AddComponent <MailBoxComponent>(); // 通知客户端创建My Unit M2C_CreateMyUnit m2CCreateUnits = new M2C_CreateMyUnit(); m2CCreateUnits.Unit = UnitHelper.CreateUnitInfo(unit); MessageHelper.SendToClient(unit, m2CCreateUnits); var numericComponent = unit.GetComponent <NumericComponent>(); // 加入aoi var aoiu = unit.AddComponent <AOIUnitComponent, Vector3, Quaternion, UnitType, int> (unit.Position, unit.Rotation, UnitType.Player, numericComponent.GetAsInt(NumericType.AOI)); aoiu.AddSphereTrigger(0.5f, AOITriggerType.None, null, true); response.NewInstanceId = unit.InstanceId; reply(); }