Initial progress syncing + many existing bugs

This commit is contained in:
2026-01-15 23:00:15 +01:00
parent fb902aaddc
commit c41491e55e
11 changed files with 345 additions and 230 deletions

View File

@@ -43,7 +43,7 @@ namespace Marro.PacManUdon
#endregion
public void Initialize(PlayerInput input, GameManager gameController)
public void Initialize(PlayerInput input, Transform startTransform, GameManager gameController)
{
this.gameController = gameController;
this.input = input;
@@ -51,14 +51,13 @@ namespace Marro.PacManUdon
renderer = GetComponent<Renderer>();
frozen = false;
hideUntilUnfrozen = false;
startPosition = transform.localPosition;
startRotation = transform.localRotation;
startScale = transform.localScale;
startPosition = startTransform.localPosition;
startRotation = startTransform.localRotation;
startScale = startTransform.localScale;
}
public void Reset()
{
// Debug.Log($"{gameObject} Reset!");
transform.SetLocalPositionAndRotation(startPosition, startRotation);
transform.localScale = startScale;
direction = Vector2.left;
@@ -69,6 +68,8 @@ namespace Marro.PacManUdon
SetDead(false);
animator.SetTrigger("Reset");
Debug.Log($"{gameObject} Reset! Position is now {GetPosition()}.");
}
public override void SyncedUpdate()
@@ -155,6 +156,7 @@ namespace Marro.PacManUdon
SetDirection(inputDirection + new Vector2(GridMoverTools.PositionToGrid(nextPosition).x - nextPosition.x, 0).normalized);
}
SetTargetDirection(inputDirection); // This is the direction most logic should assume pacman is moving, the actual direction may be different due to cornering
networkManager.SendEvent(NetworkEventType.PacManTurn);
}
return nextPosition;
@@ -338,5 +340,31 @@ namespace Marro.PacManUdon
gameController.GotFruit();
}
}
public override void AppendSyncedData(byte[][] data, ref int offset, NetworkEventType eventType)
{
if (eventType != NetworkEventType.PacManTurn || kinematic || frozen || !enabled)
{
return;
}
data[offset++] = BitConverter.GetBytes(targetDirection.x);
data[offset++] = BitConverter.GetBytes(targetDirection.y);
base.AppendSyncedData(data, ref offset, eventType);
}
public override bool SetSyncedData(byte[] data, ref int offset, NetworkEventType eventType)
{
if (eventType != NetworkEventType.PacManTurn || kinematic || frozen || !enabled)
{
return true;
}
SetTargetDirection(new Vector2(BitConverter.ToSingle(data, offset), BitConverter.ToSingle(data, offset + 4)));
offset += 8;
return base.SetSyncedData(data, ref offset, eventType);
}
}
}