Animation refactor mostly done
This commit is contained in:
@@ -89,6 +89,9 @@ namespace Marro.PacManUdon
|
||||
public bool IsScared => isScared;
|
||||
public int Index { get; private set; }
|
||||
|
||||
private readonly int animatorKeyDirection = Animator.StringToHash("Direction");
|
||||
private readonly int animatorKeyGhostType = Animator.StringToHash("GhostType");
|
||||
|
||||
public void Initialize(CollisionManager collisionManager, PacMan pacMan, Ghost blinky, Transform startTransform, Vector2 homePosition, Vector2 idlePosition1, Vector2 idlePosition2, Vector2 cornerPosition, int index)
|
||||
{
|
||||
ghostManager = transform.parent.GetComponent<GhostManager>();
|
||||
@@ -341,20 +344,9 @@ namespace Marro.PacManUdon
|
||||
// }
|
||||
if (isScared)
|
||||
{
|
||||
switch (PseudoRNG() % 4)
|
||||
{
|
||||
default:
|
||||
return gridPosition;
|
||||
case 0:
|
||||
return gridPosition + Vector2.up;
|
||||
case 1:
|
||||
return gridPosition + Vector2.left;
|
||||
case 2:
|
||||
return gridPosition + Vector2.down;
|
||||
case 3:
|
||||
return gridPosition + Vector2.right;
|
||||
}
|
||||
return gridPosition + directionVectors[(int)cardinalDirections[PseudoRNG() % 4]];
|
||||
}
|
||||
|
||||
switch (ghostState)
|
||||
{
|
||||
default:
|
||||
@@ -456,7 +448,7 @@ namespace Marro.PacManUdon
|
||||
rngState ^= rngState << 13;
|
||||
rngState ^= rngState >> 17;
|
||||
rngState ^= rngState << 5;
|
||||
return rngState;
|
||||
return Math.Abs(rngState);
|
||||
}
|
||||
|
||||
private readonly Direction[] cardinalDirections = new Direction[] { Direction.Up, Direction.Left, Direction.Down, Direction.Right };
|
||||
@@ -507,16 +499,12 @@ namespace Marro.PacManUdon
|
||||
// Debug.Log($"{gameObject} UpdateAnimator with state: {ghostState}, isScared: {isScared}, direction: {direction}");
|
||||
if (specialLook)
|
||||
{
|
||||
animator.SetFloat("GhostType", GhostTypeToAnimationValue(PacManGhostType.Special));
|
||||
SetAnimatorGhostType((int)PacManGhostType.Special);
|
||||
}
|
||||
else if (isScared)
|
||||
{
|
||||
float currentGhostType = animator.GetFloat("GhostType");
|
||||
if (currentGhostType > 0.5f && currentGhostType < 2.5f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
animator.SetFloat("GhostType", GhostTypeToAnimationValue(PacManGhostType.Scared));
|
||||
|
||||
SetAnimatorGhostType((int)PacManGhostType.Scared);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -527,58 +515,35 @@ namespace Marro.PacManUdon
|
||||
case PacManGhostState.Home:
|
||||
case PacManGhostState.Exiting:
|
||||
// Debug.Log($"{gameObject} Set GhostType in animator to: {GhostTypeToAnimationValue(ghostType)}");
|
||||
animator.SetFloat("GhostType", GhostTypeToAnimationValue(ghostType));
|
||||
SetAnimatorGhostType((int)ghostType);
|
||||
break;
|
||||
case PacManGhostState.Returning:
|
||||
case PacManGhostState.Entering:
|
||||
animator.SetFloat("GhostType", GhostTypeToAnimationValue(PacManGhostType.Caught));
|
||||
SetAnimatorGhostType((int)PacManGhostType.Caught);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (faceInStartingDirectionUntilUnfrozen && startState == PacManGhostStartState.TargetingIdlePosition1)
|
||||
{
|
||||
animator.SetFloat("DirX", 0);
|
||||
animator.SetFloat("DirY", 1);
|
||||
SetAnimatorDirection((int)Direction.Up);
|
||||
}
|
||||
else if (faceInStartingDirectionUntilUnfrozen && startState == PacManGhostStartState.TargetingIdlePosition2)
|
||||
{
|
||||
animator.SetFloat("DirX", 0);
|
||||
animator.SetFloat("DirY", -1);
|
||||
SetAnimatorDirection((int)Direction.Down);
|
||||
}
|
||||
else if (specialLook || targetDirection != Direction.Zero)
|
||||
{
|
||||
var vector = GetVector(targetDirection);
|
||||
animator.SetFloat("DirX", vector.x);
|
||||
animator.SetFloat("DirY", vector.y);
|
||||
SetAnimatorDirection((int)targetDirection);
|
||||
}
|
||||
}
|
||||
|
||||
private float GhostTypeToAnimationValue(PacManGhostType ghostType)
|
||||
{
|
||||
switch (ghostType)
|
||||
{
|
||||
default:
|
||||
Debug.LogError("Invalid ghost animation value!");
|
||||
return 0;
|
||||
case PacManGhostType.Caught:
|
||||
return 0;
|
||||
case PacManGhostType.Scared:
|
||||
return 1;
|
||||
case PacManGhostType.ScaredWhite:
|
||||
return 2;
|
||||
case PacManGhostType.Blinky:
|
||||
return 3;
|
||||
case PacManGhostType.Pinky:
|
||||
return 4;
|
||||
case PacManGhostType.Inky:
|
||||
return 5;
|
||||
case PacManGhostType.Clyde:
|
||||
return 6;
|
||||
case PacManGhostType.Special:
|
||||
return 7;
|
||||
}
|
||||
}
|
||||
// A Udon bug means converting an enum to a float causes an exception unless the conversion from int to float is in a separate method
|
||||
private void SetAnimatorDirection(int value) =>
|
||||
animator.SetFloat(animatorKeyDirection, value);
|
||||
|
||||
private void SetAnimatorGhostType(int value) =>
|
||||
animator.SetFloat(animatorKeyGhostType, value);
|
||||
|
||||
public void UpdateSpeed()
|
||||
{
|
||||
@@ -743,14 +708,7 @@ namespace Marro.PacManUdon
|
||||
if (!isScared || !gameObject.activeInHierarchy)
|
||||
return;
|
||||
|
||||
if (white)
|
||||
{
|
||||
animator.SetFloat("GhostType", 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
animator.SetFloat("GhostType", 1);
|
||||
}
|
||||
SetAnimatorGhostType(white ? (int)PacManGhostType.ScaredWhite : (int)PacManGhostType.Scared);
|
||||
}
|
||||
|
||||
public void SetElroy(int elroyLevel)
|
||||
|
||||
Reference in New Issue
Block a user