Example #1
0
        /// <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;
        }
        protected override void Run(ETModel.Session session, A1006_PathfindingResult_M2C message)
        {
            Gamer gamer = ETModel.Game.Scene.GetComponent <GamerComponent>().Get(message.UserID);

            //如果本地玩家收到服务器转发自己的消息 不处理
            if (gamer.UserID == GamerComponent.Instance.MyUser.UserID)
            {
                return;
            }

            gamer.GetComponent <GamerAnimatorComponent>().SetIntValue("Speed", 1);
            GamerPathComponent gamerPathComponent = gamer.GetComponent <GamerPathComponent>();

            gamerPathComponent.StartMove(message).NoAwait();

            GizmosDebug.Instance.Path.Clear();
            GizmosDebug.Instance.Path.Add(new Vector3(message.X, message.Y, message.Z));
            for (int i = 0; i < message.Xs.Count; ++i)
            {
                GizmosDebug.Instance.Path.Add(new Vector3(message.Xs[i], message.Ys[i], message.Zs[i]));
            }
        }