diff --git a/Assets/Joystick Pack/Scripts/Base/Joystick.cs b/Assets/Joystick Pack/Scripts/Base/Joystick.cs index e382bbae..d4180787 100644 --- a/Assets/Joystick Pack/Scripts/Base/Joystick.cs +++ b/Assets/Joystick Pack/Scripts/Base/Joystick.cs @@ -77,7 +77,7 @@ public class Joystick : MonoBehaviour, IPointerDownHandler, IDragHandler, IPoint FormatInput(); HandleInput(input.magnitude, input.normalized, radius, cam); handle.anchoredPosition = input * radius * handleRange; - OnPadDrag.Invoke(Direction); + OnPadDrag?.Invoke(Direction); } protected virtual void HandleInput(float magnitude, Vector2 normalised, Vector2 radius, Camera cam) diff --git a/Assets/PlayerView.cs b/Assets/PlayerView.cs index dad7ec07..f724b5fb 100644 --- a/Assets/PlayerView.cs +++ b/Assets/PlayerView.cs @@ -3,14 +3,8 @@ using UnityEngine; public class PlayerView : MonoBehaviour { - private Animator _animator; public Action OnStep; - void Start() - { - _animator.GetComponent(); - } - public void Step() { OnStep?.Invoke(); diff --git a/Assets/Scripts/Chars/Player.cs b/Assets/Scripts/Chars/Player.cs index af83c38a..935af00e 100644 --- a/Assets/Scripts/Chars/Player.cs +++ b/Assets/Scripts/Chars/Player.cs @@ -54,7 +54,7 @@ namespace Chars _cell.PaintHex(_texture); _animator.SetBool("isMoving", _isMoving); }; - _instance.transform.DOMove(_cell.transform.position, _tick); + _instance.transform.DOMove(_cell.transform.position, _animator.GetCurrentAnimatorClipInfo(0).LongLength); } } @@ -76,6 +76,7 @@ namespace Chars _isAlive = true; _animator = _instance.GetComponent(); _playerView = _instance.GetComponent(); + } } diff --git a/Assets/Scripts/Chars/PlayerControl.cs b/Assets/Scripts/Chars/PlayerControl.cs index 94c341c7..fbfebb3d 100644 --- a/Assets/Scripts/Chars/PlayerControl.cs +++ b/Assets/Scripts/Chars/PlayerControl.cs @@ -1,4 +1,5 @@ using System; +using Controller; using Data; using HexFiled; using Runtime.Controller; @@ -7,13 +8,12 @@ using Object = UnityEngine.Object; namespace Chars { - public class PlayerControl : IExecute + public class PlayerControl : IFixedExecute { private Player _player; private FloatingJoystick _moveJoystick; private FloatingJoystick _attackJoystick; - private float _curTime; - private float _tick; + public PlayerControl(Player player, PlayerData playerData) { @@ -21,24 +21,17 @@ namespace Chars var joyView = Object.Instantiate(playerData.joystickView); _moveJoystick = joyView.MoveJoystick; _attackJoystick = joyView.AttackJoystick; - _curTime = Time.time; - _tick = playerData.Tick; - _moveJoystick.OnPadDrag += Move; } - - public void Execute() + + + public void FixedExecute() { - if (!_player.IsMoving && _moveJoystick.Direction != Vector2.zero) + if (!_player.IsMoving && _moveJoystick.isPressed) { - _curTime = Time.time; _player.Move(VectorToDirection(_moveJoystick.Direction.normalized)); } } - private void Move(Vector3 dir) - { - } - private static HexDirection VectorToDirection(Vector2 dir) { if (dir.x >= 0 && dir.y <= 1 && dir.x <= 1 && dir.y >= 0.5) @@ -73,5 +66,7 @@ namespace Chars return HexDirection.W; } + + } } \ No newline at end of file