Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace HexGame.Actions
- {
- [Serializable]
- public class Movement : MovementAction
- {
- [Inject] private IUnit _unit;
- [Inject] private BoardView _view;
- [Inject] private Board.Board _board;
- [SerializeField] private float _duration;
- [SerializeField] private bool _activate;
- [SerializeField] private bool _triggerMoveEffects;
- [SerializeField] private bool _smoothAnimation;
- public override async UniTask Execute(Offset position, CancellationToken cancellationToken)
- {
- _board.SetStateChangedFlag();
- if(_triggerMoveEffects) await _board.InvokeLifeCycleTrigger(Trigger.OnPreMove, cancellationToken);
- var pointView = _view.GetNodeView(position);
- var node = _board.Nodes.First(node => node.Position == position);
- if (_smoothAnimation)
- {
- _view.UnitView.transform.DOMove(pointView.transform.position, _duration)
- .ToUniTask(cancellationToken: cancellationToken)
- .Forget();
- }
- else
- {
- //instant "teleportation"
- _view.UnitView.transform.position = pointView.transform.position;
- }
- //check if position has changed?
- _unit.Position = position;
- var exhaust = _activate && !node.HasState(NodeStateFlags.Exhausted);
- if (exhaust) await _board.ChangeStateAsync(node, NodeState.Exhausted, cancellationToken);
- if (exhaust && node.TryGet(Trigger.OnActivation, out var action))
- {
- await action.Execute(cancellationToken);
- }
- if(_triggerMoveEffects) await _board.InvokeLifeCycleTrigger(Trigger.OnPostMove, cancellationToken);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement