示例#1
0
        public static async ETTask <bool> MoveToAsync(this MoveComponent self, List <Vector3> target, float speed, int turnTime = 100, ETCancellationToken cancellationToken = null)
        {
            self.Stop();

            foreach (Vector3 v in target)
            {
                self.Targets.Add(v);
            }

            self.IsTurnHorizontal = true;
            self.TurnTime         = turnTime;
            self.Speed            = speed;
            self.tcs = ETTask <bool> .Create(true);

            Game.EventSystem.Publish(self.DomainScene(), new EventType.MoveStart()
            {
                Unit = self.GetParent <Unit>()
            });

            self.StartMove();

            void CancelAction()
            {
                self.Stop();
            }

            bool moveRet;

            try
            {
                cancellationToken?.Add(CancelAction);
                moveRet = await self.tcs;
            }
            finally
            {
                cancellationToken?.Remove(CancelAction);
            }

            if (moveRet)
            {
                Game.EventSystem.Publish(self.DomainScene(), new EventType.MoveStop()
                {
                    Unit = self.GetParent <Unit>()
                });
            }
            return(moveRet);
        }