public static Unit Create(Entity domain, UnitInfo unitInfo) { UnitComponent unitComponent = domain.GetComponent <UnitComponent>(); Unit unit = unitComponent.AddChildWithId <Unit, int>(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 }).Coroutine(); return(unit); }
public static Unit Create(Scene scene, long id, UnitType unitType) { UnitComponent unitComponent = scene.GetComponent <UnitComponent>(); switch (unitType) { case UnitType.Player: { Unit unit = unitComponent.AddChildWithId <Unit, int>(id, 1001); unit.AddComponent <MoveComponent>(); unit.Position = new Vector3(-10, 0, -10); NumericComponent numericComponent = unit.AddComponent <NumericComponent>(); numericComponent.Set(NumericType.Speed, 6f); // 速度是6米每秒 numericComponent.Set(NumericType.AOI, 15000); // 视野15米 unitComponent.Add(unit); // 加入aoi unit.AddComponent <AOIEntity, int, Vector3>(9 * 1000, unit.Position); return(unit); } default: throw new Exception($"not such unit type: {unitType}"); } }
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(); }
public static Unit Create(Scene currentScene, UnitInfo unitInfo) { UnitComponent unitComponent = currentScene.GetComponent <UnitComponent>(); Unit unit = unitComponent.AddChildWithId <Unit, int>(unitInfo.UnitId, unitInfo.ConfigId); unitComponent.Add(unit); unit.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z); unit.Forward = new Vector3(unitInfo.ForwardX, unitInfo.ForwardY, unitInfo.ForwardZ); NumericComponent numericComponent = unit.AddComponent <NumericComponent>(); for (int i = 0; i < unitInfo.Ks.Count; ++i) { numericComponent.Set(unitInfo.Ks[i], unitInfo.Vs[i]); } unit.AddComponent <MoveComponent>(); if (unitInfo.MoveInfo != null) { if (unitInfo.MoveInfo.X.Count > 0) { using (ListComponent <Vector3> list = ListComponent <Vector3> .Create()) { list.Add(unit.Position); for (int i = 0; i < unitInfo.MoveInfo.X.Count; ++i) { list.Add(new Vector3(unitInfo.MoveInfo.X[i], unitInfo.MoveInfo.Y[i], unitInfo.MoveInfo.Z[i])); } unit.MoveToAsync(list).Coroutine(); } } } unit.AddComponent <ObjectWait>(); unit.AddComponent <XunLuoPathComponent>(); Game.EventSystem.Publish(new EventType.AfterUnitCreate() { Unit = unit }); return(unit); }
public static Unit Create(Scene scene, long id, UnitType unitType) { UnitComponent unitComponent = scene.GetComponent <UnitComponent>(); switch (unitType) { case UnitType.Player: { Unit unit = unitComponent.AddChildWithId <Unit, int>(id, 1); //ChildType测试代码 取消注释 编译Server.hotfix 可发现报错 //unitComponent.AddChild<Player, string>("Player"); unit.AddComponent <MoveComponent>(); unit.Position = new Vector3(-10, 0, -10); NumericComponent numericComponent = unit.AddComponent <NumericComponent>(); numericComponent.Set(NumericType.SpeedBase, 6f); // 速度是6米每秒 numericComponent.Set(NumericType.AOIBase, 2); // 视野2格 numericComponent.Set(NumericType.HpBase, 1000); // 生命1000 numericComponent.Set(NumericType.MaxHpBase, 1000); // 最大生命1000 numericComponent.Set(NumericType.LvBase, 1); //1级 numericComponent.Set(NumericType.ATKBase, 100); //100攻击 numericComponent.Set(NumericType.DEFBase, 500); //500防御 var SkillIds = new List <int>() { 1001, 1002, 1003, 1004 }; //初始技能 unit.AddComponent <CombatUnitComponent, List <int> >(SkillIds); unitComponent.Add(unit); // 进入地图再加入aoi return(unit); } default: throw new Exception($"not such unit type: {unitType}"); } }
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.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(); }
public static Unit Create(Scene currentScene, UnitInfo unitInfo) { UnitComponent unitComponent = currentScene.GetComponent <UnitComponent>(); Unit unit = unitComponent.AddChildWithId <Unit, int>(unitInfo.UnitId, unitInfo.ConfigId); unitComponent.Add(unit); unit.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z); unit.Forward = new Vector3(unitInfo.ForwardX, unitInfo.ForwardY, unitInfo.ForwardZ); switch (unit.Type) { case UnitType.Monster: case UnitType.Player: { NumericComponent numericComponent = unit.AddComponent <NumericComponent>(); for (int i = 0; i < unitInfo.Ks.Count; ++i) { if (unitInfo.Ks[i] > NumericType.Max) //不需要同步最终值 { numericComponent.Set(unitInfo.Ks[i], unitInfo.Vs[i], true); } } unit.AddComponent <MoveComponent>(); if (unitInfo.MoveInfo != null) { if (unitInfo.MoveInfo.X.Count > 0) { using (ListComponent <Vector3> list = ListComponent <Vector3> .Create()) { list.Add(unit.Position); for (int i = 0; i < unitInfo.MoveInfo.X.Count; ++i) { list.Add(new Vector3(unitInfo.MoveInfo.X[i], unitInfo.MoveInfo.Y[i], unitInfo.MoveInfo.Z[i])); } unit.MoveToAsync(list).Coroutine(); } } } unit.AddComponent <AOIUnitComponent, Vector3, Quaternion, UnitType>(unit.Position, unit.Rotation, unit.Type); CombatUnitComponent combatU; if (unitInfo.SkillIds != null) { combatU = unit.AddComponent <CombatUnitComponent, List <int> >(unitInfo.SkillIds); } else { combatU = unit.AddComponent <CombatUnitComponent>(); } if (unitInfo.BuffIds != null && unitInfo.BuffIds.Count > 0) { var buffC = combatU.GetComponent <BuffComponent>(); buffC.Init(unitInfo.BuffIds, unitInfo.BuffTimestamp); } unit.AddComponent <ObjectWait>(); unit.AddComponent <XunLuoPathComponent>(); break; } case UnitType.Skill: { NumericComponent numericComponent = unit.AddComponent <NumericComponent>(); if (unitInfo.Ks != null && unitInfo.Ks.Count > 0) { for (int i = 0; i < unitInfo.Ks.Count; ++i) { if (unitInfo.Ks[i] > NumericType.Max) //不需要同步最终值 { numericComponent.Set(unitInfo.Ks[i], unitInfo.Vs[i], true); } } } unit.AddComponent <MoveComponent>(); if (unitInfo.MoveInfo != null && unitInfo.MoveInfo.X.Count > 0) { using (ListComponent <Vector3> list = ListComponent <Vector3> .Create()) { list.Add(unit.Position); for (int i = 0; i < unitInfo.MoveInfo.X.Count; ++i) { list.Add(new Vector3(unitInfo.MoveInfo.X[i], unitInfo.MoveInfo.Y[i], unitInfo.MoveInfo.Z[i])); } unit.MoveToAsync(list).Coroutine(); } } unit.AddComponent <AOIUnitComponent, Vector3, Quaternion, UnitType>(unit.Position, unit.Rotation, unit.Type); unit.AddComponent <ObjectWait>(); break; } default: { Log.Error("没有处理 " + unit.Type); break; } } Game.EventSystem.PublishAsync(new EventType.AfterUnitCreate() { Unit = unit }).Coroutine(); return(unit); }