fix animation end action, fast forward work as expected

This commit is contained in:
Vladimir Koshevarov
2023-03-14 13:16:15 +02:00
parent 9208aa251f
commit f6a8ca9d9d
6 changed files with 25 additions and 19 deletions
+17 -5
View File
@@ -1,6 +1,5 @@
using Assets.Scripts.Actions.Interfaces;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
@@ -33,6 +32,7 @@ public class Player : MonoBehaviour
private const string WALK_VELOCITY = "WalkVelocity";
private ContainerItem _containerItem;
private Action _OnAnimationFinish;
private void Awake()
{
@@ -64,8 +64,15 @@ public class Player : MonoBehaviour
{
if (IsBlockingAnimation(_currentAnimation))
{
StartCoroutine(IsAnimationStatePlaying(0));
if (IsAnimationStatePlaying(0))
{
return;
}
else
{
_OnAnimationFinish?.Invoke();
_OnAnimationFinish = null;
}
}
if (_currentTask == null || _currentTask.Status == TaskStatus.Complete)
@@ -164,6 +171,11 @@ public class Player : MonoBehaviour
return TaskStatus.Complete;
}
public void SetPlayerAnimation(AnimationStates newState, Action onAnimationFinish)
{
_OnAnimationFinish = onAnimationFinish;
SetPlayerAnimation(newState);
}
public void SetPlayerAnimation(AnimationStates newState)
{
if (newState == _currentAnimation)
@@ -175,12 +187,12 @@ public class Player : MonoBehaviour
}
public IEnumerator IsAnimationStatePlaying(int animLayer)
public bool IsAnimationStatePlaying(int animLayer)
{
string stateName = GetEnumMemberValue(_currentAnimation);
var stateInfo = _animator.GetCurrentAnimatorStateInfo(animLayer);
yield return new WaitWhile(() => stateInfo.IsName(stateName) && stateInfo.normalizedTime < 1.0f);
yield break;
return stateInfo.IsName(stateName) && stateInfo.normalizedTime < 1.0f;
}
public void AddTask(PlayerTasks task)