Animation refactor mostly done
This commit is contained in:
@@ -43,7 +43,7 @@ MonoBehaviour:
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 12
|
||||
Data: 42
|
||||
Data: 44
|
||||
- Name:
|
||||
Entry: 7
|
||||
Data:
|
||||
@@ -2122,19 +2122,19 @@ MonoBehaviour:
|
||||
Data:
|
||||
- Name: $k
|
||||
Entry: 1
|
||||
Data: cardinalDirections
|
||||
Data: animatorKeyDirection
|
||||
- Name: $v
|
||||
Entry: 7
|
||||
Data: 107|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
|
||||
- Name: <Name>k__BackingField
|
||||
Entry: 1
|
||||
Data: cardinalDirections
|
||||
Data: animatorKeyDirection
|
||||
- Name: <UserType>k__BackingField
|
||||
Entry: 9
|
||||
Data: 100
|
||||
Data: 8
|
||||
- Name: <SystemType>k__BackingField
|
||||
Entry: 9
|
||||
Data: 101
|
||||
Data: 8
|
||||
- Name: <SyncMode>k__BackingField
|
||||
Entry: 7
|
||||
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
|
||||
@@ -2171,19 +2171,19 @@ MonoBehaviour:
|
||||
Data:
|
||||
- Name: $k
|
||||
Entry: 1
|
||||
Data: horizontalDirections
|
||||
Data: animatorKeyGhostType
|
||||
- Name: $v
|
||||
Entry: 7
|
||||
Data: 109|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
|
||||
- Name: <Name>k__BackingField
|
||||
Entry: 1
|
||||
Data: horizontalDirections
|
||||
Data: animatorKeyGhostType
|
||||
- Name: <UserType>k__BackingField
|
||||
Entry: 9
|
||||
Data: 100
|
||||
Data: 8
|
||||
- Name: <SystemType>k__BackingField
|
||||
Entry: 9
|
||||
Data: 101
|
||||
Data: 8
|
||||
- Name: <SyncMode>k__BackingField
|
||||
Entry: 7
|
||||
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
|
||||
@@ -2215,6 +2215,104 @@ MonoBehaviour:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 7
|
||||
Data:
|
||||
- Name: $k
|
||||
Entry: 1
|
||||
Data: cardinalDirections
|
||||
- Name: $v
|
||||
Entry: 7
|
||||
Data: 111|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
|
||||
- Name: <Name>k__BackingField
|
||||
Entry: 1
|
||||
Data: cardinalDirections
|
||||
- Name: <UserType>k__BackingField
|
||||
Entry: 9
|
||||
Data: 100
|
||||
- Name: <SystemType>k__BackingField
|
||||
Entry: 9
|
||||
Data: 101
|
||||
- Name: <SyncMode>k__BackingField
|
||||
Entry: 7
|
||||
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
|
||||
- Name:
|
||||
Entry: 6
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name: <IsSerialized>k__BackingField
|
||||
Entry: 5
|
||||
Data: false
|
||||
- Name: _fieldAttributes
|
||||
Entry: 7
|
||||
Data: 112|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
|
||||
mscorlib
|
||||
- Name:
|
||||
Entry: 12
|
||||
Data: 0
|
||||
- Name:
|
||||
Entry: 13
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 7
|
||||
Data:
|
||||
- Name: $k
|
||||
Entry: 1
|
||||
Data: horizontalDirections
|
||||
- Name: $v
|
||||
Entry: 7
|
||||
Data: 113|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
|
||||
- Name: <Name>k__BackingField
|
||||
Entry: 1
|
||||
Data: horizontalDirections
|
||||
- Name: <UserType>k__BackingField
|
||||
Entry: 9
|
||||
Data: 100
|
||||
- Name: <SystemType>k__BackingField
|
||||
Entry: 9
|
||||
Data: 101
|
||||
- Name: <SyncMode>k__BackingField
|
||||
Entry: 7
|
||||
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
|
||||
- Name:
|
||||
Entry: 6
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name: <IsSerialized>k__BackingField
|
||||
Entry: 5
|
||||
Data: false
|
||||
- Name: _fieldAttributes
|
||||
Entry: 7
|
||||
Data: 114|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
|
||||
mscorlib
|
||||
- Name:
|
||||
Entry: 12
|
||||
Data: 0
|
||||
- Name:
|
||||
Entry: 13
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 13
|
||||
Data:
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -43,7 +43,7 @@ MonoBehaviour:
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 12
|
||||
Data: 22
|
||||
Data: 24
|
||||
- Name:
|
||||
Entry: 7
|
||||
Data:
|
||||
@@ -1196,6 +1196,102 @@ MonoBehaviour:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 7
|
||||
Data:
|
||||
- Name: $k
|
||||
Entry: 1
|
||||
Data: animatorKeyState
|
||||
- Name: $v
|
||||
Entry: 7
|
||||
Data: 62|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
|
||||
- Name: <Name>k__BackingField
|
||||
Entry: 1
|
||||
Data: animatorKeyState
|
||||
- Name: <UserType>k__BackingField
|
||||
Entry: 9
|
||||
Data: 8
|
||||
- Name: <SystemType>k__BackingField
|
||||
Entry: 9
|
||||
Data: 8
|
||||
- Name: <SyncMode>k__BackingField
|
||||
Entry: 7
|
||||
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
|
||||
- Name:
|
||||
Entry: 6
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name: <IsSerialized>k__BackingField
|
||||
Entry: 5
|
||||
Data: false
|
||||
- Name: _fieldAttributes
|
||||
Entry: 7
|
||||
Data: 63|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
|
||||
- Name:
|
||||
Entry: 12
|
||||
Data: 0
|
||||
- Name:
|
||||
Entry: 13
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 7
|
||||
Data:
|
||||
- Name: $k
|
||||
Entry: 1
|
||||
Data: animatorKeyDirection
|
||||
- Name: $v
|
||||
Entry: 7
|
||||
Data: 64|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
|
||||
- Name: <Name>k__BackingField
|
||||
Entry: 1
|
||||
Data: animatorKeyDirection
|
||||
- Name: <UserType>k__BackingField
|
||||
Entry: 9
|
||||
Data: 8
|
||||
- Name: <SystemType>k__BackingField
|
||||
Entry: 9
|
||||
Data: 8
|
||||
- Name: <SyncMode>k__BackingField
|
||||
Entry: 7
|
||||
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
|
||||
- Name:
|
||||
Entry: 6
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name: <IsSerialized>k__BackingField
|
||||
Entry: 5
|
||||
Data: false
|
||||
- Name: _fieldAttributes
|
||||
Entry: 7
|
||||
Data: 65|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
|
||||
- Name:
|
||||
Entry: 12
|
||||
Data: 0
|
||||
- Name:
|
||||
Entry: 13
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 8
|
||||
Data:
|
||||
- Name:
|
||||
Entry: 13
|
||||
Data:
|
||||
|
||||
@@ -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