move time fixed

This commit is contained in:
dddushesss 2021-12-20 22:10:12 +03:00
parent 10363a03f4
commit 0eba5f8bee
3 changed files with 44 additions and 29 deletions

View File

@ -73465,17 +73465,10 @@ AnimationClip:
m_HasGenericRootTransform: 0
m_HasMotionFloatCurves: 0
m_Events:
- time: 0.33333334
- time: 0.53333336
functionName: Step
data:
objectReferenceParameter: {fileID: 0}
floatParameter: 0
intParameter: 0
messageOptions: 0
- time: 0.53333336
functionName:
data:
objectReferenceParameter: {fileID: 0}
floatParameter: 0
intParameter: 0
messageOptions: 0

View File

@ -400,49 +400,49 @@ AnimatorController:
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 0}
m_Controller: {fileID: 9100000}
- m_Name: BackToIdle
m_Type: 9
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 0}
m_Controller: {fileID: 9100000}
- m_Name: Build
m_Type: 9
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 0}
m_Controller: {fileID: 9100000}
- m_Name: TreeAttack
m_Type: 9
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 0}
m_Controller: {fileID: 9100000}
- m_Name: Move
m_Type: 9
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 0}
m_Controller: {fileID: 9100000}
- m_Name: SuperJump
m_Type: 9
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 0}
m_Controller: {fileID: 9100000}
- m_Name: Frozen
m_Type: 9
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 0}
m_Controller: {fileID: 9100000}
- m_Name: isMoving
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 0}
m_Controller: {fileID: 9100000}
m_AnimatorLayers:
- serializedVersion: 5
m_Name: Base Layer

View File

@ -7,12 +7,17 @@ using Object = UnityEngine.Object;
namespace Chars
{
struct AnimLength
{
public float Move;
}
public class Player : IUnit
{
private HexCoordinates _curentPosition;
private HexCoordinates spawnPos;
private bool _isAlive;
private GameObject _instance;
private GameObject prefab;
private AnimLength _animLength;
private HexCell _cell;
private HexGrid _hexGrid;
private Texture _texture;
@ -20,13 +25,15 @@ namespace Chars
private Animator _animator;
private PlayerView _playerView;
private bool _isMoving;
private static readonly int Moving = Animator.StringToHash("isMoving");
private static readonly int Move1 = Animator.StringToHash("Move");
private float _tick = 0.8f;
public bool IsMoving => _isMoving;
public GameObject Playerinstance => _instance;
public GameObject PlayerInstance => _instance;
public Player(PlayerData playerData, HexGrid hexGrid)
{
_curentPosition = playerData.spawnPos;
spawnPos = playerData.spawnPos;
prefab = playerData.playerPrefab;
_isAlive = false;
_hexGrid = hexGrid;
@ -37,44 +44,59 @@ namespace Chars
public void Move(HexDirection direction)
{
_tick = Time.time;
if (_cell.GetNeighbor(direction))
{
_isMoving = true;
_cell = _cell.GetNeighbor(direction);
_curentPosition = _cell.coordinates;
_instance.transform.LookAt(_cell.transform);
_animator.SetTrigger("Move");
_animator.SetBool("isMoving", _isMoving);
_animator.SetTrigger(Move1);
_animator.SetBool(Moving, _isMoving);
_playerView.OnStep += () =>
{
_isMoving = false;
_cell.PaintHex(_texture);
_animator.SetBool("isMoving", _isMoving);
_tick = Time.time - _tick;
_animator.SetBool(Moving, _isMoving);
};
_instance.transform.DOMove(_cell.transform.position, _animator.GetCurrentAnimatorClipInfo(0).LongLength);
_instance.transform.DOMove(_cell.transform.position, _animLength.Move);
}
}
private void SetAnimLength()
{
AnimationClip[] clips = _animator.runtimeAnimatorController.animationClips;
foreach(var clip in clips)
{
_animLength.Move = clip.name switch
{
"Jump" => clip.length,
_ => _animLength.Move
};
}
}
public void Spawn()
{
if (!_isAlive)
{
_cell = _hexGrid.GetCellFromCoord(_curentPosition);
_cell = _hexGrid.GetCellFromCoord(spawnPos);
_cell.PaintHex(_texture);
for (int i = 0; i < 6; i++)
{
_cell.GetNeighbor((HexDirection)i).PaintHex(_texture);
}
_instance = Object.Instantiate(prefab, _cell.transform.parent);
_instance.transform.localPosition = _cell.transform.localPosition;
OnPlayerSpawned?.Invoke(_instance);
_isAlive = true;
_animator = _instance.GetComponent<Animator>();
_playerView = _instance.GetComponent<PlayerView>();
SetAnimLength();
}
}