diff --git a/Assets/PlayerView.cs b/Assets/PlayerView.cs new file mode 100644 index 00000000..dad7ec07 --- /dev/null +++ b/Assets/PlayerView.cs @@ -0,0 +1,18 @@ +using System; +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/PlayerView.cs.meta b/Assets/PlayerView.cs.meta new file mode 100644 index 00000000..403a3a7a --- /dev/null +++ b/Assets/PlayerView.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 04619977b07331e43a21b8d1bc33b6e9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/1/Animation/Character/Jump.anim b/Assets/Resources/1/Animation/Character/Jump.anim index 1bd4b293..27158931 100644 --- a/Assets/Resources/1/Animation/Character/Jump.anim +++ b/Assets/Resources/1/Animation/Character/Jump.anim @@ -73472,3 +73472,10 @@ AnimationClip: floatParameter: 0 intParameter: 0 messageOptions: 0 + - time: 0.53333336 + functionName: + data: + objectReferenceParameter: {fileID: 0} + floatParameter: 0 + intParameter: 0 + messageOptions: 0 diff --git a/Assets/Resources/1/Character/Prefab/Asvald.prefab b/Assets/Resources/1/Character/Prefab/Asvald.prefab index 57d49012..f0fddb4f 100644 --- a/Assets/Resources/1/Character/Prefab/Asvald.prefab +++ b/Assets/Resources/1/Character/Prefab/Asvald.prefab @@ -2934,6 +2934,7 @@ GameObject: m_Component: - component: {fileID: 7150739129758644021} - component: {fileID: -4568693640035559416} + - component: {fileID: 8989822822968797088} m_Layer: 0 m_Name: Asvald m_TagString: Untagged @@ -2993,6 +2994,18 @@ Animator: m_HasTransformHierarchy: 1 m_AllowConstantClipSamplingOptimization: 1 m_KeepAnimatorControllerStateOnDisable: 0 +--- !u!114 &8989822822968797088 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7527582019267571087} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 04619977b07331e43a21b8d1bc33b6e9, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &7550162364350684268 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Chars/Player.cs b/Assets/Scripts/Chars/Player.cs index 0fcad8a8..af83c38a 100644 --- a/Assets/Scripts/Chars/Player.cs +++ b/Assets/Scripts/Chars/Player.cs @@ -19,7 +19,10 @@ namespace Chars public Action OnPlayerSpawned; private Animator _animator; private float _tick; + private PlayerView _playerView; + private bool _isMoving; + public bool IsMoving => _isMoving; public GameObject Playerinstance => _instance; public Player(PlayerData playerData, HexGrid hexGrid) @@ -30,6 +33,7 @@ namespace Chars _hexGrid = hexGrid; _texture = playerData.hexTexture; _tick = playerData.Tick; + _isMoving = false; } @@ -37,22 +41,25 @@ namespace Chars { if (_cell.GetNeighbor(direction)) { + _isMoving = true; _cell = _cell.GetNeighbor(direction); _curentPosition = _cell.coordinates; _instance.transform.LookAt(_cell.transform); _animator.SetTrigger("Move"); - _animator.SetBool("isMoving", true); - _instance.transform.DOMove(_cell.transform.position, _tick).OnComplete(() => + _animator.SetBool("isMoving", _isMoving); + _playerView.OnStep += () => { - _animator.SetBool("isMoving", false); - _animator.SetTrigger("Jump"); + _isMoving = false; _cell.PaintHex(_texture); - }); + _animator.SetBool("isMoving", _isMoving); + }; + _instance.transform.DOMove(_cell.transform.position, _tick); } } + public void Spawn() { if (!_isAlive) @@ -68,6 +75,7 @@ namespace Chars OnPlayerSpawned?.Invoke(_instance); _isAlive = true; _animator = _instance.GetComponent(); + _playerView = _instance.GetComponent(); } } diff --git a/Assets/Scripts/Chars/PlayerControl.cs b/Assets/Scripts/Chars/PlayerControl.cs index cddda4bf..94c341c7 100644 --- a/Assets/Scripts/Chars/PlayerControl.cs +++ b/Assets/Scripts/Chars/PlayerControl.cs @@ -28,7 +28,7 @@ namespace Chars public void Execute() { - if (Time.time - _curTime >= _tick && _moveJoystick.Direction != Vector2.zero) + if (!_player.IsMoving && _moveJoystick.Direction != Vector2.zero) { _curTime = Time.time; _player.Move(VectorToDirection(_moveJoystick.Direction.normalized));