public static Unit Create(Entity domain, UnitInfo unitInfo) { Unit unit = EntityFactory.CreateWithId <Unit, int>(domain, unitInfo.UnitId, unitInfo.ConfigId); 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>(); UnitComponent unitComponent = domain.GetComponent <UnitComponent>(); unitComponent.Add(unit); 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, 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, 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(); }
public static Unit Create(Entity domain, long id) { Unit unit = EntityFactory.CreateWithId <Unit>(domain, id); unit.AddComponent <MoveComponent>(); unit.AddComponent <TurnComponent>(); unit.AddComponent <UnitPathComponent>(); Game.EventSystem.Run(EventIdType.AfterUnitCreate, unit); UnitComponent unitComponent = Game.Scene.GetComponent <UnitComponent>(); unitComponent.Add(unit); return(unit); }
public static Unit Create(Entity domain, long id) { Unit unit = EntityFactory.CreateWithId <Unit>(domain, id); unit.AddComponent <TurnComponent>(); Game.EventSystem.Publish(new EventType.AfterUnitCreate() { Unit = unit }); UnitComponent unitComponent = Game.Scene.GetComponent <UnitComponent>(); unitComponent.Add(unit); return(unit); }
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(Entity domain, UnitInfo unitInfo) { Unit unit = EntityFactory.CreateWithId <Unit, int>(domain, unitInfo.UnitId, unitInfo.ConfigId); unit.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z); unit.AddComponent <MoveComponent>(); unit.AddComponent <TurnComponent>(); unit.AddComponent <UnitPathComponent>(); UnitComponent unitComponent = domain.GetComponent <UnitComponent>(); unitComponent.Add(unit); Game.EventSystem.Publish(new EventType.AfterUnitCreate() { Unit = unit }); return(unit); }
public static Unit Create(Entity domain, UnitInfo unitInfo) { ResourcesComponent resourcesComponent = Game.Scene.GetComponent <ResourcesComponent>(); GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit"); GameObject prefab = bundleGameObject.Get <GameObject>("Skeleton"); GameObject go = UnityEngine.Object.Instantiate(prefab); Unit unit = EntityFactory.CreateWithId <Unit, GameObject>(domain, unitInfo.UnitId, go); unit.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z); unit.AddComponent <MoveComponent>(); unit.AddComponent <TurnComponent>(); unit.AddComponent <UnitPathComponent>(); unit.AddComponent <AnimatorComponent>(); UnitComponent unitComponent = Game.Scene.GetComponent <UnitComponent>(); unitComponent.Add(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 = 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(); }
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); }