Animation refactor mostly done
This commit is contained in:
@@ -3,6 +3,15 @@ using UnityEngine;
|
||||
|
||||
namespace Marro.PacManUdon
|
||||
{
|
||||
enum PacManAnimatorState
|
||||
{
|
||||
Idle,
|
||||
Moving,
|
||||
Stopped,
|
||||
Dead,
|
||||
Big
|
||||
}
|
||||
|
||||
[RequireComponent(typeof(Animator))]
|
||||
[RequireComponent(typeof(Renderer))]
|
||||
public class PacMan : GridMover
|
||||
@@ -29,14 +38,8 @@ namespace Marro.PacManUdon
|
||||
private bool frozen;
|
||||
|
||||
#region Animator constants
|
||||
private const string AnimatorKeyDead = "Dead";
|
||||
private const string AnimatorKeyDirection = "Direction";
|
||||
private const float AnimatorDirectionNone = 0f;
|
||||
private const float AnimatorDirectionRight = 0.25f;
|
||||
private const float AnimatorDirectionLeft = 0.50f;
|
||||
private const float AnimatorDirectionDown = 0.75f;
|
||||
private const float AnimatorDirectionUp = 1f;
|
||||
private const float AnimatorDirectionRightBig = 1.25f;
|
||||
private readonly int animatorKeyState = Animator.StringToHash("State");
|
||||
private readonly int animatorKeyDirection = Animator.StringToHash("Direction");
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -65,9 +68,8 @@ namespace Marro.PacManUdon
|
||||
followingPredefinedPath = false;
|
||||
|
||||
SetDead(false);
|
||||
animator.SetTrigger("Reset");
|
||||
|
||||
//Debug.Log($"{gameObject} Reset! Position is now {GetPosition()}.");
|
||||
SetAnimatorState((int)PacManAnimatorState.Idle);
|
||||
}
|
||||
|
||||
public override void SyncedUpdate()
|
||||
@@ -225,44 +227,41 @@ namespace Marro.PacManUdon
|
||||
|
||||
protected override void UpdateAnimator()
|
||||
{
|
||||
// Debug.Log($"{gameObject} UpdateAnimator with direction {direction}, dead {dead}, frozen {frozen}");
|
||||
Debug.Log($"{gameObject} UpdateAnimator with direction {direction}, dead {dead}, frozen {frozen}");
|
||||
if (!gameObject.activeInHierarchy)
|
||||
return;
|
||||
|
||||
animator.SetBool(AnimatorKeyDead, dead);
|
||||
if (dead)
|
||||
{
|
||||
SetAnimatorState((int)PacManAnimatorState.Dead);
|
||||
animator.speed = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (frozen || direction.Equals(Direction.Zero))
|
||||
animator.speed = frozen ? 0 : 1;
|
||||
|
||||
if (frozen)
|
||||
{
|
||||
animator.SetFloat(AnimatorKeyDirection, AnimatorDirectionNone);
|
||||
animator.speed = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (direction.Equals(Direction.Zero))
|
||||
{
|
||||
SetAnimatorState((int)PacManAnimatorState.Stopped);
|
||||
}
|
||||
else
|
||||
{
|
||||
animator.speed = 1;
|
||||
if (targetDirection.Equals(Direction.Right))
|
||||
{
|
||||
animator.SetFloat(AnimatorKeyDirection, AnimatorDirectionRight);
|
||||
}
|
||||
else if (targetDirection.Equals(Direction.Left))
|
||||
{
|
||||
animator.SetFloat(AnimatorKeyDirection, AnimatorDirectionLeft);
|
||||
}
|
||||
else if (targetDirection.Equals(Direction.Down))
|
||||
{
|
||||
animator.SetFloat(AnimatorKeyDirection, AnimatorDirectionDown);
|
||||
}
|
||||
else if (targetDirection.Equals(Direction.Up))
|
||||
{
|
||||
animator.SetFloat(AnimatorKeyDirection, AnimatorDirectionUp);
|
||||
}
|
||||
SetAnimatorState((int)PacManAnimatorState.Moving);
|
||||
SetAnimatorDirection((int)targetDirection);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetAnimatorDirection(int value) =>
|
||||
animator.SetFloat(animatorKeyDirection, value);
|
||||
|
||||
private void SetAnimatorState(int value) =>
|
||||
animator.SetFloat(animatorKeyState, value);
|
||||
|
||||
public void SetDead(bool dead)
|
||||
{
|
||||
this.dead = dead;
|
||||
@@ -324,7 +323,7 @@ namespace Marro.PacManUdon
|
||||
|
||||
public void BecomeBig()
|
||||
{
|
||||
animator.SetFloat(AnimatorKeyDirection, AnimatorDirectionRightBig);
|
||||
SetAnimatorState((int)PacManAnimatorState.Big);
|
||||
}
|
||||
|
||||
void SetVisibility(bool visible)
|
||||
|
||||
Reference in New Issue
Block a user