Ejemplo n.º 1
0
        private MovementActionStrategy GetStrategy(MovementAction action)
        {
            switch (action.Type)
            {
            case MovementType.StartPoint:
                return(new StartPointStrategy(_rigidbody, action.Point, _formationCell));

            case MovementType.MoveToPoint:
                return(new MoveToPointStrategy(_rigidbody, action.Point, _speed, _rotationSpeed));

            case MovementType.MoveToPlayer:
                return(new MoveToPlayerStrategy(_rigidbody, _player, action.Point, _speed, _rotationSpeed));

            case MovementType.MoveToFormation:
                return(new MoveToFormationStrategy(_rigidbody, _formationCell, _speed, _rotationSpeed));

            case MovementType.JoinFormation:
                return(new JoinFormationStrategy(_rigidbody, _formationCell));

            case MovementType.GoOffscreen:
                return(new MoveOffscreenStrategy(_rigidbody, _speed, _rotationSpeed));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 2
0
        private Task DoAction(MovementAction action)
        {
            var strategy = GetStrategy(action);
            var tcs      = new TaskCompletionSource <Unit>();

            strategy.Finished += () => tcs.TrySetResult(Unit.Default);
            _currentStrategy   = strategy;
            return(tcs.Task);
        }