fixed moving and animations
This commit is contained in:
parent
ac7e2a0b52
commit
be4ababa0b
18
Assets/PlayerView.cs
Normal file
18
Assets/PlayerView.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerView : MonoBehaviour
|
||||
{
|
||||
private Animator _animator;
|
||||
public Action OnStep;
|
||||
|
||||
void Start()
|
||||
{
|
||||
_animator.GetComponent<Animator>();
|
||||
}
|
||||
|
||||
public void Step()
|
||||
{
|
||||
OnStep?.Invoke();
|
||||
}
|
||||
}
|
11
Assets/PlayerView.cs.meta
Normal file
11
Assets/PlayerView.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 04619977b07331e43a21b8d1bc33b6e9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -19,7 +19,10 @@ namespace Chars
|
||||
public Action<GameObject> 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<Animator>();
|
||||
_playerView = _instance.GetComponent<PlayerView>();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
|
Loading…
x
Reference in New Issue
Block a user