/// <summary> /// 玩家移动房间广播 index当前移动进度 offset发送坐标的数量 /// </summary> public static void BroadcastPath(this GamerPathComponent self, List <Vector3> path, int index, int offset) { Gamer gamer = self.GetParent <Gamer>(); Vector3 unitPos = gamer.Position; A1006_PathfindingResult_M2C pathfindingResult = new A1006_PathfindingResult_M2C(); pathfindingResult.X = unitPos.x; //当前位置 pathfindingResult.Y = unitPos.y; pathfindingResult.Z = unitPos.z; pathfindingResult.UserID = gamer.UserID; for (int i = 0; i < offset; ++i) //预测的坐标个数 先广播后移动 不包含当前坐标 { if (index + i >= self.ABPath.Result.Count) //预测坐标的序列不能大于坐标总数 { break; } Vector3 v = self.ABPath.Result[index + i]; pathfindingResult.Xs.Add(v.x); pathfindingResult.Ys.Add(v.y); pathfindingResult.Zs.Add(v.z); } //找到玩家所在房间进行广播 Moba5V5Room room = Game.Scene.GetComponent <Moba5V5Component>().GetGamingRoom(gamer); room.Broadcast(pathfindingResult); }
/// <summary> /// 寻路组件对外接口 /// </summary> public static async ETVoid StartMove(this GamerPathComponent self, A1006_PathfindingResult_M2C message) { // 取消之前的移动协程 self.CancellationTokenSource?.Cancel(); self.CancellationTokenSource = new CancellationTokenSource(); self.Path.Clear(); for (int i = 0; i < message.Xs.Count; ++i) { self.Path.Add(new Vector3(message.Xs[i], message.Ys[i], message.Zs[i])); } self.ServerPos = new Vector3(message.X, message.Y, message.Z); //设置服务端当前坐标 await self.StartMove(self.CancellationTokenSource.Token); //执行移动 self.CancellationTokenSource.Dispose(); self.CancellationTokenSource = null; }