protected override void Run(ETModel.Session session, M2C_CreateUnits message) { UnitComponent unitComponent = ETModel.Game.Scene.GetComponent <UnitComponent>(); foreach (UnitInfo unitInfo in message.Units) { if (unitComponent.Get(unitInfo.UnitId) != null) { continue; } UnitData unitData = new UnitData(); unitData.groupIndex = (GroupIndex)unitInfo.GroupIndex; unitData.layerMask = (UnitLayerMask)unitInfo.LayerMask; unitData.unitLayer = (UnitLayer)unitInfo.UnitLayer; unitData.unitTag = (UnitTag)unitInfo.UnitTag; Unit unit = UnitFactory.Create(unitInfo.UnitId, 1001, unitData); NumericComponent numericComponent = unit.GetComponent <NumericComponent>(); foreach (var v in unitInfo.UnitNumerics) { numericComponent.Set((NumericType)v.Type, v.Value); } BattleEventHandler.LoadAssets(unit); Vector3 postion = new Vector3(unitInfo.Position.X, unitInfo.Position.Y, unitInfo.Position.Z); unit.GameObject.transform.forward = new Vector3(unitInfo.Dir.X, unitInfo.Dir.Y, unitInfo.Dir.Z); unit.Position = postion; Dictionary <Type, IProperty> unitStateList = new Dictionary <Type, IProperty>(); P_Position property_Position = new P_Position(); property_Position.Value = postion; // 防止掉下去 unitStateList.Add(typeof(P_Position), property_Position); unit.GetComponent <UnitStateComponent>().Init(unitStateList); } }
protected override async ETTask Run(ETModel.Session session, M2C_CreateUnits message) { foreach (UnitInfo unitInfo in message.Units) { //TODO 暂时先忽略除英雄之外的Unit(如技能碰撞体),后期需要配表来解决这一块的逻辑,并且需要在协议里指定Unit的类型Id(注意不是运行时的Id,是Excel表中的类型Id) //TODO 诺手UnitTypeId暂定10001 if (UnitComponent.Instance.Get(unitInfo.UnitId) != null || unitInfo.UnitTypeId != 10001) { continue; } //根据不同名称和ID,创建英雄 Unit unit = UnitFactory.CreateHero(unitInfo.UnitId, "NuoKe", (RoleCamp)unitInfo.RoleCamp); //因为血条需要,创建热更层unit HotfixUnit hotfixUnit = HotfixUnitFactory.CreateHotfixUnit(unit, true); hotfixUnit.AddComponent <FallingFontComponent>(); unit.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z); //添加英雄数据 M2C_GetHeroDataResponse M2C_GetHeroDataResponse = await Game.Scene.GetComponent <SessionComponent>() .Session.Call(new C2M_GetHeroDataRequest() { UnitID = unitInfo.UnitId }) as M2C_GetHeroDataResponse; UnitComponent.Instance.Get(unitInfo.UnitId) .AddComponent <HeroDataComponent, long>(M2C_GetHeroDataResponse.HeroDataID); unit.AddComponent <NP_RuntimeTreeManager>(); //Log.Info("开始创建行为树"); ConfigComponent configComponent = Game.Scene.GetComponent <ConfigComponent>(); NP_RuntimeTreeFactory.CreateSkillNpRuntimeTree(unit, configComponent.Get <Client_SkillCanvasConfig>(10001).NPBehaveId, configComponent.Get <Client_SkillCanvasConfig>(10001).BelongToSkillId).Start(); NP_RuntimeTreeFactory.CreateSkillNpRuntimeTree(unit, configComponent.Get <Client_SkillCanvasConfig>(10002).NPBehaveId, configComponent.Get <Client_SkillCanvasConfig>(10002).BelongToSkillId).Start(); NP_RuntimeTreeFactory.CreateSkillNpRuntimeTree(unit, configComponent.Get <Client_SkillCanvasConfig>(10003).NPBehaveId, configComponent.Get <Client_SkillCanvasConfig>(10003).BelongToSkillId).Start(); NP_RuntimeTreeFactory.CreateSkillNpRuntimeTree(unit, configComponent.Get <Client_SkillCanvasConfig>(10004).NPBehaveId, configComponent.Get <Client_SkillCanvasConfig>(10004).BelongToSkillId).Start(); //Log.Info("行为树创建完成"); // 创建头顶Bar Game.EventSystem.Run(EventIdType.CreateHeadBar, unitInfo.UnitId); // 挂载头顶Bar hotfixUnit.AddComponent <HeroHeadBarComponent, Unit, FUI>(unit, Game.Scene.GetComponent <FUIComponent>().Get(unitInfo.UnitId)); } if (UnitComponent.Instance.MyUnit == null) { // 给自己的Unit添加引用 UnitComponent.Instance.MyUnit = UnitComponent.Instance.Get(PlayerComponent.Instance.MyPlayer.UnitId); UnitComponent.Instance.MyUnit .AddComponent <CameraComponent, Unit>(UnitComponent.Instance.MyUnit); UnitComponent.Instance.MyUnit.AddComponent <OutLineComponent>(); Game.Scene.GetComponent <M5V5GameComponent>().GetHotfixUnit(PlayerComponent.Instance.MyPlayer.UnitId).AddComponent <PlayerHeroControllerComponent>(); Game.EventSystem.Run(EventIdType.EnterMapFinish); } //ETModel.Log.Info($"{DateTime.UtcNow}完成一次创建Unit"); await ETTask.CompletedTask; }
protected async ETVoid RunAsync(Session session, G2M_CreateUnit message, Action <M2G_CreateUnit> reply) { M2G_CreateUnit response = new M2G_CreateUnit(); try { UnitData playerData = new UnitData(); if (unitIndex % 2 == 0) { playerData.groupIndex = GroupIndex.Player; playerData.layerMask = UnitLayerMask.ALL; playerData.unitLayer = UnitLayer.Character; playerData.unitTag = UnitTag.Player; } else { playerData.groupIndex = GroupIndex.Monster; playerData.layerMask = UnitLayerMask.ALL; playerData.unitLayer = UnitLayer.Character; playerData.unitTag = UnitTag.Monster; } unitIndex++; Unit unit = UnitFactory.Create(IdGenerater.GenerateId(), 1001, playerData); await unit.AddComponent <MailBoxComponent>().AddLocation(); unit.AddComponent <UnitGateComponent, long>(message.GateSessionId); unit.Position = new Vector3(-10, 0, -10); UnitStateComponent stateCom = unit.GetComponent <UnitStateComponent>(); Game.Scene.GetComponent <UnitStateMgrComponent>().Add(stateCom); response.UnitId = unit.Id; // 广播创建的unit M2C_CreateUnits createUnits = new M2C_CreateUnits(); Unit[] units = Game.Scene.GetComponent <UnitComponent>().GetAll(); foreach (Unit u in units) { UnitInfo unitInfo = new UnitInfo(); UnitStateComponent unitStateComponent = u.GetComponent <UnitStateComponent>(); unitInfo.Position = u.Position.ToV3Info(); unitInfo.Dir = Vector3.forward.ToV3Info(); unitInfo.UnitId = u.Id; unitInfo.GroupIndex = (int)u.UnitData.groupIndex; unitInfo.LayerMask = (int)u.UnitData.layerMask; unitInfo.UnitLayer = (int)u.UnitData.unitLayer; unitInfo.UnitTag = (int)u.UnitData.unitTag; foreach (var v in u.GetComponent <NumericComponent>().NumericDic) { unitInfo.UnitNumerics.Add(new UnitNumeric() { Type = v.Key, Value = v.Value }); } createUnits.Units.Add(unitInfo); } MessageHelper.Broadcast(createUnits); reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }