/// <summary> /// 加入房间 /// </summary> /// <param name="self"></param> /// <param name="room"></param> /// <param name="matcher"></param> public static void JoinRoom(this Moba5V5Component self, Moba5V5Room room, Gamer gamer) { //玩家可能掉线 if (gamer == null) { return; } //玩家绑定待机房间 机器人不用绑定房间 if (gamer.UserID != 0) { self.Waiting.Add(gamer.UserID, room); } //为玩家添加座位 机器人也有座位 room.Add(gamer); //通知Gate服务器玩家匹配成功 参数:Gamer的InstanceId //Gate服务器将Actor类消息转发给Gamer if (gamer.UserID != 0) { ActorMessageSenderComponent actorProxyComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); ActorMessageSender gamerActorProxy = actorProxyComponent.Get(gamer.ActorIDofUser); gamerActorProxy.Send(new B1002_Match5V5Sucess_M2G() { ActorIDofGamer = gamer.InstanceId }); } }
/// <summary> /// 检查匹配状态 每当有新排队玩家加入时执行一次 /// </summary> /// <param name="self"></param> public static void MatchingCheck(this Moba5V5Component self) { //如果有空房间 且 正在排队的玩家>0 Moba5V5Room room = self.GetFreeRoom(); if (room != null) { while (self.MatchingQueue.Count > 0 && room.Count < self.StartNumber) { self.JoinRoom(room, self.MatchingQueue.Dequeue()); } } //else 如果没有空房间 且 正在排队的玩家>=开局人数 else if (self.MatchingQueue.Count >= self.StartNumber) { //创建新房间 room = ComponentFactory.Create <Moba5V5Room>(); room.AddComponent <MailBoxComponent>(); self.FreeRooms.Add(room.Id, room); while (self.MatchingQueue.Count > 0 && room.Count < self.StartNumber) { self.JoinRoom(room, self.MatchingQueue.Dequeue()); } } }
public bool canMove = true; //是否可以移动 public void Awake() { instance = this; touchHandler = TouchHandler.GetInstance(); //按键消息处理 touchHandler.OnKeyChanged = OnTouch; lastFrameStartTime = TimeHelper.Now(); //本地计时 moba5V5UI = Game.Scene.GetComponent <UIComponent>().Get(UIType.Moba5V5UI).GetComponent <Moba5V5UIComponent>(); }
/// <summary> /// 返回未开始游戏的房间 用于处理准备消息 /// </summary> /// <param name="self"></param> /// <param name="gamer"></param> /// <returns></returns> public static Moba5V5Room GetWaitingRoom(this Moba5V5Component self, Gamer gamer) { Moba5V5Room room; if (!self.Waiting.TryGetValue(gamer.UserID, out room)) { Log.Error("玩家不在待机的房间中"); } return(room); }
protected override void Run(ETModel.Session session, A1011_SpawnMonster_M2C message) { //服务端通知客户端刷新一波士兵 2战士 1法师 TimerComponent timerComponent = ETModel.Game.Scene.GetComponent <TimerComponent>(); ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent <ResourcesComponent>(); GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit"); ConfigComponent config = Game.Scene.GetComponent <ConfigComponent>(); Moba5V5Component moba = Moba5V5Component.instance; //创建24个野怪 其中61号Boss1跳过 配置编号49-72 for (int i = 0; i < 24; i++) { if (i == 12) { continue; } //获取角色配置 Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 49); GameObject prefab = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab); prefab.transform.position = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]); prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0); //创建角色 Gamer gamer = ETModel.ComponentFactory.Create <Gamer>(); gamer.GameObject = UnityEngine.Object.Instantiate(prefab); gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false); int mobaID = moba.MobaID; //获取ID moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典 //添加Unity组件 NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>(); navMeshAgent.radius = 0.2f; navMeshAgent.height = 0.8f; navMeshAgent.angularSpeed = 360f; navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance; //添加ET组件 gamer.AddComponent <GamerAnimatorComponent>(); gamer.AddComponent <GamerMoveComponent>(); gamer.AddComponent <GamerTurnComponent>(); gamer.AddComponent <GamerPathComponent>(); //设置角色 CharacterComponent character = gamer.AddComponent <CharacterComponent>(); character.mobaID = mobaID; character.group = moba5V5Config.Group; //阵营 character.type = moba5V5Config.Type; //类型 } }
/// <summary> /// 匹配队列人数加一 队列模式没有插队/离队操作 /// 队列满足匹配条件时 创建新房间 /// </summary> /// <param name="self"></param> /// <param name="gamer"></param> public static void AddGamerToMatchingQueue(this Moba5V5Component self, Gamer gamer) { //添加玩家到队列 self.MatchingQueue.Enqueue(gamer); Log.Debug("一位玩家加入队列"); //广播通知所有匹配中的玩家 self.Broadcast(new A1003_MatcherPlusOne_M2C() { MatchingNumber = self.MatchingQueue.Count }); //检查匹配状态 self.MatchingCheck(); }
/// <summary> /// 匹配队列广播 /// </summary> /// <param name="self"></param> /// <param name="message"></param> public static void Broadcast(this Moba5V5Component self, IActorMessage message) { foreach (Gamer gamer in self.MatchingQueue) { if (gamer.UserID == 0) { continue; } //像Gate服务器中User绑定的Seesion发送Actor消息 ActorMessageSenderComponent actorProxyComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); ActorMessageSender actorProxy = actorProxyComponent.Get(gamer.ActorIDofClient); actorProxy.Send(message); } }
protected override void Run(Gamer gamer, A1007_GamerReadyMoba5V5_C2M message) { Moba5V5Component moba = Game.Scene.GetComponent <Moba5V5Component>(); Moba5V5Room room = moba.GetWaitingRoom(gamer); if (room != null) { //找到玩家的座位顺序 设置其准备状态为真 int seatIndex = room.GetGamerSeat(gamer.UserID); if (seatIndex >= 0) { room.isReadys[seatIndex] = true; //检测开始游戏 room.GetComponent <MobaControllerComponent>().CheckGameStart(); } else { Log.Error("玩家不在正确的座位上"); } } }
/// <summary> /// 所有玩家已就绪游戏开始 /// </summary> /// <param name="self"></param> public static void GameStart(this MobaControllerComponent self) { //正式开始游戏前的准备 Moba5V5Room room = self.GetParent <Moba5V5Room>(); Moba5V5Component moba = Game.Scene.GetComponent <Moba5V5Component>(); //更改房间状态为游戏中 moba.FreeRooms.Remove(room.Id); moba.GamingRooms.Add(room.Id, room); //更改玩家状态为游戏中 for (int i = 0; i < room.gamers.Length; i++) { if (room.gamers[i].UserID != 0) { Gamer gamer = room.gamers[i]; moba.Waiting.Remove(gamer.UserID); moba.Playing.Add(gamer.UserID, room); } } //服务端加载游戏逻辑 for (int i = 0; i < room.gamers.Length; i++) { room.gamers[i].AddComponent <GamerMoveComponent>(); room.gamers[i].AddComponent <GamerPathComponent>(); room.gamers[i].Position = new Vector3(-10, 0, -10); } //开始服务端游戏计时 self.isGameStarted = true; self.gameStartTime = TimeHelper.ClientNow(); self.lastFrameCostTime = self.gameStartTime; self.SpawnArmy().NoAwait(); //周期刷新士兵 self.SpawnWild().NoAwait(); //刷新野怪 room.Broadcast(new A1008_GameStart_M2C()); }
protected override async void Run(Session session, B1001_CreateRobotMatch5V5_G2M message) { Moba5V5Component moba = Game.Scene.GetComponent <Moba5V5Component>(); //创建玩家Entity Gamer roomCreater = ComponentFactory.Create <Gamer, long>(message.UserID); //设置玩家参数 roomCreater.ActorIDofUser = message.ActorIDofUser; roomCreater.ActorIDofClient = message.ActorIDofClient; await roomCreater.AddComponent <MailBoxComponent>().AddLocation(); moba.AddGamerToMatchingQueue(roomCreater); //需要先设置ActorIDofClient才能使用Actor消息 //创建9个机器人加入匹配 机器人的UserID为0 for (int i = 0; i < 9; i++) { Gamer robot = ComponentFactory.Create <Gamer, long>(0); await robot.AddComponent <MailBoxComponent>().AddLocation(); moba.AddGamerToMatchingQueue(robot); } }
//普通攻击一个目标 目标ID和普攻连击数 public static void OnAttack(this CharacterComponent self, int targetMobaID, int combo) { //播放普攻动画 self.anime.SetIntValue("Attack", combo); //向目标施加被攻击特效 ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent <ResourcesComponent>(); GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit"); Moba5V5Component moba = Moba5V5Component.instance; GameObject effectPrefab = bundleGameObject.Get <GameObject>("Hit1"); effectPrefab.SetActive(false); GameObject effectHit1 = UnityEngine.Object.Instantiate(effectPrefab); Gamer target; moba.mobaIDGamers.TryGetValue(targetMobaID, out target); if (target == null || effectHit1 == null) { return; } effectHit1.transform.SetParent(target.GameObject.transform.Find("Effect_OnHit").gameObject.transform, false); effectHit1.SetActive(true); }
/// <summary> /// 获取一个可以添加座位的房间 没有则返回null /// </summary> /// <param name="self"></param> /// <returns></returns> public static Moba5V5Room GetFreeRoom(this Moba5V5Component self) { return(self.FreeRooms.Where(p => p.Value.Count < self.StartNumber).FirstOrDefault().Value); }
protected override async void Run(ETModel.Session session, A1010_NewArmyWave_M2C message) { //服务端通知客户端刷新一波士兵 1坦克 战士 1法师 TimerComponent timerComponent = ETModel.Game.Scene.GetComponent <TimerComponent>(); ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent <ResourcesComponent>(); GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit"); ConfigComponent config = Game.Scene.GetComponent <ConfigComponent>(); Moba5V5Component moba = Moba5V5Component.instance; //创建3个蓝方坦克 配置编号37-39 for (int i = 0; i < 3; i++) { //获取角色配置 Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 37); GameObject prefab = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab); prefab.transform.position = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]); prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0); //创建角色 Gamer gamer = ETModel.ComponentFactory.Create <Gamer>(); gamer.GameObject = UnityEngine.Object.Instantiate(prefab); gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false); int mobaID = moba.MobaID; //获取ID moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典 //添加Unity组件 NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>(); navMeshAgent.radius = 0.2f; navMeshAgent.height = 0.8f; navMeshAgent.angularSpeed = 360f; navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance; //添加ET组件 gamer.AddComponent <GamerAnimatorComponent>(); gamer.AddComponent <GamerMoveComponent>(); gamer.AddComponent <GamerTurnComponent>(); gamer.AddComponent <GamerPathComponent>(); //设置角色 CharacterComponent character = gamer.AddComponent <CharacterComponent>(); character.mobaID = mobaID; character.group = moba5V5Config.Group; //阵营 character.type = moba5V5Config.Type; //类型 character.route = moba5V5Config.Route; //默认导航线路 } //创建3个红方坦克 配置编号46-48 for (int i = 0; i < 3; i++) { //获取角色配置 Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 46); GameObject prefab = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab); prefab.transform.position = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]); prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0); //创建角色 Gamer gamer = ETModel.ComponentFactory.Create <Gamer>(); gamer.GameObject = UnityEngine.Object.Instantiate(prefab); gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false); int mobaID = moba.MobaID; //获取ID moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典 //添加Unity组件 NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>(); navMeshAgent.radius = 0.2f; navMeshAgent.height = 0.8f; navMeshAgent.angularSpeed = 360f; navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance; //添加ET组件 gamer.AddComponent <GamerAnimatorComponent>(); gamer.AddComponent <GamerMoveComponent>(); gamer.AddComponent <GamerTurnComponent>(); gamer.AddComponent <GamerPathComponent>(); //设置角色 CharacterComponent character = gamer.AddComponent <CharacterComponent>(); character.mobaID = mobaID; character.group = moba5V5Config.Group; //阵营 character.type = moba5V5Config.Type; //类型 character.route = moba5V5Config.Route; //默认导航线路 } await timerComponent.WaitAsync(1000); for (int i = 0; i < 3; i++) { //获取角色配置 Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 31); GameObject prefab = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab); prefab.transform.position = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]); prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0); //创建角色 Gamer gamer = ETModel.ComponentFactory.Create <Gamer>(); gamer.GameObject = UnityEngine.Object.Instantiate(prefab); gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false); int mobaID = moba.MobaID; //获取ID moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典 //添加Unity组件 NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>(); navMeshAgent.radius = 0.2f; navMeshAgent.height = 0.8f; navMeshAgent.angularSpeed = 360f; navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance; //添加ET组件 gamer.AddComponent <GamerAnimatorComponent>(); gamer.AddComponent <GamerMoveComponent>(); gamer.AddComponent <GamerTurnComponent>(); gamer.AddComponent <GamerPathComponent>(); //设置角色 CharacterComponent character = gamer.AddComponent <CharacterComponent>(); character.mobaID = mobaID; character.group = moba5V5Config.Group; //阵营 character.type = moba5V5Config.Type; //类型 character.route = moba5V5Config.Route; //默认导航线路 } for (int i = 0; i < 3; i++) { //获取角色配置 Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 40); GameObject prefab = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab); prefab.transform.position = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]); prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0); //创建角色 Gamer gamer = ETModel.ComponentFactory.Create <Gamer>(); gamer.GameObject = UnityEngine.Object.Instantiate(prefab); gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false); int mobaID = moba.MobaID; //获取ID moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典 //添加Unity组件 NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>(); navMeshAgent.radius = 0.2f; navMeshAgent.height = 0.8f; navMeshAgent.angularSpeed = 360f; navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance; //添加ET组件 gamer.AddComponent <GamerAnimatorComponent>(); gamer.AddComponent <GamerMoveComponent>(); gamer.AddComponent <GamerTurnComponent>(); gamer.AddComponent <GamerPathComponent>(); //设置角色 CharacterComponent character = gamer.AddComponent <CharacterComponent>(); character.mobaID = mobaID; character.group = moba5V5Config.Group; //阵营 character.type = moba5V5Config.Type; //类型 character.route = moba5V5Config.Route; //默认导航线路 } await timerComponent.WaitAsync(1000); //创建3个蓝方法师 配置编号34-36 for (int i = 0; i < 3; i++) { //获取角色配置 Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 34); GameObject prefab = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab); prefab.transform.position = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]); prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0); //创建角色 Gamer gamer = ETModel.ComponentFactory.Create <Gamer>(); gamer.GameObject = UnityEngine.Object.Instantiate(prefab); gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false); int mobaID = moba.MobaID; //获取ID moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典 //添加Unity组件 NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>(); navMeshAgent.radius = 0.2f; navMeshAgent.height = 0.8f; navMeshAgent.angularSpeed = 360f; navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance; //添加ET组件 gamer.AddComponent <GamerAnimatorComponent>(); gamer.AddComponent <GamerMoveComponent>(); gamer.AddComponent <GamerTurnComponent>(); gamer.AddComponent <GamerPathComponent>(); //设置角色 CharacterComponent character = gamer.AddComponent <CharacterComponent>(); character.mobaID = mobaID; character.group = moba5V5Config.Group; //阵营 character.type = moba5V5Config.Type; //类型 character.route = moba5V5Config.Route; //默认导航线路 } //创建3个红方法师 配置编号43-45 for (int i = 0; i < 3; i++) { //获取角色配置 Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 43); GameObject prefab = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab); prefab.transform.position = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]); prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0); //创建角色 Gamer gamer = ETModel.ComponentFactory.Create <Gamer>(); gamer.GameObject = UnityEngine.Object.Instantiate(prefab); gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false); int mobaID = moba.MobaID; //获取ID moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典 //添加Unity组件 NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>(); navMeshAgent.radius = 0.2f; navMeshAgent.height = 0.8f; navMeshAgent.angularSpeed = 360f; navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance; //添加ET组件 gamer.AddComponent <GamerAnimatorComponent>(); gamer.AddComponent <GamerMoveComponent>(); gamer.AddComponent <GamerTurnComponent>(); gamer.AddComponent <GamerPathComponent>(); //设置角色 CharacterComponent character = gamer.AddComponent <CharacterComponent>(); character.mobaID = mobaID; character.group = moba5V5Config.Group; //阵营 character.type = moba5V5Config.Type; //类型 character.route = moba5V5Config.Route; //默认导航线路 } }
protected override async void Run(ETModel.Session session, A1004_CreateMoba5V5Secene_M2C message) { //开启加载界面 切换UI UIComponent uiComponent = Game.Scene.GetComponent <UIComponent>(); UI ui = uiComponent.Get(UIType.SekiaLobby); if (ui == null) { return; } if (ui.GetComponent <SekiaLobbyComponent>().isMatching == false) { return; } uiComponent.Create(UIType.Moba5V5UI); uiComponent.Remove(UIType.SekiaLobby); //切换场景 using (SceneChangeComponent sceneChangeComponent = ETModel.Game.Scene.AddComponent <SceneChangeComponent>()) { await sceneChangeComponent.ChangeSceneAsync(SceneType.Moba5V5Map); } //加载配置 ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent <ResourcesComponent>(); await resourcesComponent.LoadBundleAsync($"unit.unity3d"); GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit"); ConfigComponent config = Game.Scene.GetComponent <ConfigComponent>(); Moba5V5Component moba = Game.Scene.AddComponent <Moba5V5Component>(); //创建空气墙 编号73和74 for (int i = 0; i < 2; i++) { Moba5V5Config qiang = (Moba5V5Config)config.Get(typeof(Moba5V5Config), 73 + i); GameObject qiangPrefab = bundleGameObject.Get <GameObject>(qiang.Prefab); qiangPrefab.transform.position = new Vector3((float)qiang.Position[0], (float)qiang.Position[1], (float)qiang.Position[2]); qiangPrefab.transform.eulerAngles = new Vector3(0, qiang.Rotation, 0); qiangPrefab.name = $"Qiang{(i + 1).ToString()}"; UnityEngine.Object.Instantiate(qiangPrefab).transform.SetParent(GameObject.Find($"/Global/Unit").transform, false); } //创建10个英雄的GameObject和Gamer MobaID编号1-10 for (int i = 0; i < message.Gamers.Count; i++) { //获取英雄配置 角色配置 技能配置 HeroConfig heroConfig = (HeroConfig)config.Get(typeof(HeroConfig), message.Gamers[i].HeroID); Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 1); GameObject prefab = bundleGameObject.Get <GameObject>(heroConfig.Prefab); prefab.transform.position = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]); prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0); //创建角色 Gamer gamer = ETModel.ComponentFactory.Create <Gamer, long>(message.Gamers[i].UserID); gamer.GameObject = UnityEngine.Object.Instantiate(prefab); gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false); int mobaID = moba.MobaID; //获取ID moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典 //添加Unity组件 NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>(); navMeshAgent.radius = 0.2f; navMeshAgent.height = 0.8f; navMeshAgent.angularSpeed = 360f; navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance; //添加ET组件 GamerAnimatorComponent anime = gamer.AddComponent <GamerAnimatorComponent>(); gamer.AddComponent <GamerMoveComponent>(); gamer.AddComponent <GamerTurnComponent>(); gamer.AddComponent <GamerPathComponent>(); //设置角色 CharacterComponent character = gamer.AddComponent <CharacterComponent>(); character.mobaID = mobaID; character.group = moba5V5Config.Group; //阵营 character.type = moba5V5Config.Type; //类型 character.route = moba5V5Config.Route; //默认导航线路 character.anime = anime; //确认本地玩家 if (gamer.UserID == GamerComponent.Instance.MyUser.UserID) { gamer.AddComponent <GamerCameraComponent>(); moba.myGamer = gamer; } } //创建攻击类建筑 MobaID编号11-30 for (int i = 0; i < 20; i++) { //获取角色配置 Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 11); //创建角色 Gamer gamer = ETModel.ComponentFactory.Create <Gamer>(); gamer.GameObject = GameObject.Find($"/World/5v5_Map/mobaTower{i+1}"); gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false); int mobaID = moba.MobaID; //获取ID moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典 //添加ET组件 gamer.AddComponent <GamerAnimatorComponent>(); CharacterComponent character = gamer.AddComponent <CharacterComponent>(); //设置角色 character.mobaID = mobaID; character.group = moba5V5Config.Group; //阵营 character.type = moba5V5Config.Type; //类型 } //初始加载完成 SessionComponent.Instance.Session.Send(new A1007_GamerReadyMoba5V5_C2M()); //等待服务端通知游戏计时开始 //等待服务端通知刷新第一波小兵 //等待服务端通知刷新普通野怪 //等待服务端通知刷新大龙 }
protected override void Run(ETModel.Session session, A1012_NewMonster_M2C message) { //服务端通知客户端刷新一窝野怪 TimerComponent timerComponent = ETModel.Game.Scene.GetComponent <TimerComponent>(); ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent <ResourcesComponent>(); GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit"); ConfigComponent config = Game.Scene.GetComponent <ConfigComponent>(); Moba5V5Component moba = Moba5V5Component.instance; //野怪点ID 编号分别为:49 51 52 54 57 58 59 60 61 62 63 64 65 68 70 71 int configID; //配置编号 int monsterNumber; //野怪数量 switch (message.MonsterID) { case 49: //蜥蜴 configID = 49; monsterNumber = 2; break; case 51: //蓝Buff configID = 51; monsterNumber = 1; break; case 52: //狼 configID = 52; monsterNumber = 2; break; case 54: //熊 configID = 54; monsterNumber = 3; break; case 57: //红Buff configID = 57; monsterNumber = 1; break; case 58: //鸟 configID = 58; monsterNumber = 1; break; case 59: //河道蟹 configID = 59; monsterNumber = 1; break; case 60: //河道蟹 configID = 60; monsterNumber = 1; break; case 61: //大Boss configID = 61; monsterNumber = 1; break; case 62: //小Boss configID = 62; monsterNumber = 1; break; case 63: //鸟 configID = 63; monsterNumber = 1; break; case 64: //红buff configID = 64; monsterNumber = 1; break; case 65: //熊 configID = 65; monsterNumber = 3; break; case 68: //狼 configID = 68; monsterNumber = 2; break; case 70: //蓝Buff configID = 70; monsterNumber = 1; break; case 71: //蜥蜴 configID = 71; monsterNumber = 2; break; default: throw new Exception("未知野怪点"); } for (int i = 0; i < monsterNumber; i++) { if (i == 12) { continue; } //获取角色配置 Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + configID); GameObject prefab = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab); prefab.transform.position = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]); prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0); //创建角色 Gamer gamer = ETModel.ComponentFactory.Create <Gamer>(); gamer.GameObject = UnityEngine.Object.Instantiate(prefab); gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false); int mobaID = moba.MobaID; //获取ID moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典 //添加Unity组件 NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>(); navMeshAgent.radius = 0.2f; navMeshAgent.height = 0.8f; navMeshAgent.angularSpeed = 360f; navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance; //添加ET组件 gamer.AddComponent <GamerAnimatorComponent>(); gamer.AddComponent <GamerMoveComponent>(); gamer.AddComponent <GamerTurnComponent>(); gamer.AddComponent <GamerPathComponent>(); //设置角色 CharacterComponent character = gamer.AddComponent <CharacterComponent>(); character.mobaID = mobaID; character.group = moba5V5Config.Group; //阵营 character.type = moba5V5Config.Type; //类型 } }