Working on ghost sync
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -39,6 +39,7 @@ namespace Marro.PacManUdon
|
|||||||
[SerializeField] private PacManGhostType ghostType;
|
[SerializeField] private PacManGhostType ghostType;
|
||||||
[SerializeField] private PacManGhostStartState startState;
|
[SerializeField] private PacManGhostStartState startState;
|
||||||
|
|
||||||
|
// External references
|
||||||
private GhostManager ghostManager;
|
private GhostManager ghostManager;
|
||||||
private Animator animator;
|
private Animator animator;
|
||||||
private new Renderer renderer;
|
private new Renderer renderer;
|
||||||
@@ -54,31 +55,36 @@ namespace Marro.PacManUdon
|
|||||||
private Vector2 idlePosition2;
|
private Vector2 idlePosition2;
|
||||||
private Vector2 cornerPosition;
|
private Vector2 cornerPosition;
|
||||||
|
|
||||||
private bool kinematic;
|
// Pathfinding
|
||||||
|
private Vector2 target;
|
||||||
private bool horizontalOnly;
|
private bool horizontalOnly;
|
||||||
private int housePelletCounterLimit;
|
private bool inTunnel;
|
||||||
|
private int rngState;
|
||||||
|
private bool turnAroundSoon;
|
||||||
|
|
||||||
|
private float speed;
|
||||||
|
|
||||||
|
// State
|
||||||
|
private PacManGhostState ghostState;
|
||||||
|
private bool isScared;
|
||||||
|
private bool scattering;
|
||||||
|
private PacManGhostFrozenState frozenState;
|
||||||
|
|
||||||
|
// Home
|
||||||
|
private bool offGrid;
|
||||||
|
private int housePelletCounter;
|
||||||
|
private bool housePelletCounterActive;
|
||||||
|
private int housePelletCounterLimit;
|
||||||
private bool faceInStartingDirectionUntilUnfrozen;
|
private bool faceInStartingDirectionUntilUnfrozen;
|
||||||
|
|
||||||
|
// Cutscene
|
||||||
|
private bool kinematic;
|
||||||
private bool specialLook;
|
private bool specialLook;
|
||||||
|
|
||||||
private bool followingPredefinedPath;
|
private bool followingPredefinedPath;
|
||||||
private Vector2[] predefinedPath;
|
private Vector2[] predefinedPath;
|
||||||
private int predefinedPathIndex;
|
private int predefinedPathIndex;
|
||||||
|
|
||||||
int rngState;
|
|
||||||
private float speed;
|
|
||||||
private Vector2 target;
|
|
||||||
private bool offGrid;
|
|
||||||
private bool inTunnel;
|
|
||||||
private PacManGhostState ghostState;
|
|
||||||
private bool isScared;
|
|
||||||
private bool scattering;
|
|
||||||
private PacManGhostFrozenState frozenState;
|
|
||||||
private int housePelletCounter;
|
|
||||||
private bool housePelletCounterActive;
|
|
||||||
private bool turnAroundSoon;
|
|
||||||
|
|
||||||
public void Initialize(PacMan pacMan, Ghost blinky, Transform startTransform, Vector2 homePosition, Vector2 idlePosition1, Vector2 idlePosition2, Vector2 cornerPosition)
|
public void Initialize(PacMan pacMan, Ghost blinky, Transform startTransform, Vector2 homePosition, Vector2 idlePosition1, Vector2 idlePosition2, Vector2 cornerPosition)
|
||||||
{
|
{
|
||||||
ghostManager = transform.parent.GetComponent<GhostManager>();
|
ghostManager = transform.parent.GetComponent<GhostManager>();
|
||||||
@@ -760,6 +766,62 @@ namespace Marro.PacManUdon
|
|||||||
UpdateAnimator();
|
UpdateAnimator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
|
||||||
|
{
|
||||||
|
if (eventType != NetworkEventType.GhostUpdate)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
data.Append(target, ref index);
|
||||||
|
data.Append(horizontalOnly, ref index);
|
||||||
|
data.Append(inTunnel, ref index);
|
||||||
|
data.Append(rngState, ref index);
|
||||||
|
data.Append(turnAroundSoon, ref index);
|
||||||
|
data.Append(speed, ref index);
|
||||||
|
|
||||||
|
data.Append((byte)ghostState, ref index);
|
||||||
|
data.Append(isScared, ref index);
|
||||||
|
data.Append(scattering, ref index);
|
||||||
|
data.Append((byte)frozenState, ref index);
|
||||||
|
|
||||||
|
data.Append(offGrid, ref index);
|
||||||
|
data.Append((byte)housePelletCounter, ref index);
|
||||||
|
data.Append(housePelletCounterActive, ref index);
|
||||||
|
data.Append((byte)housePelletCounterLimit, ref index);
|
||||||
|
data.Append(faceInStartingDirectionUntilUnfrozen, ref index);
|
||||||
|
|
||||||
|
base.CollectSyncedData(data, ref index, eventType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
|
||||||
|
{
|
||||||
|
if (eventType != NetworkEventType.GhostUpdate)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
target = data.ReadVector2(ref index);
|
||||||
|
horizontalOnly = data.ReadBool(ref index);
|
||||||
|
inTunnel = data.ReadBool(ref index);
|
||||||
|
rngState = data.ReadInt(ref index);
|
||||||
|
turnAroundSoon = data.ReadBool(ref index);
|
||||||
|
speed = data.ReadFloat(ref index);
|
||||||
|
|
||||||
|
ghostState = (PacManGhostState)data.ReadByte(ref index);
|
||||||
|
isScared = data.ReadBool(ref index);
|
||||||
|
scattering = data.ReadBool(ref index);
|
||||||
|
frozenState = (PacManGhostFrozenState)data.ReadByte(ref index);
|
||||||
|
|
||||||
|
offGrid = data.ReadBool(ref index);
|
||||||
|
housePelletCounter = data.ReadByte(ref index);
|
||||||
|
housePelletCounterActive = data.ReadBool(ref index);
|
||||||
|
housePelletCounterLimit = data.ReadByte(ref index);
|
||||||
|
faceInStartingDirectionUntilUnfrozen = data.ReadBool(ref index);
|
||||||
|
|
||||||
|
return base.WriteSyncedData(data, ref index, eventType);
|
||||||
|
}
|
||||||
|
|
||||||
void OnTriggerEnter(Collider other)
|
void OnTriggerEnter(Collider other)
|
||||||
{
|
{
|
||||||
if (other.gameObject.GetComponent<PacManGhostCollider>())
|
if (other.gameObject.GetComponent<PacManGhostCollider>())
|
||||||
@@ -796,14 +858,5 @@ namespace Marro.PacManUdon
|
|||||||
SetInTunnel(false);
|
SetInTunnel(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PacManGhostState State
|
|
||||||
{
|
|
||||||
set
|
|
||||||
{
|
|
||||||
SetState(value);
|
|
||||||
}
|
|
||||||
get => ghostState;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -16,6 +16,7 @@ namespace Marro.PacManUdon
|
|||||||
PacManTurn = 2,
|
PacManTurn = 2,
|
||||||
StartGameButtonPressed = 3,
|
StartGameButtonPressed = 3,
|
||||||
SyncPellets = 4,
|
SyncPellets = 4,
|
||||||
|
GhostUpdate = 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
public class NetworkManager : UdonSharpBehaviour
|
public class NetworkManager : UdonSharpBehaviour
|
||||||
|
|||||||
Reference in New Issue
Block a user