Compare commits

..

2 Commits

Author SHA1 Message Date
73b3194c51 Switched to Direction enum 2026-06-15 10:29:36 +02:00
2ccf77c0eb Tools for testing 2026-06-11 19:24:09 +02:00
30 changed files with 4464 additions and 2363 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 186 B

View File

@@ -0,0 +1,114 @@
fileFormatVersion: 2
guid: 433bc126202e0994fa11758168105efa
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 12
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -10184,17 +10184,11 @@ MonoBehaviour:
SerializationNodes: [] SerializationNodes: []
_udonSharpBackingUdonBehaviour: {fileID: 1180286844452673728} _udonSharpBackingUdonBehaviour: {fileID: 1180286844452673728}
networkManager: {fileID: 0} networkManager: {fileID: 0}
networkEventSubscribersFlat:
- {fileID: 7714172614521704433}
- {fileID: 7714172614521704433}
- {fileID: 7714172614521704433}
- {fileID: 7714172614521704433}
networkEventSubscribersFlatSegmentLengths: 000000000000000003000000ffffffff000000000000000000000000000000000000000000000000
root: {fileID: 6505452106475299050} root: {fileID: 6505452106475299050}
delay: 1 delay: 50
maxEventSendTries: 3 maxEventSendTries: 3
pingDelay: 0.3 pingDelay: 15
updateDelta: 0.016666668 tickDelta: 0.016666668
DebugImageToIndicateOwner: {fileID: 3129450115522694373} DebugImageToIndicateOwner: {fileID: 3129450115522694373}
DebugImageToIndicateSynced: {fileID: 762605392980976710} DebugImageToIndicateSynced: {fileID: 762605392980976710}
DebugImageToIndicateReady: {fileID: 1191965255371285111} DebugImageToIndicateReady: {fileID: 1191965255371285111}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -59,7 +59,7 @@ namespace Marro.PacManUdon
networkManager.Initialize(); networkManager.Initialize();
ghostManager.Initialize(maze.ghostStarts, maze.ghostTargets, pacMan, pelletManager, this); ghostManager.Initialize(maze.ghostStarts, maze.ghostTargets, pacMan, pelletManager, this);
pacMan.Initialize(playerInput, maze.pacManStart, this); pacMan.Initialize(playerInput, maze.pacManStart, this, pelletManager);
bonusFruit.Initialize(); bonusFruit.Initialize();
pelletManager.Initialize(); pelletManager.Initialize();
statusDisplay.Initialize(); statusDisplay.Initialize();

File diff suppressed because it is too large Load Diff

View File

@@ -41,6 +41,7 @@ namespace Marro.PacManUdon
// External references // External references
private GhostManager ghostManager; private GhostManager ghostManager;
private PelletManager pelletManager;
private Animator animator; private Animator animator;
private new Renderer renderer; private new Renderer renderer;
private PacMan pacMan; private PacMan pacMan;
@@ -88,12 +89,13 @@ namespace Marro.PacManUdon
public bool IsScared => isScared; public bool IsScared => isScared;
public int Index { get; private set; } public int Index { get; private set; }
public void Initialize(PacMan pacMan, Ghost blinky, Transform startTransform, Vector2 homePosition, Vector2 idlePosition1, Vector2 idlePosition2, Vector2 cornerPosition, int index) public void Initialize(PelletManager pelletManager, PacMan pacMan, Ghost blinky, Transform startTransform, Vector2 homePosition, Vector2 idlePosition1, Vector2 idlePosition2, Vector2 cornerPosition, int index)
{ {
ghostManager = transform.parent.GetComponent<GhostManager>(); ghostManager = transform.parent.GetComponent<GhostManager>();
animator = GetComponent<Animator>(); animator = GetComponent<Animator>();
renderer = GetComponent<Renderer>(); renderer = GetComponent<Renderer>();
this.pelletManager = pelletManager;
this.pacMan = pacMan; this.pacMan = pacMan;
this.blinky = blinky; this.blinky = blinky;
this.homePosition = homePosition; this.homePosition = homePosition;
@@ -158,7 +160,7 @@ namespace Marro.PacManUdon
} }
Vector2 position = GetPosition(); Vector2 position = GetPosition();
Vector2 nextPosition = GridMoverTools.GetNextPosition(position, direction, speed, networkManager.SyncedDeltaTime); Vector2 nextPosition = GetNextPosition(position, directionVectors[(int)direction], speed, networkManager.SyncedDeltaTime);
nextPosition = ProcessNextPosition(position, nextPosition); nextPosition = ProcessNextPosition(position, nextPosition);
@@ -168,10 +170,11 @@ namespace Marro.PacManUdon
private Vector2 ProcessNextPosition(Vector2 position, Vector2 nextPosition) private Vector2 ProcessNextPosition(Vector2 position, Vector2 nextPosition)
{ {
if (turnAroundSoon && ghostState == PacManGhostState.Normal if (turnAroundSoon && ghostState == PacManGhostState.Normal
&& GridMoverTools.CrossesTileBorder(position, nextPosition, direction.x != 0, direction.y != 0)) && CrossesTileBorder(position, nextPosition, direction))
{ {
SetDirection(direction * -1); var newDirection = GetInverseDirection(direction);
//Debug.Log($"{gameObject} turned around to direction {GetDirection()}"); Debug.Log($"{gameObject} turned around from direction {direction} to {newDirection}");
SetDirection(newDirection);
turnAroundSoon = false; turnAroundSoon = false;
return nextPosition; return nextPosition;
} }
@@ -216,21 +219,19 @@ namespace Marro.PacManUdon
{ {
nextPosition = ProcessPredefinedPath(position, nextPosition); nextPosition = ProcessPredefinedPath(position, nextPosition);
} }
else if (!offGrid && GridMoverTools.CrossesTileCenter(position, nextPosition, direction.x != 0, direction.y != 0)) else if (!offGrid && CrossesTileCenter(position, nextPosition, direction))
{ {
Vector2 gridPosition = GridMoverTools.PositionToGrid(position); var gridPosition = PositionToGrid(position);
Vector2[] availableDirections = GetAvailableDirections(gridPosition, direction * -1); var blockedDirections = pelletManager.GetBlockedDirections(position);
if (availableDirections.Length > 1) blockedDirections[GetIllegalCardinalDirection(direction)] = true; // Not allowed to turn around
target = GetGridTarget(gridPosition);
var newDirection = GetGridDirectionToTargetGreedy(blockedDirections, gridPosition, target);
if (newDirection != direction)
{ {
target = GetGridTarget(gridPosition); Debug.Log($"{gameObject.name} Was moving in direction {direction}, continues with moving in direction {newDirection}");
SetDirection(GetGridDirectionToTargetGreedy(availableDirections, gridPosition, target)); nextPosition = GetNextPosition(gridPosition, directionVectors[(int)newDirection], speed, networkManager.SyncedDeltaTime);
nextPosition = GridMoverTools.GetNextPosition(gridPosition, direction, speed, networkManager.SyncedDeltaTime); SetDirection(newDirection);
// Debug.Log($"GetNextPosition at gridPosition {gridPosition} with direction {direction} and speed {speed} gives nextPosition {nextPosition}");
}
else if (availableDirections.Length == 1 && availableDirections[0] != direction)
{
SetDirection(availableDirections[0]);
nextPosition = GridMoverTools.GetNextPosition(gridPosition, direction, speed, networkManager.SyncedDeltaTime);
} }
// Debug.Log($"{gameObject} crossed tile center {gridPosition}, new target: {target}, new direction: {direction}"); // Debug.Log($"{gameObject} crossed tile center {gridPosition}, new target: {target}, new direction: {direction}");
} }
@@ -244,9 +245,26 @@ namespace Marro.PacManUdon
return nextPosition; return nextPosition;
} }
private int GetIllegalCardinalDirection(Direction direction)
{
switch (direction)
{
case Direction.Up:
return 1;
case Direction.Down:
return 0;
case Direction.Left:
return 3;
case Direction.Right:
return 2;
default:
return 0;
}
}
private Vector2 ProcessPredefinedPath(Vector2 position, Vector2 nextPosition) private Vector2 ProcessPredefinedPath(Vector2 position, Vector2 nextPosition)
{ {
if (GridMoverTools.CrossesTileCenter(position, nextPosition, direction.x != 0, direction.y != 0)) if (CrossesTileCenter(position, nextPosition, direction))
{ {
// Find the next valid direction which isn't Vector2.zero // Find the next valid direction which isn't Vector2.zero
int nextValidDirectionIndex = predefinedPathIndex; int nextValidDirectionIndex = predefinedPathIndex;
@@ -254,13 +272,13 @@ namespace Marro.PacManUdon
{ {
nextValidDirectionIndex += 1; nextValidDirectionIndex += 1;
} }
if (!GridMoverTools.CheckCollisionInDirection(transform, nextPosition, predefinedPath[nextValidDirectionIndex])) if (!CheckCollisionInDirection(transform, nextPosition, predefinedPath[nextValidDirectionIndex]))
{ {
// If we're at a Vector2.zero, we skip applying the direction and only increment. // If we're at a Vector2.zero, we skip applying the direction and only increment.
if (nextValidDirectionIndex == predefinedPathIndex) if (nextValidDirectionIndex == predefinedPathIndex)
{ {
SetDirection(predefinedPath[nextValidDirectionIndex]); SetDirection(predefinedPath[nextValidDirectionIndex]);
nextPosition = GridMoverTools.PositionToGrid(nextPosition) + direction.normalized * 0.01f; nextPosition = PositionToGrid(nextPosition) + GetVector(direction) * 0.01f;
// Check if we've reached the end of the path, which includes making sure the path doesn't end on Vector2.zero // Check if we've reached the end of the path, which includes making sure the path doesn't end on Vector2.zero
do do
@@ -323,15 +341,15 @@ namespace Marro.PacManUdon
default: default:
return gridPosition; return gridPosition;
case PacManGhostType.Blinky: case PacManGhostType.Blinky:
return GridMoverTools.PositionToGrid(pacMan.transform.localPosition); return PositionToGrid(pacMan.transform.localPosition);
case PacManGhostType.Pinky: case PacManGhostType.Pinky:
return GridMoverTools.PositionToGrid(pacMan.transform.localPosition) + pacMan.GetDirection() * 4; return PositionToGrid(pacMan.transform.localPosition) + pacMan.GetVector(direction) * 4;
case PacManGhostType.Inky: case PacManGhostType.Inky:
return 2 * GridMoverTools.PositionToGrid(pacMan.transform.localPosition) + 4 * pacMan.GetDirection() - GridMoverTools.PositionToGrid(blinky.transform.localPosition); return 2 * PositionToGrid(pacMan.transform.localPosition) + 4 * pacMan.GetVector(direction) - PositionToGrid(blinky.transform.localPosition);
case PacManGhostType.Clyde: case PacManGhostType.Clyde:
if (Vector2.Distance(gridPosition, GridMoverTools.PositionToGrid(pacMan.transform.localPosition)) >= 8) if (Vector2.Distance(gridPosition, PositionToGrid(pacMan.transform.localPosition)) >= 8)
{ {
return GridMoverTools.PositionToGrid(pacMan.transform.localPosition); return PositionToGrid(pacMan.transform.localPosition);
} }
else else
{ {
@@ -386,7 +404,7 @@ namespace Marro.PacManUdon
case PacManGhostState.Exiting: case PacManGhostState.Exiting:
offGrid = false; offGrid = false;
SetState(PacManGhostState.Normal); SetState(PacManGhostState.Normal);
SetDirection(Vector2.left); SetDirection(Direction.Left);
break; break;
} }
} }
@@ -395,11 +413,11 @@ namespace Marro.PacManUdon
{ {
if (startHorizontal) if (startHorizontal)
{ {
SetDirection(GetOffGridDirectionToTarget(GetPosition(), newTarget, Vector2.right)); SetDirection(GetOffGridDirectionToTarget(GetPosition(), newTarget, Direction.Right));
} }
else else
{ {
SetDirection(GetOffGridDirectionToTarget(GetPosition(), newTarget, Vector2.down)); SetDirection(GetOffGridDirectionToTarget(GetPosition(), newTarget, Direction.Down));
} }
// Debug.Log($"{gameObject} SetOffGridTarget with position {GetPosition()}, newTarget {newTarget}, startHorizontal {startHorizontal} resulted in direction {direction}"); // Debug.Log($"{gameObject} SetOffGridTarget with position {GetPosition()}, newTarget {newTarget}, startHorizontal {startHorizontal} resulted in direction {direction}");
target = newTarget; target = newTarget;
@@ -413,69 +431,42 @@ namespace Marro.PacManUdon
return rngState; return rngState;
} }
Vector2[] GetAvailableDirections(Vector2 gridPosition, Vector2 discardDirection) private Direction[] cardinalDirections = new Direction[] { Direction.Up, Direction.Down, Direction.Left, Direction.Right };
Direction GetGridDirectionToTargetGreedy(bool[] blockedDirections, Vector2 gridPosition, Vector2 targetGridPosition)
{ {
Vector2[] directions; Direction bestDirection = Direction.Zero;
Vector2[] availableDirections; float bestDistance = float.MaxValue;
if (horizontalOnly && ghostState == PacManGhostState.Normal) for (int i = horizontalOnly ? 2 : 0; i < blockedDirections.Length; i++)
{ {
directions = new Vector2[] { new Vector2(1, 0), new Vector2(-1, 0) }; if (blockedDirections[i])
availableDirections = new Vector2[2];
}
else
{
directions = new Vector2[] { new Vector2(0, 1), new Vector2(1, 0), new Vector2(0, -1), new Vector2(-1, 0) };
availableDirections = new Vector2[4];
}
int availableDirectionsNum = 0;
for (int i = 0; i < directions.Length; i++)
{
if (directions[i].Equals(discardDirection) || GridMoverTools.CheckCollisionInDirection(transform, gridPosition, directions[i]))
{ {
continue; continue;
} }
availableDirections[availableDirectionsNum] = directions[i];
availableDirectionsNum++;
}
Vector2[] availableDirectionsTrimmed = new Vector2[availableDirectionsNum];
// Debug.Log($"{gameObject} Number of available directions: {availableDirectionsTrimmed.Length}");
Array.Copy(availableDirections, 0, availableDirectionsTrimmed, 0, availableDirectionsNum);
return availableDirectionsTrimmed;
}
Vector2 GetGridDirectionToTargetGreedy(Vector2[] availableDirections, Vector2 gridPosition, Vector2 targetGridPosition)
{
Vector2 bestDirection = Vector2.zero;
float bestDistance = float.MaxValue;
for (int i = 0; i < availableDirections.Length; i++)
{
Vector2 direction = availableDirections[i];
// Debug.Log("Evaluating direction " + direction); // Debug.Log("Evaluating direction " + direction);
float distance = Vector2.Distance(gridPosition + direction, targetGridPosition); var direction = cardinalDirections[i];
float distance = Vector2.Distance(gridPosition + directionVectors[(int)direction], targetGridPosition);
if (distance < bestDistance) if (distance < bestDistance)
{ {
bestDistance = distance; bestDistance = distance;
bestDirection = direction; bestDirection = direction;
} }
} }
// Debug.Log("Closest next tile is in direction " + bestDirection); Debug.Log($"{gameObject.name} Closest next tile is in direction {bestDirection}");
return bestDirection; return bestDirection;
} }
Vector2 GetOffGridDirectionToTarget(Vector2 position, Vector2 target, Vector2 direction) private Direction GetOffGridDirectionToTarget(Vector2 position, Vector2 target, Direction direction)
{ {
if ((direction.x != 0 && position.x != target.x) || position.y == target.y) if ((IsHorizontal(direction) && position.x != target.x) || position.y == target.y)
{ {
// Debug.Log($"{gameObject} getOffGridDirectionToTarget with position {position}, target {target} and direction {direction} gives movement on the X axis in direction {new Vector2(target.x-position.x, 0).normalized}"); // Debug.Log($"{gameObject} getOffGridDirectionToTarget with position {position}, target {target} and direction {direction} gives movement on the X axis in direction {new Vector2(target.x-position.x, 0).normalized}");
return new Vector2(target.x - position.x, 0).normalized; return HorizontalToDirection(target.x - position.x);
} }
else else
{ {
// Debug.Log($"{gameObject} getOffGridDirectionToTarget with position {position}, target {target} and direction {direction} gives movement on the Y axis in direction {new Vector2(0, target.y-position.y).normalized}"); // Debug.Log($"{gameObject} getOffGridDirectionToTarget with position {position}, target {target} and direction {direction} gives movement on the Y axis in direction {new Vector2(0, target.y-position.y).normalized}");
return new Vector2(0, target.y - position.y).normalized; return VerticalToDirection(target.y - position.y);
} }
} }
@@ -526,10 +517,11 @@ namespace Marro.PacManUdon
animator.SetFloat("DirX", 0); animator.SetFloat("DirX", 0);
animator.SetFloat("DirY", -1); animator.SetFloat("DirY", -1);
} }
else if (specialLook || !direction.Equals(Vector2.zero)) else if (specialLook || direction != Direction.Zero)
{ {
animator.SetFloat("DirX", direction.x); var vector = GetVector(direction);
animator.SetFloat("DirY", direction.y); animator.SetFloat("DirX", vector.x);
animator.SetFloat("DirY", vector.y);
} }
} }

View File

@@ -72,7 +72,7 @@ namespace Marro.PacManUdon
Vector2 idlePosition2 = ghostTargets[2 + ghostIndex * 3].localPosition; Vector2 idlePosition2 = ghostTargets[2 + ghostIndex * 3].localPosition;
Vector2 cornerPosition = ghostTargets[3 + ghostIndex * 3].localPosition; Vector2 cornerPosition = ghostTargets[3 + ghostIndex * 3].localPosition;
ghosts[ghostIndex].Initialize(pacMan, blinky, startTransform, homePosition, idlePosition1, idlePosition2, cornerPosition, ghostIndex); ghosts[ghostIndex].Initialize(pelletManager, pacMan, blinky, startTransform, homePosition, idlePosition1, idlePosition2, cornerPosition, ghostIndex);
} }
SubscribeToEvent(NetworkEventType.GhostUpdate); SubscribeToEvent(NetworkEventType.GhostUpdate);

View File

@@ -3,9 +3,42 @@ namespace Marro.PacManUdon
using System; using System;
using UnityEngine; using UnityEngine;
public enum Direction
{
Zero = 0, Up = 1, Down = 2, Left = 4, Right = 8, UpLeft = 5, UpRight = 9, DownLeft = 6, DownRight = 10
}
public enum DirectionAxis
{
Horizontal = 0,
Vertical = 1,
Both = 2
}
public abstract class GridMover : SyncedObject public abstract class GridMover : SyncedObject
{ {
protected Vector2 direction; protected Direction direction;
// Cannot be static, much to my annoyance
public readonly Vector2[] directionVectors =
{
Vector2.zero, // 0
Vector2.down, // 1
Vector2.up, // 2
Vector2.zero, // 3
Vector2.left, // 4
Vector2.down + Vector2.left, // 5
Vector2.up + Vector2.left, // 6
Vector2.left, // 7
Vector2.right, // 8
Vector2.down + Vector2.right, // 9
Vector2.up + Vector2.right, // 10
Vector2.right, // 11
Vector2.zero, // 12
Vector2.down, // 13
Vector2.up, // 14
Vector2.zero, // 15
};
public virtual Vector2 GetPosition() public virtual Vector2 GetPosition()
{ {
@@ -17,43 +50,193 @@ namespace Marro.PacManUdon
transform.localPosition = new Vector3(position.x, position.y, transform.localPosition.z); transform.localPosition = new Vector3(position.x, position.y, transform.localPosition.z);
} }
public virtual Vector2 GetDirection() public Vector2 GetVector(Direction direction)
{
return directionVectors[(int)direction];
}
public Direction GetDirection()
{ {
return direction; return direction;
} }
public void SetDirection(Vector2 direction) public void SetDirection(Direction direction)
{ {
this.direction = direction; this.direction = direction;
UpdateAnimator(); UpdateAnimator();
} }
public void SetDirection(Vector2 vector)
{
direction = VectorToDirection(vector);
UpdateAnimator();
}
protected static Direction VectorToDirection(Vector2 vector)
{
var directionId = 0;
if (vector.x < 0)
{
directionId = 4;
}
else if (vector.x > 0)
{
directionId = 8;
}
if (vector.y < 0)
{
directionId += 1;
}
else if (vector.y > 0)
{
directionId += 2;
}
return (Direction)directionId;
}
protected static Direction HorizontalToDirection(float horizontal)
{
if (horizontal < 0)
{
return Direction.Left;
}
if (horizontal > 0)
{
return Direction.Right;
}
return Direction.Zero;
}
protected static Direction VerticalToDirection(float vertical)
{
if (vertical < 0)
{
return Direction.Up;
}
if (vertical > 0)
{
return Direction.Down;
}
return Direction.Zero;
}
protected abstract void UpdateAnimator(); protected abstract void UpdateAnimator();
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType) public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{ {
data.Append(GetPosition(), ref index); data.Append(GetPosition(), ref index);
data.Append(GetDirection(), ref index); data.AppendAsByte((int)direction, ref index);
} }
public void PadSyncedData(byte[] data, ref int index, NetworkEventType eventType) public void PadSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{ {
index += 16; index += 9;
} }
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType) public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{ {
SetPosition(data.ReadVector2(ref index)); SetPosition(data.ReadVector2(ref index));
SetDirection(data.ReadVector2(ref index)); SetDirection((Direction)data.ReadByte(ref index));
return true; return true;
} }
public bool ConsumeSyncedData(byte[] data, ref int index, NetworkEventType eventType) public bool ConsumeSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{ {
index += 16; index += 9;
return true; return true;
} }
#region Utils
public static Direction GetInverseDirection(Direction direction)
{
switch (direction)
{
case Direction.Up:
return Direction.Down;
case Direction.Down:
return Direction.Up;
case Direction.Left:
return Direction.Right;
case Direction.Right:
return Direction.Left;
case Direction.UpLeft:
return Direction.DownRight;
case Direction.UpRight:
return Direction.DownLeft;
case Direction.DownLeft:
return Direction.UpRight;
case Direction.DownRight:
return Direction.UpLeft;
default:
return Direction.Zero;
}
}
public static bool IsVertical(Direction direction) => ((int)direction & 0b0011) != 0;
public static bool IsHorizontal(Direction direction) => ((int)direction & 0b1100) != 0;
public static Direction VerticalComponent(Direction direction) => (Direction)((int)direction & 0b0011);
public static Direction HorizontalComponent(Direction direction) => (Direction)((int)direction & 0b1100);
public static Vector2 GetNextPosition(Vector2 currentPosition, Vector2 directionVector, float speed, float deltaTime)
{
return currentPosition + deltaTime * speed * directionVector;
}
public static Vector2 PositionToGrid(Vector2 position)
{
return new Vector2((float)Math.Round(position.x), (float)Math.Round(position.y));
}
public static bool CrossesTileCenter(Vector2 currentPosition, Vector2 nextPosition, Direction direction)
{
bool result = false;
if (IsHorizontal(direction))
{
result = result || Math.Floor(currentPosition.x) != Math.Floor(nextPosition.x);
}
if (IsVertical(direction))
{
result = result || Math.Floor(currentPosition.y) != Math.Floor(nextPosition.y);
}
return result;
}
public static bool CrossesTileBorder(Vector2 currentPosition, Vector2 nextPosition, Direction direction)
{
bool result = false;
if (IsHorizontal(direction))
{
result = result || nextPosition.x != currentPosition.x
&& ((Math.Floor(currentPosition.x) != Math.Floor(nextPosition.x) && nextPosition.x % 1 != 0)
|| currentPosition.x % 1 == 0);
}
if (IsVertical(direction))
{
result = result || nextPosition.y != currentPosition.y
&& ((Math.Floor(currentPosition.y) != Math.Floor(nextPosition.y) && nextPosition.y % 1 != 0)
|| currentPosition.y % 1 == 0);
}
return result;
}
public static bool CheckCollisionInDirection(Transform transform, Vector2 position, Vector2 direction)
{
// Debug.Log("Collision check");
bool result = Physics.Linecast(transform.parent.TransformPoint(position), transform.parent.TransformPoint(position + direction.normalized), 1 << 22, QueryTriggerInteraction.Ignore);
// Debug.DrawLine(transform.parent.TransformPoint(position), transform.parent.TransformPoint(position + direction.normalized), Color.red, 1);
// Debug.Log($"{gameObject} Collision; Position {position} became {transform.parent.TransformPoint(position)}, direction {direction.normalized} became {transform.parent.TransformDirection(direction.normalized)}");
// Debug.Log("collision check for " + position + " in direction " + direction + " returned " + result);
return result;
}
#endregion
} }
} }

View File

@@ -1,64 +0,0 @@
namespace Marro.PacManUdon
{
using System;
using UnityEngine;
public static class GridMoverTools
{
public static Vector2 GetNextPosition(Vector2 currentPosition, Vector2 direction, float speed, float deltaTime)
{
return currentPosition + direction * speed * deltaTime;
}
public static Vector2 PositionToGrid(Vector2 position)
{
return new Vector2((float)Math.Round(position.x), (float)Math.Round(position.y));
}
public static bool CrossesTileCenter(Vector2 currentPosition, Vector2 nextPosition, bool horizontal, bool vertical)
{
bool result = false;
if (horizontal)
{
result = result || Math.Floor(currentPosition.x) != Math.Floor(nextPosition.x);
}
if (vertical)
{
result = result || Math.Floor(currentPosition.y) != Math.Floor(nextPosition.y);
}
// Debug.Log($"CrossesTileCenter at currentPosition {currentPosition} with nextPosition {nextPosition}, horizontal {horizontal} and vertical {vertical} gives {result}");
return result;
}
public static bool CrossesTileBorder(Vector2 currentPosition, Vector2 nextPosition, bool horizontal, bool vertical)
{
bool result = false;
if (horizontal)
{
result = result || nextPosition.x != currentPosition.x
&& ((Math.Floor(currentPosition.x) != Math.Floor(nextPosition.x) && nextPosition.x % 1 != 0)
|| currentPosition.x % 1 == 0);
}
if (vertical)
{
result = result || nextPosition.y != currentPosition.y
&& ((Math.Floor(currentPosition.y) != Math.Floor(nextPosition.y) && nextPosition.y % 1 != 0)
|| currentPosition.y % 1 == 0);
}
return result;
}
public static bool CheckCollisionInDirection(Transform transform, Vector2 position, Vector2 direction)
{
// Debug.Log("Collision check");
bool result = Physics.Linecast(transform.parent.TransformPoint(position), transform.parent.TransformPoint(position + direction.normalized), 1 << 22, QueryTriggerInteraction.Ignore);
// Debug.DrawLine(transform.parent.TransformPoint(position), transform.parent.TransformPoint(position + direction.normalized), Color.red, 1);
// Debug.Log($"{gameObject} Collision; Position {position} became {transform.parent.TransformPoint(position)}, direction {direction.normalized} became {transform.parent.TransformDirection(direction.normalized)}");
// Debug.Log("collision check for " + position + " in direction " + direction + " returned " + result);
return result;
}
}
}

View File

@@ -181,7 +181,7 @@ MonoBehaviour:
Data: 11|System.RuntimeType, mscorlib Data: 11|System.RuntimeType, mscorlib
- Name: - Name:
Entry: 1 Entry: 1
Data: System.Single, mscorlib Data: System.Int32, mscorlib
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
@@ -237,17 +237,11 @@ MonoBehaviour:
Entry: 1 Entry: 1
Data: maxEventSendTries Data: maxEventSendTries
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 9
Data: 15|System.RuntimeType, mscorlib Data: 11
- Name:
Entry: 1
Data: System.Int32, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 15 Data: 11
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -262,13 +256,13 @@ MonoBehaviour:
Data: true Data: true
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 16|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 15|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 1 Data: 1
- Name: - Name:
Entry: 7 Entry: 7
Data: 17|UnityEngine.SerializeField, UnityEngine.CoreModule Data: 16|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
@@ -292,7 +286,7 @@ MonoBehaviour:
Data: pingDelay Data: pingDelay
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 18|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 17|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: pingDelay Data: pingDelay
@@ -316,13 +310,13 @@ MonoBehaviour:
Data: true Data: true
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 19|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 18|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 1 Data: 1
- Name: - Name:
Entry: 7 Entry: 7
Data: 20|UnityEngine.SerializeField, UnityEngine.CoreModule Data: 19|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
@@ -343,19 +337,25 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: updateDelta Data: tickDelta
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 21|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 20|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: updateDelta Data: tickDelta
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 7
Data: 11 Data: 21|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Single, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 11 Data: 21
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -625,19 +625,19 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: offsetTime Data: startTime
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 38|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 38|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: offsetTime Data: startTime
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 11 Data: 21
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 11 Data: 21
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -673,13 +673,13 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: internalTime Data: targetTicks
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 40|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 40|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: internalTime Data: targetTicks
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 11 Data: 11
@@ -817,13 +817,13 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: nextUpdateTime Data: nextEventTime
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 46|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 46|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: nextUpdateTime Data: nextEventTime
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 11 Data: 11
@@ -865,13 +865,13 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: nextEventTime Data: retriesWithoutSuccess
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 48|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 48|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: nextEventTime Data: retriesWithoutSuccess
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 11 Data: 11
@@ -913,19 +913,19 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: retriesWithoutSuccess Data: hasFullSyncReady
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 50|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 50|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: retriesWithoutSuccess Data: hasFullSyncReady
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 15 Data: 25
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 15 Data: 25
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -961,13 +961,13 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: hasFullSyncReady Data: serializationRequested
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 52|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 52|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: hasFullSyncReady Data: serializationRequested
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 25 Data: 25
@@ -1009,19 +1009,25 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: serializationRequested Data: eventsToSend
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 54|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 54|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: serializationRequested Data: eventsToSend
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 7
Data: 25 Data: 55|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.NetworkEventType[], Assembly-CSharp
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 25 Data: 32
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1036,7 +1042,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 55|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 56|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0
@@ -1057,25 +1063,19 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: eventsToSend Data: eventsToSendIndex
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 56|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 57|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: eventsToSend Data: eventsToSendIndex
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 9
Data: 57|System.RuntimeType, mscorlib Data: 11
- Name:
Entry: 1
Data: Marro.PacManUdon.NetworkEventType[], Assembly-CSharp
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 32 Data: 11
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1111,19 +1111,25 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: eventsToSendIndex Data: eventsQueue
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 59|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 59|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: eventsToSendIndex Data: eventsQueue
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 7
Data: 15 Data: 60|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Byte[][], mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 15 Data: 29
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1138,7 +1144,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 60|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 61|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0
@@ -1159,25 +1165,19 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: eventsQueue Data: eventsQueueIndex
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 61|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 62|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: eventsQueue Data: eventsQueueIndex
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 9
Data: 62|System.RuntimeType, mscorlib Data: 11
- Name:
Entry: 1
Data: System.Byte[][], mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 29 Data: 11
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1213,19 +1213,19 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: eventsQueueIndex Data: eventsQueueIndexAtLastTransmission
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 64|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 64|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: eventsQueueIndex Data: eventsQueueIndexAtLastTransmission
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 15 Data: 11
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 15 Data: 11
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1261,19 +1261,19 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: eventsQueueIndexAtLastTransmission Data: eventTransmissionHistory
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 66|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 66|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: eventsQueueIndexAtLastTransmission Data: eventTransmissionHistory
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 15 Data: 32
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 15 Data: 32
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1309,19 +1309,19 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: eventTransmissionHistory Data: eventTransmissionHistoryIndex
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 68|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 68|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: eventTransmissionHistory Data: eventTransmissionHistoryIndex
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 32 Data: 11
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 32 Data: 11
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1357,19 +1357,19 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: eventTransmissionHistoryIndex Data: lastEventTransmissionTime
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 70|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 70|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: eventTransmissionHistoryIndex Data: lastEventTransmissionTime
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 15 Data: 11
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 15 Data: 11
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1405,64 +1405,16 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: lastEventTransmissionTime Data: lastEventId
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 72|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 72|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: lastEventTransmissionTime
- Name: <UserType>k__BackingField
Entry: 9
Data: 11
- Name: <SystemType>k__BackingField
Entry: 9
Data: 11
- 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: 73|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: lastEventId
- Name: $v
Entry: 7
Data: 74|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: lastEventId Data: lastEventId
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 7
Data: 75|System.RuntimeType, mscorlib Data: 73|System.RuntimeType, mscorlib
- Name: - Name:
Entry: 1 Entry: 1
Data: System.Byte, mscorlib Data: System.Byte, mscorlib
@@ -1471,7 +1423,7 @@ MonoBehaviour:
Data: Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 75 Data: 73
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1486,7 +1438,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 76|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 74|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0
@@ -1510,13 +1462,13 @@ MonoBehaviour:
Data: networkedData Data: networkedData
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 77|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 75|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: networkedData Data: networkedData
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 7
Data: 78|System.RuntimeType, mscorlib Data: 76|System.RuntimeType, mscorlib
- Name: - Name:
Entry: 1 Entry: 1
Data: System.Byte[], mscorlib Data: System.Byte[], mscorlib
@@ -1525,7 +1477,7 @@ MonoBehaviour:
Data: Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 78 Data: 76
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1540,13 +1492,13 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 79|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 77|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 1 Data: 1
- Name: - Name:
Entry: 7 Entry: 7
Data: 80|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime Data: 78|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
@@ -1570,7 +1522,7 @@ MonoBehaviour:
Data: ready Data: ready
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 81|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 79|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: ready Data: ready
@@ -1592,6 +1544,54 @@ MonoBehaviour:
- Name: <IsSerialized>k__BackingField - Name: <IsSerialized>k__BackingField
Entry: 5 Entry: 5
Data: false Data: false
- Name: _fieldAttributes
Entry: 7
Data: 80|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: synced
- Name: $v
Entry: 7
Data: 81|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: synced
- Name: <UserType>k__BackingField
Entry: 9
Data: 25
- Name: <SystemType>k__BackingField
Entry: 9
Data: 25
- 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 - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 82|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 82|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
@@ -1615,19 +1615,19 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: synced Data: <SyncedTimeTicks>k__BackingField
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 83|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 83|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: synced Data: <SyncedTimeTicks>k__BackingField
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 25 Data: 11
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 25 Data: 11
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1672,10 +1672,10 @@ MonoBehaviour:
Data: <SyncedTime>k__BackingField Data: <SyncedTime>k__BackingField
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 11 Data: 21
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 11 Data: 21
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1711,19 +1711,19 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: <SyncedDeltaTime>k__BackingField Data: <IsEventUpdate>k__BackingField
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 87|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 87|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: <SyncedDeltaTime>k__BackingField Data: <IsEventUpdate>k__BackingField
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 11 Data: 25
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 11 Data: 25
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1759,13 +1759,13 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: <IsEventUpdate>k__BackingField Data: isOwner
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 89|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 89|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: <IsEventUpdate>k__BackingField Data: isOwner
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 25 Data: 25
@@ -1807,19 +1807,25 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: isOwner Data: debugOutput
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 91|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 91|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: isOwner Data: debugOutput
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 7
Data: 25 Data: 92|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: TMPro.TMP_InputField, Unity.TextMeshPro
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 25 Data: 92
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1831,13 +1837,19 @@ MonoBehaviour:
Data: Data:
- Name: <IsSerialized>k__BackingField - Name: <IsSerialized>k__BackingField
Entry: 5 Entry: 5
Data: false Data: true
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 92|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 93|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 1
- Name:
Entry: 7
Data: 94|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name: - Name:
Entry: 13 Entry: 13
Data: Data:
@@ -1858,13 +1870,13 @@ MonoBehaviour:
Data: DebugImageToIndicateOwner Data: DebugImageToIndicateOwner
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 93|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 95|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: DebugImageToIndicateOwner Data: DebugImageToIndicateOwner
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 7
Data: 94|System.RuntimeType, mscorlib Data: 96|System.RuntimeType, mscorlib
- Name: - Name:
Entry: 1 Entry: 1
Data: UnityEngine.Animator, UnityEngine.AnimationModule Data: UnityEngine.Animator, UnityEngine.AnimationModule
@@ -1873,7 +1885,7 @@ MonoBehaviour:
Data: Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 94 Data: 96
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1888,13 +1900,13 @@ MonoBehaviour:
Data: true Data: true
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 95|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 97|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 1 Data: 1
- Name: - Name:
Entry: 7 Entry: 7
Data: 96|UnityEngine.SerializeField, UnityEngine.CoreModule Data: 98|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
@@ -1918,16 +1930,16 @@ MonoBehaviour:
Data: DebugImageToIndicateSynced Data: DebugImageToIndicateSynced
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 97|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 99|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: DebugImageToIndicateSynced Data: DebugImageToIndicateSynced
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 94 Data: 96
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 94 Data: 96
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1942,68 +1954,69 @@ MonoBehaviour:
Data: true Data: true
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 98|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 100|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data: 99|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- 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: DebugImageToIndicateReady
- Name: $v
Entry: 7
Data: 100|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: DebugImageToIndicateReady
- Name: <UserType>k__BackingField
Entry: 9
Data: 94
- Name: <SystemType>k__BackingField
Entry: 9
Data: 94
- 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: true
- Name: _fieldAttributes
Entry: 7
Data: 101|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 1 Data: 1
- Name: - Name:
Entry: 7 Entry: 7
Data: 102|UnityEngine.SerializeField, UnityEngine.CoreModule Data: 101|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- 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: DebugImageToIndicateReady
- Name: $v
Entry: 7
Data: 102|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: DebugImageToIndicateReady
- Name: <UserType>k__BackingField
Entry: 9
Data: 96
- Name: <SystemType>k__BackingField
Entry: 9
Data: 96
- 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: true
- Name: _fieldAttributes
Entry: 7
Data: 103|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data: 104|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
@@ -2027,13 +2040,13 @@ MonoBehaviour:
Data: tester Data: tester
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 103|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 105|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: tester Data: tester
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 7
Data: 104|System.RuntimeType, mscorlib Data: 106|System.RuntimeType, mscorlib
- Name: - Name:
Entry: 1 Entry: 1
Data: NetworkManagerTester, Assembly-CSharp Data: NetworkManagerTester, Assembly-CSharp
@@ -2057,7 +2070,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 105|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], Data: 107|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib mscorlib
- Name: - Name:
Entry: 12 Entry: 12

View File

@@ -1,4 +1,6 @@
using System; using Newtonsoft.Json.Linq;
using System;
using System.Numerics;
using System.Text; using System.Text;
using TMPro; using TMPro;
using UdonSharp; using UdonSharp;
@@ -52,9 +54,9 @@ namespace Marro.PacManUdon
/// </summary> /// </summary>
[SerializeField] private GameObject root; [SerializeField] private GameObject root;
/// <summary> /// <summary>
/// The delay at which the receiving side replays events. /// The delay in ticks at which the receiving side replays events.
/// </summary> /// </summary>
[SerializeField] private float delay = 1f; [SerializeField] private int delay = 50;
/// <summary> /// <summary>
/// The maximum amount of times a message is sent. /// The maximum amount of times a message is sent.
/// </summary> /// </summary>
@@ -62,11 +64,11 @@ namespace Marro.PacManUdon
/// <summary> /// <summary>
/// How long to wait since last message to send next ping. /// How long to wait since last message to send next ping.
/// </summary> /// </summary>
[SerializeField] private float pingDelay = 0.3f; [SerializeField] private int pingDelay = 15;
/// <summary> /// <summary>
/// The time delta at which updates occur. /// The time delta at which updates occur.
/// </summary> /// </summary>
[SerializeField] private float updateDelta = 0.0166666667f; [SerializeField] private float tickDelta = 0.0166666667f;
#endregion #endregion
#region Constants #region Constants
@@ -123,13 +125,14 @@ namespace Marro.PacManUdon
private SyncedObject[] syncedUpdateSubscribers; private SyncedObject[] syncedUpdateSubscribers;
/// <summary> /// <summary>
/// Offset from system time to network time, including delay. /// The <see cref="Time.fixedTime"/> that corresponds to tick 0.
/// </summary> /// </summary>
private float offsetTime; private float startTime;
/// <summary> /// <summary>
/// Time since last full sync, captured when this FixedUpdate started, with network delay applied. /// Time in ticks since start of game.
/// </summary> /// </summary>
private float internalTime; private int targetTicks;
/// <summary> /// <summary>
/// True if time is paused /// True if time is paused
@@ -142,13 +145,9 @@ namespace Marro.PacManUdon
private bool stepNext; private bool stepNext;
/// <summary> /// <summary>
/// Time at which the next update should occur. /// Time at which next received event occured, in ticks.
/// </summary> /// </summary>
private float nextUpdateTime; private int nextEventTime;
/// <summary>
/// Time at which next received event occured.
/// </summary>
private float nextEventTime;
/// <summary> /// <summary>
/// Amounot of retries in a row without a successful sync. /// Amounot of retries in a row without a successful sync.
@@ -196,9 +195,9 @@ namespace Marro.PacManUdon
/// </summary> /// </summary>
private int eventTransmissionHistoryIndex; private int eventTransmissionHistoryIndex;
/// <summary> /// <summary>
/// Time of last event transmission. /// Time of last event transmission, in ticks.
/// </summary> /// </summary>
private float lastEventTransmissionTime; private int lastEventTransmissionTime;
/// <summary> /// <summary>
@@ -251,14 +250,18 @@ namespace Marro.PacManUdon
private bool synced = false; private bool synced = false;
/// <summary> /// <summary>
/// The time since last full sync which is currently being simulated. /// The time since start of game, in ticks.
/// </summary>
public int SyncedTimeTicks { get; private set; }
/// <summary>
/// The time since start of game which is currently being simulated.
/// </summary> /// </summary>
public float SyncedTime { get; private set; } public float SyncedTime { get; private set; }
/// <summary> /// <summary>
/// Time since the last simulation, in seconds. /// Time since the last simulation, in seconds.
/// </summary> /// </summary>
public float SyncedDeltaTime { get; private set; } public float SyncedDeltaTime => tickDelta;
/// <summary> /// <summary>
/// Is the current simulation to prepare for applying a network event? /// Is the current simulation to prepare for applying a network event?
@@ -355,11 +358,10 @@ namespace Marro.PacManUdon
retriesWithoutSuccess = 0; retriesWithoutSuccess = 0;
hasFullSyncReady = false; hasFullSyncReady = false;
offsetTime = Time.fixedTime; targetTicks = 0;
internalTime = 0; startTime = Time.fixedTime;
SyncedTime = 0; SyncedTime = 0;
SyncedDeltaTime = Time.fixedDeltaTime; SyncedTimeTicks = 0;
nextUpdateTime = SyncedTime;
Ready = true; Ready = true;
@@ -373,11 +375,16 @@ namespace Marro.PacManUdon
RequestEvent(NetworkEventType.FullSync); RequestEvent(NetworkEventType.FullSync);
} }
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Initialized, time offset: {offsetTime}"); Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Initialized");
} }
public void Update() public void Update()
{ {
if (debugOutput != null)
{
WriteDebugOutput(debugOutput);
}
if (!initialized) if (!initialized)
{ {
return; return;
@@ -387,35 +394,12 @@ namespace Marro.PacManUdon
UpdateInternalTime(); UpdateInternalTime();
// Forwards simulated time by updateDelta until we're caught up // Forwards simulated time by updateDelta until we're caught up
while (nextUpdateTime <= internalTime) while (SyncedTimeTicks <= targetTicks)
{ {
PerformFixedSyncedUpdate(); PerformFixedSyncedUpdate();
} }
} }
private void UpdateInternalTime()
{
var delta = Time.fixedTime - offsetTime - internalTime;
if (!paused)
{
// Continue time like normal
internalTime += delta;
}
else if (paused && !stepNext)
{
// Since we're paused, increase our offset from Unity's time
offsetTime += delta;
}
else
{
// Step forward by exactly updateDelta, apply the remainder to our offset
offsetTime += delta - updateDelta;
internalTime += updateDelta;
stepNext = false;
}
}
private void PerformFixedSyncedUpdate() private void PerformFixedSyncedUpdate()
{ {
if (Ready) if (Ready)
@@ -431,9 +415,8 @@ namespace Marro.PacManUdon
} }
} }
ProgressSyncedTime(nextUpdateTime); ProgressSyncedTime();
CallSyncedUpdate(); CallSyncedUpdate();
nextUpdateTime = SyncedTime + updateDelta;
} }
private void CallSyncedUpdate() private void CallSyncedUpdate()
@@ -555,7 +538,7 @@ namespace Marro.PacManUdon
return; return;
} }
var timestamp = SyncedTime; var timestamp = SyncedTimeTicks;
var eventId = GetNextEventId(lastEventId); var eventId = GetNextEventId(lastEventId);
@@ -593,7 +576,7 @@ namespace Marro.PacManUdon
retriesWithoutSuccess = 0; // We had success! retriesWithoutSuccess = 0; // We had success!
} }
private static void InitializeEvent(NetworkEventType eventType, float timestamp, byte eventId, out byte[] data, out int index) private static void InitializeEvent(NetworkEventType eventType, int timestamp, byte eventId, out byte[] data, out int index)
{ {
data = new byte[MaxEventSize]; data = new byte[MaxEventSize];
@@ -640,7 +623,7 @@ namespace Marro.PacManUdon
private void ProgressPingTime() private void ProgressPingTime()
{ {
if (eventsQueueIndex > 0 && !serializationRequested if (eventsQueueIndex > 0 && !serializationRequested
&& internalTime - lastEventTransmissionTime >= pingDelay) && targetTicks - lastEventTransmissionTime >= pingDelay)
{ {
RequestSerializationForEvents(); RequestSerializationForEvents();
} }
@@ -695,7 +678,7 @@ namespace Marro.PacManUdon
// If there was a full sync in the queue, it has now been transmitted at least once // If there was a full sync in the queue, it has now been transmitted at least once
hasFullSyncReady = false; hasFullSyncReady = false;
lastEventTransmissionTime = internalTime; lastEventTransmissionTime = targetTicks;
} }
#endregion #endregion
@@ -811,7 +794,7 @@ namespace Marro.PacManUdon
QueueEventInBuffer(@event); QueueEventInBuffer(@event);
// Set this event to play after the default delay // Set this event to play after the default delay
nextEventTime = internalTime + delay; nextEventTime = targetTicks + delay;
hasFullSyncReady = true; hasFullSyncReady = true;
@@ -822,7 +805,7 @@ namespace Marro.PacManUdon
{ {
IsEventUpdate = true; IsEventUpdate = true;
while (eventsQueueIndex > 0 && nextEventTime <= SyncedTime) while (eventsQueueIndex > 0 && nextEventTime <= SyncedTimeTicks)
{ {
var success = ApplyEvent(eventsQueue[0]); var success = ApplyEvent(eventsQueue[0]);
@@ -847,11 +830,16 @@ namespace Marro.PacManUdon
{ {
SyncToTimestamp(timestamp); SyncToTimestamp(timestamp);
} }
else if (timestamp < SyncedTimeTicks)
{
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Next received event is in the past! " +
$"{nameof(nextEventTime)}: {nextEventTime} < {nameof(SyncedTimeTicks)}: {SyncedTimeTicks}.");
HandleError(true);
return false;
}
var index = (int)HeaderLength; // Skip header var index = (int)HeaderLength; // Skip header
ProgressSyncedTime(timestamp);
var subscribers = GetEventSubscribers(eventType); var subscribers = GetEventSubscribers(eventType);
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) ApplyEvent with dt {SyncedDeltaTime}"); Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) ApplyEvent with dt {SyncedDeltaTime}");
@@ -890,7 +878,7 @@ namespace Marro.PacManUdon
Synced = true; Synced = true;
} }
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Performed incoming eventof type {eventType}! Total {index} bytes."); Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Performed incoming event of type {eventType}! Total {index} bytes.");
retriesWithoutSuccess = 0; // We had success! retriesWithoutSuccess = 0; // We had success!
@@ -951,30 +939,38 @@ namespace Marro.PacManUdon
#endregion #endregion
#region Time #region Time
private void ProgressSyncedTime(float newTime) private void UpdateInternalTime()
{ {
//Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) updating SyncedTime from {SyncedTime} to {newTime}"); if (paused && !stepNext)
SyncedDeltaTime = newTime - SyncedTime;
if (SyncedDeltaTime < 0)
{ {
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Negative Dt: {SyncedDeltaTime}! Going from {SyncedTime} to {newTime}, IsEventUpdate: {IsEventUpdate}"); return;
} }
SyncedTime = newTime; if (paused && stepNext)
{
targetTicks++;
stepNext = false;
return;
}
targetTicks = (int)((Time.fixedTime - startTime) / tickDelta);
} }
private void SyncToTimestamp(float timestamp) private void ProgressSyncedTime()
{ {
var oldOffset = offsetTime; SyncedTimeTicks++;
offsetTime = Time.fixedTime - timestamp; SyncedTime = SyncedTimeTicks * tickDelta;
}
var delta = offsetTime - oldOffset; private void SyncToTimestamp(int timestamp)
internalTime -= delta; {
SyncedTime -= delta; startTime = Time.fixedTime - timestamp * tickDelta;
nextEventTime -= delta; targetTicks = timestamp;
SyncedTimeTicks = timestamp;
SyncedTime = SyncedTimeTicks * tickDelta;
nextEventTime = timestamp;
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Synced to timestamp {timestamp}, current time is {Time.fixedTime}, offsetTime is now {offsetTime}, internalTime is now {internalTime}, SyncedTime is now {SyncedTime}, nextEventTime is now {nextEventTime}"); Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Synced to timestamp {timestamp}, internalTime is now {targetTicks}, SyncedTime is now {SyncedTime}, nextEventTime is now {nextEventTime}");
} }
private void UpdateNextEventTime() private void UpdateNextEventTime()
@@ -993,9 +989,9 @@ namespace Marro.PacManUdon
return; return;
} }
if (nextEventTime < SyncedTime) if (nextEventTime < SyncedTimeTicks)
{ {
Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) New event timestamp is earlier than our current synced time by {SyncedTime - nextEventTime} seconds! nextEventTime: {nextEventTime} SyncedTime: {SyncedTime}, internalTime: {internalTime}"); Debug.LogWarning($"({nameof(PacManUdon)} {nameof(NetworkManager)}) New event timestamp is earlier than our current synced time by {SyncedTime - nextEventTime} seconds! nextEventTime: {nextEventTime} SyncedTime: {SyncedTime}, internalTime: {targetTicks}");
HandleError(true); HandleError(true);
return; return;
} }
@@ -1026,8 +1022,8 @@ namespace Marro.PacManUdon
private static NetworkEventType GetEventTypeFromHeader(byte[] @event, int eventIndex = 0) => private static NetworkEventType GetEventTypeFromHeader(byte[] @event, int eventIndex = 0) =>
(NetworkEventType)@event[eventIndex + HeaderEventTypeIndex]; (NetworkEventType)@event[eventIndex + HeaderEventTypeIndex];
private static float GetTimestampFromHeader(byte[] @event, int eventIndex = 0) => private static int GetTimestampFromHeader(byte[] @event, int eventIndex = 0) =>
BitConverter.ToSingle(@event, eventIndex + HeaderTimestampIndex); BitConverter.ToInt32(@event, eventIndex + HeaderTimestampIndex);
private static byte GetEventIdFromHeader(byte[] @event, int eventIndex = 0) => private static byte GetEventIdFromHeader(byte[] @event, int eventIndex = 0) =>
@event[eventIndex + HeaderEventIdIndex]; @event[eventIndex + HeaderEventIdIndex];
@@ -1107,6 +1103,11 @@ namespace Marro.PacManUdon
Array.Copy(data, start, result, 0, length); Array.Copy(data, start, result, 0, length);
return result; return result;
} }
private static float RoundDown(float value, float precision)
{
return (float)(Math.Floor(value / precision) * precision);
}
#endregion #endregion
#region SyncedData #region SyncedData
@@ -1137,20 +1138,20 @@ namespace Marro.PacManUdon
#region Debug #region Debug
public void SimulateSyncToTimestamp(float timestamp) public void SimulateSyncToTimestamp(float timestamp)
{ {
SyncToTimestamp(timestamp); //SyncToTimestamp(timestamp);
} }
public void WriteDebugOutput(TMP_InputField debugOutput) public void WriteDebugOutput(TMP_InputField debugOutput)
{ {
debugOutput.text += $"{nameof(NetworkManager)}:\n" + debugOutput.text = $"{nameof(NetworkManager)}:\n" +
$"IsOwner: {IsOwner}\n" + $"IsOwner: {IsOwner}\n" +
$"Ready: {Ready}\n" + $"Ready: {Ready}\n" +
$"Synced: {Synced}\n" + $"Synced: {Synced}\n" +
$"hasFullSyncReady: {hasFullSyncReady}\n" + $"hasFullSyncReady: {hasFullSyncReady}\n" +
$"lastEventId: {lastEventId}" + $"lastEventId: {lastEventId}\n" +
$"Time.fixedTime: {Time.fixedTime}\n" + $"Time.fixedTime: {Time.fixedTime}\n" +
$"offsetTime: {offsetTime}\n" + $"startTime: {startTime}\n" +
$"internalTime: {internalTime}\n" + $"targetTicks: {targetTicks}\n" +
$"SyncedTime: {SyncedTime}\n" + $"SyncedTime: {SyncedTime}\n" +
$"Dt: {SyncedDeltaTime}\n" + $"Dt: {SyncedDeltaTime}\n" +
$"BufferIndex: {eventsQueueIndex}\n" + $"BufferIndex: {eventsQueueIndex}\n" +
@@ -1158,6 +1159,11 @@ namespace Marro.PacManUdon
$"\n"; $"\n";
} }
/// <summary>
/// Text field to display debug info in.
/// </summary>
[SerializeField] private TMP_InputField debugOutput;
/// <summary> /// <summary>
/// An animator which visualizes whether the current perspective is the owner. /// An animator which visualizes whether the current perspective is the owner.
/// </summary> /// </summary>

File diff suppressed because it is too large Load Diff

View File

@@ -7,8 +7,9 @@ namespace Marro.PacManUdon
[RequireComponent(typeof(Renderer))] [RequireComponent(typeof(Renderer))]
public class PacMan : GridMover public class PacMan : GridMover
{ {
private GameManager gameController; private GameManager gameManager;
private PlayerInput input; private PlayerInput input;
private PelletManager pelletManager;
private float defaultSpeed; private float defaultSpeed;
private float powerPelletSpeed; private float powerPelletSpeed;
private float speed; private float speed;
@@ -40,9 +41,10 @@ namespace Marro.PacManUdon
#endregion #endregion
public void Initialize(PlayerInput input, Transform startTransform, GameManager gameController) public void Initialize(PlayerInput input, Transform startTransform, GameManager gameManager, PelletManager pelletManager)
{ {
this.gameController = gameController; this.gameManager = gameManager;
this.pelletManager = pelletManager;
this.input = input; this.input = input;
animator = GetComponent<Animator>(); animator = GetComponent<Animator>();
renderer = GetComponent<Renderer>(); renderer = GetComponent<Renderer>();
@@ -57,7 +59,7 @@ namespace Marro.PacManUdon
public void Reset() public void Reset()
{ {
transform.SetLocalPositionAndRotation(startPosition, startRotation); transform.SetLocalPositionAndRotation(startPosition, startRotation);
direction = Vector2.left; direction = Direction.Left;
targetDirection = Vector2.left; targetDirection = Vector2.left;
speed = defaultSpeed; speed = defaultSpeed;
kinematic = false; kinematic = false;
@@ -104,7 +106,7 @@ namespace Marro.PacManUdon
} }
Vector2 position = GetPosition(); Vector2 position = GetPosition();
Vector2 nextPosition = GridMoverTools.GetNextPosition(position, direction, speed, networkManager.SyncedDeltaTime); // The position pacman will move to, assuming it doens't get changed Vector2 nextPosition = GetNextPosition(position, directionVectors[(int)direction], speed, networkManager.SyncedDeltaTime); // The position pacman will move to, assuming it doens't get changed
if (!kinematic) if (!kinematic)
{ {
@@ -123,34 +125,35 @@ namespace Marro.PacManUdon
private Vector2 ProcessNextPosition(Vector2 position, Vector2 nextPosition) private Vector2 ProcessNextPosition(Vector2 position, Vector2 nextPosition)
{ {
if (GridMoverTools.CrossesTileCenter(position, nextPosition, direction.x != 0, false) // If pacman is moving horizontally, check if he may cross the center of a tile in that axis if (CrossesTileCenter(position, nextPosition, Direction.Left) // If pacman is moving horizontally, check if he may cross the center of a tile in that axis
&& (targetDirection.x == 0 || GridMoverTools.CheckCollisionInDirection(transform, nextPosition, new Vector2(direction.x, 0)))) && (targetDirection.x == 0 || pelletManager.IsWallUpcoming(nextPosition, directionVectors[(int)HorizontalComponent(direction)])))
{ // If the target direction is in the other axis or if we're about to run into a wall { // If the target direction is in the other axis or if we're about to run into a wall
nextPosition.x = GridMoverTools.PositionToGrid(nextPosition).x; // Snap pacman to the center of his current tile in this axis nextPosition.x = PositionToGrid(nextPosition).x; // Snap pacman to the center of his current tile in this axis
SetDirection(new Vector2(0, direction.y)); SetDirection(VerticalComponent(direction));
// Debug.Log($"{gameObject} crossed X tile center from {currentPosition}, nextPosition is now {nextPosition} and direction is now {direction}"); Debug.Log($"{gameObject} crossed X tile center from {position}, nextPosition is now {nextPosition} and direction is now {direction}");
} }
if (GridMoverTools.CrossesTileCenter(position, nextPosition, false, direction.y != 0) // See comments above but now vertical if (CrossesTileCenter(position, nextPosition, Direction.Down) // See comments above but now vertical
&& (targetDirection.y == 0 || GridMoverTools.CheckCollisionInDirection(transform, nextPosition, new Vector2(0, direction.y)))) && (targetDirection.y == 0 || pelletManager.IsWallUpcoming(nextPosition, directionVectors[(int)VerticalComponent(direction)])))
{ {
nextPosition.y = GridMoverTools.PositionToGrid(nextPosition).y; nextPosition.y = PositionToGrid(nextPosition).y;
SetDirection(new Vector2(direction.x, 0)); SetDirection(HorizontalComponent(direction));
// Debug.Log($"{gameObject} crossed Y tile center from {currentPosition} with targetDirection {targetDirection}, nextPosition is now {nextPosition} and direction is now {direction}"); Debug.Log($"{gameObject} crossed Y tile center from {position} with targetDirection {targetDirection}, nextPosition is now {nextPosition} and direction is now {direction}");
} }
Vector2 inputDirection = input.GetDirection(); Vector2 inputDirection = input.GetDirection();
if (!inputDirection.Equals(Vector2.zero) && !inputDirection.Equals(targetDirection) // Ignore neutral input or input in our current direction if (!inputDirection.Equals(Vector2.zero) && !inputDirection.Equals(targetDirection) // Ignore neutral input or input in our current direction
&& (inputDirection.x == 0 || (Math.Round(nextPosition.y, 5) - 0.5) % 1 != 0) && (inputDirection.y == 0 || (Math.Round(nextPosition.x, 5) - 0.5) % 1 != 0) // Target grid position near the edge of a tile may not be correct, ignore inputs near the border && (inputDirection.x == 0 || (Math.Round(nextPosition.y, 5) - 0.5) % 1 != 0) // Target grid position near the edge of a tile may not be correct, ignore inputs near the border
&& !GridMoverTools.CheckCollisionInDirection(transform, nextPosition, inputDirection)) && (inputDirection.y == 0 || (Math.Round(nextPosition.x, 5) - 0.5) % 1 != 0)
&& !CheckCollisionInDirection(transform, nextPosition, inputDirection))
{ // Check if the requested direction does not have a wall { // Check if the requested direction does not have a wall
if (inputDirection.x != 0) if (inputDirection.x != 0)
{ // Move in the requested direction, as well as perpundicular to it to get to the center of the tunnel { // Move in the requested direction, as well as perpundicular to it to get to the center of the tunnel
SetDirection(inputDirection + new Vector2(0, GridMoverTools.PositionToGrid(nextPosition).y - nextPosition.y).normalized); SetDirection(inputDirection + new Vector2(0, PositionToGrid(nextPosition).y - nextPosition.y).normalized);
} }
else else
{ {
SetDirection(inputDirection + new Vector2(GridMoverTools.PositionToGrid(nextPosition).x - nextPosition.x, 0).normalized); SetDirection(inputDirection + new Vector2(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 SetTargetDirection(inputDirection); // This is the direction most logic should assume pacman is moving, the actual direction may be different due to cornering
@@ -165,7 +168,7 @@ namespace Marro.PacManUdon
private Vector2 ProcessPredefinedPath(Vector2 position, Vector2 nextPosition) private Vector2 ProcessPredefinedPath(Vector2 position, Vector2 nextPosition)
{ {
if (GridMoverTools.CrossesTileCenter(position, nextPosition, direction.x != 0, direction.y != 0)) if (CrossesTileCenter(position, nextPosition, direction))
{ {
// Find the next valid direction which isn't Vector2.zero // Find the next valid direction which isn't Vector2.zero
int nextValidDirectionIndex = predefinedPathIndex; int nextValidDirectionIndex = predefinedPathIndex;
@@ -173,14 +176,14 @@ namespace Marro.PacManUdon
{ {
nextValidDirectionIndex += 1; nextValidDirectionIndex += 1;
} }
if (!GridMoverTools.CheckCollisionInDirection(transform, nextPosition, predefinedPath[nextValidDirectionIndex])) if (!CheckCollisionInDirection(transform, nextPosition, predefinedPath[nextValidDirectionIndex]))
{ {
// If we're at a Vector2.zero, we skip applying the direction and only increment. // If we're at a Vector2.zero, we skip applying the direction and only increment.
if (nextValidDirectionIndex == predefinedPathIndex) if (nextValidDirectionIndex == predefinedPathIndex)
{ {
SetDirection(predefinedPath[nextValidDirectionIndex]); SetDirection(predefinedPath[nextValidDirectionIndex]);
SetTargetDirection(predefinedPath[nextValidDirectionIndex]); SetTargetDirection(predefinedPath[nextValidDirectionIndex]);
nextPosition = GridMoverTools.PositionToGrid(nextPosition) + direction.normalized * 0.01f; nextPosition = PositionToGrid(nextPosition) + directionVectors[(int)direction] * 0.01f;
// Check if we've reached the end of the path, which includes making sure the path doesn't end on Vector2.zero // Check if we've reached the end of the path, which includes making sure the path doesn't end on Vector2.zero
do do
@@ -324,19 +327,19 @@ namespace Marro.PacManUdon
{ {
if (pellet.isPowerPellet) if (pellet.isPowerPellet)
{ {
gameController.GotPowerPellet(pellet); gameManager.GotPowerPellet(pellet);
freezeSeconds = 0.05f; freezeSeconds = 0.05f;
} }
else else
{ {
gameController.GotPellet(pellet); gameManager.GotPellet(pellet);
freezeSeconds = 0.0166666666666667f; freezeSeconds = 0.0166666666666667f;
} }
return; return;
} }
else if (other.gameObject.GetComponent<BonusFruit>()) else if (other.gameObject.GetComponent<BonusFruit>())
{ {
gameController.GotFruit(); gameManager.GotFruit();
} }
} }

View File

@@ -1,6 +1,7 @@
namespace Marro.PacManUdon namespace Marro.PacManUdon
{ {
using UnityEngine; using UnityEngine;
using VRC.Udon;
public enum PacManFruitType public enum PacManFruitType
{ {
@@ -49,16 +50,77 @@ namespace Marro.PacManUdon
Intermission3 Intermission3
} }
public enum PacManTileType
{
Empty = -1,
Wall = -2,
}
public static class PacManConstants public static class PacManConstants
{ {
// Jagged or 2D arrays can't be static so we work with 1D arrays
public static int[] GetMazeDefinition() => new int[] {
-02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02,
-02, 216, 215, 214, 213, 212, 196, 195, 194, 193, 192, 191, 190, -02, -02, 178, 179, 180, 181, 182, 183, 152, 151, 150, 149, 148, 147, -02,
-02, 217, -02, -02, -02, -02, 197, -02, -02, -02, -02, -02, 189, -02, -02, 177, -02, -02, -02, -02, -02, 153, -02, -02, -02, -02, 146, -02,
-02, 003, -02, -01, -01, -02, 198, -02, -01, -01, -01, -02, 188, -02, -02, 176, -02, -01, -01, -01, -02, 154, -02, -01, -01, -02, 002, -02,
-02, 218, -02, -02, -02, -02, 199, -02, -02, -02, -02, -02, 187, -02, -02, 175, -02, -02, -02, -02, -02, 155, -02, -02, -02, -02, 145, -02,
-02, 219, 220, 221, 222, 223, 200, 201, 202, 203, 204, 205, 186, 185, 184, 174, 173, 172, 165, 164, 163, 156, 157, 158, 159, 160, 144, -02,
-02, 224, -02, -02, -02, -02, 231, -02, -02, 206, -02, -02, -02, -02, -02, -02, -02, -02, 166, -02, -02, 161, -02, -02, -02, -02, 143, -02,
-02, 225, -02, -02, -02, -02, 232, -02, -02, 207, -02, -02, -02, -02, -02, -02, -02, -02, 167, -02, -02, 162, -02, -02, -02, -02, 142, -02,
-02, 226, 227, 228, 229, 230, 233, -02, -02, 208, 209, 210, 211, -02, -02, 171, 170, 169, 168, -02, -02, 136, 137, 138, 139, 140, 141, -02,
-02, -02, -02, -02, -02, -02, 234, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, 134, -02, -02, -02, -02, -02, -02,
-01, -01, -01, -01, -01, -02, 235, -02, -02, -02, -02, -02, -01, -02, -02, -01, -02, -02, -02, -02, -02, 133, -02, -01, -01, -01, -01, -01,
-01, -01, -01, -01, -01, -02, 236, -02, -02, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -02, -02, 132, -02, -01, -01, -01, -01, -01,
-01, -01, -01, -01, -01, -02, 237, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, 131, -02, -01, -01, -01, -01, -01,
-02, -02, -02, -02, -02, -02, 238, -02, -02, -01, -02, -01, -01, -01, -01, -01, -01, -02, -01, -02, -02, 130, -02, -02, -02, -02, -02, -02,
-01, -01, -01, -01, -01, -01, 239, -01, -01, -01, -02, -01, -01, -01, -01, -01, -01, -02, -01, -01, -01, 129, -01, -01, -01, -01, -01, -01,
-02, -02, -02, -02, -02, -02, 240, -02, -02, -01, -02, -01, -01, -01, -01, -01, -01, -02, -01, -02, -02, 128, -02, -02, -02, -02, -02, -02,
-01, -01, -01, -01, -01, -02, 241, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, 127, -02, -01, -01, -01, -01, -01,
-01, -01, -01, -01, -01, -02, 242, -02, -02, -01, -01, -01, -01, -01, -01, -01, -01, -01, -01, -02, -02, 126, -02, -01, -01, -01, -01, -01,
-01, -01, -01, -01, -01, -02, 243, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, 125, -02, -01, -01, -01, -01, -01,
-02, -02, -02, -02, -02, -02, 244, -02, -02, -01, -02, -02, -02, -02, -02, -02, -02, -02, -01, -02, -02, 124, -02, -02, -02, -02, -02, -02,
-02, 086, 087, 088, 089, 090, 091, 094, 095, 096, 097, 098, 099, -02, -02, 104, 105, 106, 107, 108, 109, 110, 123, 122, 121, 120, 119, -02,
-02, 085, -02, -02, -02, -02, 092, -02, -02, -02, -02, -02, 100, -02, -02, 103, -02, -02, -02, -02, -02, 111, -02, -02, -02, -02, 118, -02,
-02, 084, -02, -02, -02, -02, 093, -02, -02, -02, -02, -02, 101, -02, -02, 102, -02, -02, -02, -02, -02, 112, -02, -02, -02, -02, 117, -02,
-02, 000, 083, 082, -02, -02, 010, 009, 008, 007, 006, 005, 004, -01, -01, 063, 062, 061, 060, 059, 058, 057, -02, -02, 115, 116, 001, -02,
-02, -02, -02, 081, -02, -02, 011, -02, -02, 079, -02, -02, -02, -02, -02, -02, -02, -02, 064, -02, -02, 056, -02, -02, 114, -02, -02, -02,
-02, -02, -02, 080, -02, -02, 012, -02, -02, 078, -02, -02, -02, -02, -02, -02, -02, -02, 065, -02, -02, 055, -02, -02, 113, -02, -02, -02,
-02, 018, 017, 016, 015, 014, 013, -02, -02, 077, 076, 075, 074, -02, -02, 069, 068, 067, 066, -02, -02, 054, 053, 052, 051, 050, 049, -02,
-02, 019, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, 073, -02, -02, 070, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, 048, -02,
-02, 020, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, 072, -02, -02, 071, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, 047, -02,
-02, 021, 022, 023, 024, 025, 026, 027, 028, 029, 030, 031, 032, 033, 034, 035, 036, 037, 038, 039, 040, 041, 042, 043, 044, 045, 046, -02,
-02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02, -02,
};
public static int[] GetPelletIndices() => new int[]
{
645, 670, 110, 085, 656, 655, 654, 653, 652, 651, 650, 678, 706, 734, 733, 732,
731, 730, 729, 757, 785, 813, 814, 815, 816, 817, 818, 819, 820, 821, 822, 823,
824, 825, 826, 827, 828, 829, 830, 831, 832, 833, 834, 835, 836, 837, 838, 810,
782, 754, 753, 752, 751, 750, 749, 721, 693, 665, 664, 663, 662, 661, 660, 659,
690, 718, 746, 745, 744, 743, 771, 799, 796, 768, 740, 739, 738, 737, 709, 681,
703, 675, 647, 646, 617, 589, 561, 562, 563, 564, 565, 566, 594, 622, 567, 568,
569, 570, 571, 572, 600, 628, 631, 603, 575, 576, 577, 578, 579, 580, 581, 609,
637, 724, 696, 668, 669, 642, 614, 586, 585, 584, 583, 582, 553, 525, 497, 469,
441, 413, 385, 357, 329, 301, 273, 245, 245, 246, 247, 248, 249, 250, 222, 194,
166, 138, 082, 054, 053, 052, 051, 050, 049, 077, 105, 133, 161, 162, 163, 164,
165, 189, 217, 160, 159, 158, 186, 214, 242, 241, 240, 239, 157, 156, 155, 127,
099, 071, 043, 044, 045, 046, 047, 048, 154, 153, 152, 124, 096, 068, 040, 039,
038, 037, 036, 035, 034, 062, 090, 118, 146, 147, 148, 149, 150, 151, 177, 205,
233, 234, 235, 236, 033, 032, 031, 030, 029, 057, 113, 141, 142, 143, 144, 145,
169, 197, 225, 226, 227, 228, 229, 174, 202, 230, 258, 286, 314, 342, 370, 398,
426, 454, 482, 510, 538,
};
public static GameObject[] ComponentsToGameObjects(Component[] components, bool skipFirstComponent = false) public static GameObject[] ComponentsToGameObjects(Component[] components, bool skipFirstComponent = false)
{ {
if (skipFirstComponent) if (skipFirstComponent)
{ {
GameObject[] gameObjects = new GameObject[components.Length-1]; GameObject[] gameObjects = new GameObject[components.Length - 1];
for (int i = 0; i < components.Length-1; i++) for (int i = 0; i < components.Length - 1; i++)
{ {
gameObjects[i] = components[i+1].gameObject; gameObjects[i] = components[i + 1].gameObject;
} }
return gameObjects; return gameObjects;
} }
@@ -97,15 +159,15 @@ namespace Marro.PacManUdon
PacManFruitType.Bell, PacManFruitType.Bell,
PacManFruitType.Key PacManFruitType.Key
}; };
if (level-1 < 0) if (level - 1 < 0)
{ {
return PacManFruitType.None; return PacManFruitType.None;
} }
if (level-1 >= FruitTypePerLevel.Length) if (level - 1 >= FruitTypePerLevel.Length)
{ {
return FruitTypePerLevel[FruitTypePerLevel.Length-1]; return FruitTypePerLevel[FruitTypePerLevel.Length - 1];
} }
return FruitTypePerLevel[level-1]; return FruitTypePerLevel[level - 1];
} }
public static float GetGhostHomeSpeed() public static float GetGhostHomeSpeed()
@@ -115,96 +177,96 @@ namespace Marro.PacManUdon
public static float GetPacManDefaultSpeedForLevel(int level) public static float GetPacManDefaultSpeedForLevel(int level)
{ {
if(level <= 1) return 7.576f; if (level <= 1) return 7.576f;
if(level <= 4) return 8.523f; if (level <= 4) return 8.523f;
if(level <= 20) return 9.470f; if (level <= 20) return 9.470f;
return 8.523f; return 8.523f;
} }
public static float GetPacManPowerPelletSpeedForLevel(int level) public static float GetPacManPowerPelletSpeedForLevel(int level)
{ {
if(level <= 1) return 8.523f; if (level <= 1) return 8.523f;
if(level <= 4) return 8.996f; if (level <= 4) return 8.996f;
return 9.470f; return 9.470f;
} }
public static float GetGhostDefaultSpeedForLevel(int level) public static float GetGhostDefaultSpeedForLevel(int level)
{ {
if(level <= 1) return 7.102f; if (level <= 1) return 7.102f;
if(level <= 4) return 8.049f; if (level <= 4) return 8.049f;
return 8.996f; return 8.996f;
} }
public static float GetGhostTunnelSpeedForLevel(int level) public static float GetGhostTunnelSpeedForLevel(int level)
{ {
if(level <= 1) return 3.788f; if (level <= 1) return 3.788f;
if(level <= 4) return 4.261f; if (level <= 4) return 4.261f;
return 4.735f; return 4.735f;
} }
public static float GetBlinkyElroy1SpeedForLevel(int level) public static float GetBlinkyElroy1SpeedForLevel(int level)
{ {
if(level <= 1) return 7.576f; if (level <= 1) return 7.576f;
if(level <= 4) return 8.523f; if (level <= 4) return 8.523f;
return 9.470f; return 9.470f;
} }
public static float GetBlinkyElroy2SpeedForLevel(int level) public static float GetBlinkyElroy2SpeedForLevel(int level)
{ {
if(level <= 1) return 8.049f; if (level <= 1) return 8.049f;
if(level <= 4) return 8.996f; if (level <= 4) return 8.996f;
return 9.943f; return 9.943f;
} }
public static float GetGhostScaredSpeedForLevel(int level) public static float GetGhostScaredSpeedForLevel(int level)
{ {
if(level <= 1) return 4.735f; if (level <= 1) return 4.735f;
if(level <= 4) return 5.208f; if (level <= 4) return 5.208f;
return 5.682f; return 5.682f;
} }
public static int GetElroy1PelletsRemainingForLevel(int level) public static int GetElroy1PelletsRemainingForLevel(int level)
{ {
if(level <= 1) return 20; if (level <= 1) return 20;
if(level <= 2) return 30; if (level <= 2) return 30;
if(level <= 5) return 40; if (level <= 5) return 40;
if(level <= 8) return 50; if (level <= 8) return 50;
if(level <= 11) return 60; if (level <= 11) return 60;
if(level <= 14) return 80; if (level <= 14) return 80;
if(level <= 18) return 100; if (level <= 18) return 100;
return 120; return 120;
} }
public static int GetElroy2PelletsRemainingForLevel(int level) public static int GetElroy2PelletsRemainingForLevel(int level)
{ {
if(level <= 1) return 10; if (level <= 1) return 10;
if(level <= 2) return 15; if (level <= 2) return 15;
if(level <= 5) return 20; if (level <= 5) return 20;
if(level <= 8) return 25; if (level <= 8) return 25;
if(level <= 11) return 30; if (level <= 11) return 30;
if(level <= 14) return 40; if (level <= 14) return 40;
if(level <= 18) return 50; if (level <= 18) return 50;
return 60; return 60;
} }
public static float GetGhostHousePelletTimeoutLimitForLevel(int level) public static float GetGhostHousePelletTimeoutLimitForLevel(int level)
{ {
if(level <= 4) return 4; if (level <= 4) return 4;
return 3; return 3;
} }
public static int[] GetGhostHousePrivatePelletCounterLimitForLevel(int level) public static int[] GetGhostHousePrivatePelletCounterLimitForLevel(int level)
{ {
if(level <= 1) return new int[] { 0, 0, 30, 60}; if (level <= 1) return new int[] { 0, 0, 30, 60 };
if(level <= 2) return new int[] { 0, 0, 0, 50}; if (level <= 2) return new int[] { 0, 0, 0, 50 };
return new int[] { 0, 0, 0, 0}; return new int[] { 0, 0, 0, 0 };
} }
public static float[] GetScatterPatternForLevel(int level) public static float[] GetScatterPatternForLevel(int level)
{ {
if(level <= 1) return new float[] { 7, 27, 34, 54, 59, 79, 84 }; if (level <= 1) return new float[] { 7, 27, 34, 54, 59, 79, 84 };
if(level <= 4) return new float[] { 7, 27, 34, 54, 59, 1092, 1092.0166667f}; if (level <= 4) return new float[] { 7, 27, 34, 54, 59, 1092, 1092.0166667f };
return new float[] { 5, 25, 30, 50, 55, 1092, 1092.0166667f}; return new float[] { 5, 25, 30, 50, 55, 1092, 1092.0166667f };
} }
public static float GetScaredDurationForLevel(int level) public static float GetScaredDurationForLevel(int level)
@@ -231,15 +293,15 @@ namespace Marro.PacManUdon
1, 1,
0 0
}; };
if (level-1 < 0) if (level - 1 < 0)
{ {
return scaredDurationPerLevel[0]; return scaredDurationPerLevel[0];
} }
if (level-1 >= scaredDurationPerLevel.Length) if (level - 1 >= scaredDurationPerLevel.Length)
{ {
return scaredDurationPerLevel[scaredDurationPerLevel.Length-1]; return scaredDurationPerLevel[scaredDurationPerLevel.Length - 1];
} }
return scaredDurationPerLevel[level-1]; return scaredDurationPerLevel[level - 1];
} }
public static float GetScaredNumberOfFlashesForLevel(int level) public static float GetScaredNumberOfFlashesForLevel(int level)
@@ -266,18 +328,19 @@ namespace Marro.PacManUdon
3, 3,
0 0
}; };
if (level-1 < 0) if (level - 1 < 0)
{ {
return scaredNumberOfFlashesPerLevel[0]; return scaredNumberOfFlashesPerLevel[0];
} }
if (level-1 >= scaredNumberOfFlashesPerLevel.Length) if (level - 1 >= scaredNumberOfFlashesPerLevel.Length)
{ {
return scaredNumberOfFlashesPerLevel[scaredNumberOfFlashesPerLevel.Length-1]; return scaredNumberOfFlashesPerLevel[scaredNumberOfFlashesPerLevel.Length - 1];
} }
return scaredNumberOfFlashesPerLevel[level-1]; return scaredNumberOfFlashesPerLevel[level - 1];
} }
public static int FruitTypeToValue(PacManFruitType fruitType) { // I can't get casting from enum to int to work so this is a workaround public static int FruitTypeToValue(PacManFruitType fruitType)
{ // I can't get casting from enum to int to work so this is a workaround
switch (fruitType) switch (fruitType)
{ {
default: default:

View File

@@ -43,7 +43,7 @@ MonoBehaviour:
Data: Data:
- Name: - Name:
Entry: 12 Entry: 12
Data: 9 Data: 10
- Name: - Name:
Entry: 7 Entry: 7
Data: Data:
@@ -530,6 +530,60 @@ MonoBehaviour:
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: tilemap
- Name: $v
Entry: 7
Data: 29|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: tilemap
- Name: <UserType>k__BackingField
Entry: 7
Data: 30|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Int32[], mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 30
- 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: 31|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: - Name:
Entry: 13 Entry: 13
Data: Data:

View File

@@ -18,6 +18,11 @@ namespace Marro.PacManUdon
byte[] syncedPelletsCollected; byte[] syncedPelletsCollected;
int[] tilemap;
const int mazeWidth = 28;
const int mazeHeight = 31;
public void Initialize() public void Initialize()
{ {
gameObject.SetActive(true); gameObject.SetActive(true);
@@ -32,6 +37,7 @@ namespace Marro.PacManUdon
SubscribeToEvent(NetworkEventType.SyncPellets); SubscribeToEvent(NetworkEventType.SyncPellets);
} }
#region Power pellet blink
public override void SyncedUpdate() public override void SyncedUpdate()
{ {
if (!powerPelletBlinkEnabled) if (!powerPelletBlinkEnabled)
@@ -72,7 +78,39 @@ namespace Marro.PacManUdon
{ {
powerPelletBlinkEnabled = !frozen; powerPelletBlinkEnabled = !frozen;
} }
#endregion
#region Collision
public bool IsWallUpcoming(Vector2 position, Vector2 directionVector)
{
var result = GetTileAt(position + directionVector) == (int)PacManTileType.Wall;
Debug.Log($"Is wall upcoming {result} at position {position}, direction {directionVector}");
return result;
}
public bool[] GetBlockedDirections(Vector2 position)
{
var results = new bool[4];
results[0] = IsWallUpcoming(position, Vector2.down);
results[1] = IsWallUpcoming(position, Vector2.up);
results[2] = IsWallUpcoming(position, Vector2.left);
results[3] = IsWallUpcoming(position, Vector2.right);
return results;
}
private int GetTileAt(Vector2 position) => tilemap[GetTilemapIndex(position)];
private int GetTilemapIndex(Vector2 position)
{
position = Clamp(position, 0, mazeWidth - 1, 1 - mazeHeight, 0);
var index = (int)(position.x + 0.5) - (int)(position.y - 0.5) * mazeWidth;
return index;
}
#endregion
#region Pellet collecting
public int PelletCollected(Pellet pellet) public int PelletCollected(Pellet pellet)
{ {
pellet.gameObject.SetActive(false); pellet.gameObject.SetActive(false);
@@ -95,6 +133,8 @@ namespace Marro.PacManUdon
syncedPelletsCollected = new byte[pellets.Length/8 + 1]; syncedPelletsCollected = new byte[pellets.Length/8 + 1];
PelletCollectedCount = 0; PelletCollectedCount = 0;
tilemap = PacManConstants.GetMazeDefinition();
return PelletCount; return PelletCount;
} }
@@ -131,5 +171,33 @@ namespace Marro.PacManUdon
SetPelletsCollectedFromSync(); SetPelletsCollectedFromSync();
return true; return true;
} }
#endregion
#region Utils
private static Vector2 Clamp(Vector2 vector, float xMin, float xMax, float yMin, float yMax)
{
if (vector.x < xMin)
{
vector.x = xMin;
}
if (vector.x > xMax)
{
vector.x = xMax;
}
if (vector.y < yMin)
{
vector.y = yMin;
}
if (vector.y > yMax)
{
vector.y = yMax;
}
return vector;
}
#endregion
} }
} }

View File

@@ -90,7 +90,7 @@ namespace Marro.PacManUdon
pacMan.SetKinematic(true); pacMan.SetKinematic(true);
pacMan.SetActive(true); pacMan.SetActive(true);
pacMan.SetPosition(attractScreenElements[16].transform.localPosition); pacMan.SetPosition(attractScreenElements[16].transform.localPosition);
pacMan.SetDirection(Vector2.left); pacMan.SetDirection(Direction.Left);
ghostManager.RestartLevel(); ghostManager.RestartLevel();
ghostManager.SetLevel(2); ghostManager.SetLevel(2);
@@ -100,7 +100,7 @@ namespace Marro.PacManUdon
for (int i = 0; i < ghosts.Length; i++) for (int i = 0; i < ghosts.Length; i++)
{ {
ghosts[i].SetPosition(attractScreenElements[17 + i].transform.localPosition); ghosts[i].SetPosition(attractScreenElements[17 + i].transform.localPosition);
ghosts[i].SetDirection(Vector2.left); ghosts[i].SetDirection(Direction.Left);
ghosts[i].SetState(PacManGhostState.Normal); ghosts[i].SetState(PacManGhostState.Normal);
} }
break; break;
@@ -119,7 +119,7 @@ namespace Marro.PacManUdon
case 18: case 18:
// Turn PacMan around after eating power pellet // Turn PacMan around after eating power pellet
pacMan.SetDirection(Vector2.right); pacMan.SetDirection(Direction.Right);
pacMan.SetTargetDirection(Vector2.right); pacMan.SetTargetDirection(Vector2.right);
break; break;

View File

@@ -26,14 +26,14 @@ namespace Marro.PacManUdon
pacMan.SetKinematic(true); pacMan.SetKinematic(true);
pacMan.SetActive(true); pacMan.SetActive(true);
pacMan.SetPosition(intermissionScreenElements[0].transform.localPosition); pacMan.SetPosition(intermissionScreenElements[0].transform.localPosition);
pacMan.SetDirection(Vector2.left); pacMan.SetDirection(Direction.Left);
ghostManager.SetLevel(5); ghostManager.SetLevel(5);
ghostManager.SetKinematic(true); ghostManager.SetKinematic(true);
ghostManager.gameObject.SetActive(true); ghostManager.gameObject.SetActive(true);
blinky.SetElroy(2); blinky.SetElroy(2);
blinky.SetPosition(intermissionScreenElements[1].transform.localPosition); blinky.SetPosition(intermissionScreenElements[1].transform.localPosition);
blinky.SetDirection(Vector2.left); blinky.SetDirection(Direction.Left);
blinky.SetState(PacManGhostState.Normal); blinky.SetState(PacManGhostState.Normal);
SetFrozen(false); SetFrozen(false);
@@ -46,14 +46,14 @@ namespace Marro.PacManUdon
// Reached end, make ghost scared and turn around // Reached end, make ghost scared and turn around
blinky.BecomeScared(); blinky.BecomeScared();
blinky.SetPosition(intermissionScreenElements[3].transform.localPosition); blinky.SetPosition(intermissionScreenElements[3].transform.localPosition);
pacMan.SetDirection(Vector2.zero); pacMan.SetDirection(Direction.Zero);
pacMan.SetPosition(intermissionScreenElements[2].transform.localPosition); pacMan.SetPosition(intermissionScreenElements[2].transform.localPosition);
pacMan.SetPowerPellet(true); pacMan.SetPowerPellet(true);
break; break;
case 4: case 4:
// Pacman starts chasing ghosts // Pacman starts chasing ghosts
pacMan.SetDirection(Vector2.right); pacMan.SetDirection(Direction.Right);
pacMan.BecomeBig(); pacMan.BecomeBig();
break; break;
case 5: case 5:

View File

@@ -34,14 +34,14 @@ namespace Marro.PacManUdon
pacMan.SetKinematic(true); pacMan.SetKinematic(true);
pacMan.SetActive(true); pacMan.SetActive(true);
pacMan.SetPosition(intermissionScreenElements[0].transform.localPosition); pacMan.SetPosition(intermissionScreenElements[0].transform.localPosition);
pacMan.SetDirection(Vector2.left); pacMan.SetDirection(Direction.Left);
ghostManager.SetLevel(5); ghostManager.SetLevel(5);
ghostManager.SetKinematic(true); ghostManager.SetKinematic(true);
ghostManager.gameObject.SetActive(true); ghostManager.gameObject.SetActive(true);
blinky.SetElroy(2); blinky.SetElroy(2);
blinky.SetPosition(intermissionScreenElements[1].transform.localPosition); blinky.SetPosition(intermissionScreenElements[1].transform.localPosition);
blinky.SetDirection(Vector2.left); blinky.SetDirection(Direction.Left);
blinky.SetState(PacManGhostState.Normal); blinky.SetState(PacManGhostState.Normal);
SetFrozen(false); SetFrozen(false);
@@ -65,16 +65,16 @@ namespace Marro.PacManUdon
case 8: case 8:
// Blinky sprite updates with broken cover // Blinky sprite updates with broken cover
blinky.SetSpecialLook(true); blinky.SetSpecialLook(true);
blinky.SetDirection(Vector2.up); blinky.SetDirection(Direction.Up);
blinky.SetPosition(blinky.GetPosition() + new Vector2(-0.250f, 0f)); blinky.SetPosition(blinky.GetPosition() + new Vector2(-0.250f, 0f));
break; break;
case 9: case 9:
// Blinky looks at broken cover // Blinky looks at broken cover
blinky.SetDirection(Vector2.down); blinky.SetDirection(Direction.Down);
break; break;
case 10: case 10:
// Cutscene starts to unload // Cutscene starts to unload
blinky.SetDirection(Vector2.zero); blinky.SetDirection(Direction.Zero);
break; break;
case 11: case 11:
// End cutscene // End cutscene

View File

@@ -26,14 +26,14 @@ namespace Marro.PacManUdon
pacMan.SetKinematic(true); pacMan.SetKinematic(true);
pacMan.SetActive(true); pacMan.SetActive(true);
pacMan.SetPosition(intermissionScreenElements[0].transform.localPosition); pacMan.SetPosition(intermissionScreenElements[0].transform.localPosition);
pacMan.SetDirection(Vector2.left); pacMan.SetDirection(Direction.Left);
ghostManager.SetLevel(5); ghostManager.SetLevel(5);
ghostManager.SetKinematic(true); ghostManager.SetKinematic(true);
ghostManager.gameObject.SetActive(true); ghostManager.gameObject.SetActive(true);
blinky.SetElroy(2); blinky.SetElroy(2);
blinky.SetPosition(intermissionScreenElements[1].transform.localPosition); blinky.SetPosition(intermissionScreenElements[1].transform.localPosition);
blinky.SetDirection(Vector2.left); blinky.SetDirection(Direction.Left);
blinky.SetState(PacManGhostState.Normal); blinky.SetState(PacManGhostState.Normal);
blinky.SetSpecialLook(true); blinky.SetSpecialLook(true);
@@ -45,13 +45,13 @@ namespace Marro.PacManUdon
break; break;
case 3: case 3:
// Reached end, freeze // Reached end, freeze
pacMan.SetDirection(Vector2.zero); pacMan.SetDirection(Direction.Zero);
blinky.SetDirection(Vector2.zero); blinky.SetDirection(Direction.Zero);
break; break;
case 4: case 4:
// Ghost runs back on screen // Ghost runs back on screen
blinky.SetPosition(intermissionScreenElements[3].transform.localPosition); blinky.SetPosition(intermissionScreenElements[3].transform.localPosition);
blinky.SetDirection(Vector2.right); blinky.SetDirection(Direction.Right);
break; break;
case 5: case 5:
// End cutscene // End cutscene

View File

@@ -2,61 +2,21 @@
{ {
using UdonSharp; using UdonSharp;
using UnityEngine; using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
enum Direction
{
Any,
Up,
Left,
Down,
Right
}
public class Teleporter : UdonSharpBehaviour public class Teleporter : UdonSharpBehaviour
{ {
[SerializeField] private Direction direction = Direction.Any; [SerializeField] private Direction direction = Direction.Zero;
[SerializeField] private Transform target; [SerializeField] private Transform target;
void OnTriggerEnter(Collider other) void OnTriggerEnter(Collider other)
{ {
GridMover gridMover = other.gameObject.GetComponent<GridMover>(); GridMover gridMover = other.gameObject.GetComponent<GridMover>();
if (gridMover == null) if (gridMover == null || gridMover.GetDirection() != direction)
{ {
return; return;
} }
switch (direction)
{
case Direction.Up:
if (gridMover.GetDirection().y < 0)
{
return;
}
break;
case Direction.Down:
if (gridMover.GetDirection().y > 0)
{
return;
}
break;
case Direction.Left:
if (gridMover.GetDirection().x > 0)
{
return;
}
break;
case Direction.Right:
if (gridMover.GetDirection().x < 0)
{
return;
}
break;
default:
break;
}
gridMover.SetPosition(gridMover.GetPosition() + (Vector2)(target.localPosition - transform.localPosition)); gridMover.SetPosition(gridMover.GetPosition() + (Vector2)(target.localPosition - transform.localPosition));
} }
} }

View File

@@ -0,0 +1,52 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c333ccfdd0cbdbc4ca30cef2dd6e6b9b, type: 3}
m_Name: MazeDefinitionGenerator
m_EditorClassIdentifier:
serializedUdonProgramAsset: {fileID: 11400000, guid: ea99e044f80fed446bb669640608f521, type: 2}
udonAssembly:
assemblyError:
sourceCsScript: {fileID: 11500000, guid: 30a9bec71a4b36a41a9b6ee899bef38c, type: 3}
scriptVersion: 2
compiledVersion: 2
behaviourSyncMode: 0
hasInteractEvent: 0
scriptID: 6724330659013342737
serializationData:
SerializedFormat: 2
SerializedBytes:
ReferencedUnityObjects: []
SerializedBytesString:
Prefab: {fileID: 0}
PrefabModificationsReferencedUnityObjects: []
PrefabModifications: []
SerializationNodes:
- Name: fieldDefinitions
Entry: 7
Data: 0|System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[UdonSharp.Compiler.FieldDefinition,
UdonSharp.Editor]], mscorlib
- Name: comparer
Entry: 7
Data: 1|System.Collections.Generic.GenericEqualityComparer`1[[System.String,
mscorlib]], mscorlib
- Name:
Entry: 8
Data:
- Name:
Entry: 12
Data: 0
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 909752e684c57f24093795e3ba5e2c80
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,113 @@
using Marro.PacManUdon;
using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
public class MazeDefinitionGenerator : UdonSharpBehaviour
{
void Start()
{
GetMazeMap();
}
private void GetMazeMap()
{
var pellets = GetComponentsInChildren<Pellet>(includeInactive: true);
var width = 28;
var height = 31;
int[] map = new int[width * height];
int[] pelletLocations = new int[pellets.Length];
var collisionMap = GetCollisionMap();
for (int i = 0; i < map.Length; i++)
{
if (collisionMap[i])
{
map[i] = (int)PacManTileType.Wall;
}
else
{
map[i] = (int)PacManTileType.Empty;
}
}
for (int i = 0; i < pellets.Length; i++)
{
Pellet pellet = pellets[i];
var position = GridMover.PositionToGrid(new Vector2(pellet.transform.localPosition.x, - pellet.transform.localPosition.y));
var index = (int)position.x + (int)position.y * width;
map[index] = i;
pelletLocations[i] = index;
}
var result = "";
for (int i = 0; i < map.Length; i++)
{
if (map[i] < 0)
{
result += $"{map[i]:00}, ";
}
else
{
result += $"{map[i]:000}, ";
}
if (i % width == width - 1)
{
result += "\n";
}
}
Debug.Log(result);
result = "";
for (int i = 0; i < pelletLocations.Length; i++)
{
result += $"{pelletLocations[i]:000}, ";
if (i % 16 == 15)
{
result += "\n";
}
}
Debug.Log(result);
}
public static bool[] GetCollisionMap() => new bool[] {
true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true ,
true, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, true ,
true, false, true, true, true, true, false, true, true, true, true, true, false, true, true, false, true, true, true, true, true, false, true, true, true, true, false, true ,
true, false, true, false, false, true, false, true, false, false, false, true, false, true, true, false, true, false, false, false, true, false, true, false, false, true, false, true ,
true, false, true, true, true, true, false, true, true, true, true, true, false, true, true, false, true, true, true, true, true, false, true, true, true, true, false, true ,
true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true ,
true, false, true, true, true, true, false, true, true, false, true, true, true, true, true, true, true, true, false, true, true, false, true, true, true, true, false, true ,
true, false, true, true, true, true, false, true, true, false, true, true, true, true, true, true, true, true, false, true, true, false, true, true, true, true, false, true ,
true, false, false, false, false, false, false, true, true, false, false, false, false, true, true, false, false, false, false, true, true, false, false, false, false, false, false, true ,
true, true, true, true, true, true, false, true, true, true, true, true, false, true, true, false, true, true, true, true, true, false, true, true, true, true, true, true ,
false, false, false, false, false, true, false, true, true, true, true, true, false, true, true, false, true, true, true, true, true, false, true, false, false, false, false, false ,
false, false, false, false, false, true, false, true, true, false, false, false, false, false, false, false, false, false, false, true, true, false, true, false, false, false, false, false ,
false, false, false, false, false, true, false, true, true, false, true, true, true, true, true, true, true, true, false, true, true, false, true, false, false, false, false, false ,
true, true, true, true, true, true, false, true, true, false, true, false, false, false, false, false, false, true, false, true, true, false, true, true, true, true, true, true ,
false, false, false, false, false, false, false, false, false, false, true, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false ,
true, true, true, true, true, true, false, true, true, false, true, false, false, false, false, false, false, true, false, true, true, false, true, true, true, true, true, true ,
false, false, false, false, false, true, false, true, true, false, true, true, true, true, true, true, true, true, false, true, true, false, true, false, false, false, false, false ,
false, false, false, false, false, true, false, true, true, false, false, false, false, false, false, false, false, false, false, true, true, false, true, false, false, false, false, false ,
false, false, false, false, false, true, false, true, true, false, true, true, true, true, true, true, true, true, false, true, true, false, true, false, false, false, false, false ,
true, true, true, true, true, true, false, true, true, false, true, true, true, true, true, true, true, true, false, true, true, false, true, true, true, true, true, true ,
true, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, true ,
true, false, true, true, true, true, false, true, true, true, true, true, false, true, true, false, true, true, true, true, true, false, true, true, true, true, false, true ,
true, false, true, true, true, true, false, true, true, true, true, true, false, true, true, false, true, true, true, true, true, false, true, true, true, true, false, true ,
true, false, false, false, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true, true, false, false, false, true ,
true, true, true, false, true, true, false, true, true, false, true, true, true, true, true, true, true, true, false, true, true, false, true, true, false, true, true, true ,
true, true, true, false, true, true, false, true, true, false, true, true, true, true, true, true, true, true, false, true, true, false, true, true, false, true, true, true ,
true, false, false, false, false, false, false, true, true, false, false, false, false, true, true, false, false, false, false, true, true, false, false, false, false, false, false, true ,
true, false, true, true, true, true, true, true, true, true, true, true, false, true, true, false, true, true, true, true, true, true, true, true, true, true, false, true ,
true, false, true, true, true, true, true, true, true, true, true, true, false, true, true, false, true, true, true, true, true, true, true, true, true, true, false, true ,
true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, true ,
true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true
};
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: f317309f5509067439e01d1111249555 guid: 30a9bec71a4b36a41a9b6ee899bef38c
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@@ -43,7 +43,7 @@ MonoBehaviour:
Data: Data:
- Name: - Name:
Entry: 12 Entry: 12
Data: 7 Data: 10
- Name: - Name:
Entry: 7 Entry: 7
Data: Data:
@@ -349,19 +349,19 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: captureTime Data: captureTimes
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 22|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 22|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: captureTime Data: captureTimes
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 7
Data: 23|System.RuntimeType, mscorlib Data: 23|System.RuntimeType, mscorlib
- Name: - Name:
Entry: 1 Entry: 1
Data: System.Single, mscorlib Data: System.Int32[], mscorlib
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
@@ -403,25 +403,31 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: positions Data: positionCaptures
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 25|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 25|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: positions Data: positionCaptures
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 7
Data: 26|System.RuntimeType, mscorlib Data: 26|System.RuntimeType, mscorlib
- Name: - Name:
Entry: 1 Entry: 1
Data: UnityEngine.Vector2[], UnityEngine.CoreModule Data: UnityEngine.Vector2[][], UnityEngine.CoreModule
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 7
Data: 26 Data: 27|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Object[], mscorlib
- Name:
Entry: 8
Data:
- Name: <SyncMode>k__BackingField - Name: <SyncMode>k__BackingField
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -436,7 +442,157 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 27|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib Data: 28|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: ownerIndex
- Name: $v
Entry: 7
Data: 29|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: ownerIndex
- Name: <UserType>k__BackingField
Entry: 7
Data: 30|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Int32, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 30
- 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: 31|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: remoteIndex
- Name: $v
Entry: 7
Data: 32|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: remoteIndex
- Name: <UserType>k__BackingField
Entry: 9
Data: 30
- Name: <SystemType>k__BackingField
Entry: 9
Data: 30
- 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: 33|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: previousCaptureTime
- Name: $v
Entry: 7
Data: 34|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: previousCaptureTime
- Name: <UserType>k__BackingField
Entry: 9
Data: 30
- Name: <SystemType>k__BackingField
Entry: 9
Data: 30
- 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: 35|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0

View File

@@ -14,66 +14,79 @@ public class NetworkManagerSyncTester : UdonSharpBehaviour
[SerializeField] GridMover[] gridMovers2; [SerializeField] GridMover[] gridMovers2;
[SerializeField] Animator debugImageToIndicateSynced; [SerializeField] Animator debugImageToIndicateSynced;
private float captureTime; private int[] captureTimes = new int[1000];
private Vector2[] positions; private Vector2[][] positionCaptures = new Vector2[1000][];
private int ownerIndex = -1;
private int remoteIndex = 0;
private int previousCaptureTime = -1;
public void Update() public void Update()
{ {
if (!networkManager1.Synced || !networkManager2.Synced) if (!networkManager1.Synced || !networkManager2.Synced)
{ {
positions = null; ownerIndex = -1;
remoteIndex = 0;
return; return;
} }
if (positions == null) var ownerTime = networkManager1.SyncedTimeTicks;
if (ownerTime > previousCaptureTime)
{ {
positions = GetPositions(gridMovers1); IncrementIndex(ref ownerIndex);
captureTime = networkManager1.SyncedTime; captureTimes[ownerIndex] = ownerTime;
previousCaptureTime = ownerTime;
positionCaptures[ownerIndex] = GetPositions(gridMovers1);
} }
var remoteTime = networkManager2.SyncedTime; var remoteTime = networkManager2.SyncedTimeTicks;
if (captureTime > remoteTime)
while (captureTimes[remoteIndex] < remoteTime && remoteIndex != ownerIndex)
{ {
return; DiscardCapture();
} }
if (captureTime < remoteTime) Debug.Log($"ownerTime: {ownerTime}, remoteTime: {remoteTime}, ownerIndex: {ownerIndex} ({captureTimes[ownerIndex]}), remoteIndex: {remoteIndex} ({captureTimes[remoteIndex]})");
if (captureTimes[remoteIndex] == remoteTime)
{ {
Debug.Log($"{nameof(NetworkManagerSyncTester)} Skipping check"); bool equal = IsEqual(remoteIndex);
positions = null; SetIndicator(equal);
return;
DiscardCapture();
} }
bool equal = IsEqual(remoteTime);
SetIndicator(equal);
positions = null;
} }
private bool IsEqual(float remoteTime) private void DiscardCapture()
{ {
positionCaptures[remoteIndex] = null;
IncrementIndex(ref remoteIndex);
}
private bool IsEqual(int index)
{
var equal = true;
var positions1 = positionCaptures[index];
var positions2 = GetPositions(gridMovers2); var positions2 = GetPositions(gridMovers2);
for (int i = 0; i < positions.Length; i++) for (int i = 0; i < positions1.Length; i++)
{ {
var gridMover1 = gridMovers1[i]; var gridMover1 = gridMovers1[i];
var gridMover1Position = positions[i]; var gridMover1Position = positions1[i];
var gridMover2 = gridMovers2[i]; var gridMover2 = gridMovers2[i];
var gridMover2Position = positions2[i]; var gridMover2Position = positions2[i];
var equal = gridMover1Position == gridMover2Position; if (gridMover1Position != gridMover2Position)
if (!equal)
{ {
Debug.LogWarning($"{nameof(NetworkManagerSyncTester)} Desync found:\n{gridMover1.name} {gridMover1Position} (at {captureTime}) != {gridMover2.name} {gridMover2Position} (at {remoteTime})"); Debug.LogWarning($"{nameof(NetworkManagerSyncTester)} Desync found:\n{gridMover1.name} {gridMover1Position} != {gridMover2.name} {gridMover2Position}");
networkManager1.Pause(); //networkManager1.Pause();
networkManager2.Pause(); //networkManager2.Pause();
return false; equal = false;
} }
} }
return true; return equal;
} }
private void SetIndicator(bool value) private void SetIndicator(bool value)
@@ -84,7 +97,7 @@ public class NetworkManagerSyncTester : UdonSharpBehaviour
} }
} }
private Vector2[] GetPositions(GridMover[] gridMovers) private static Vector2[] GetPositions(GridMover[] gridMovers)
{ {
var length = gridMovers.Length; var length = gridMovers.Length;
var positions = new Vector2[length]; var positions = new Vector2[length];
@@ -96,4 +109,16 @@ public class NetworkManagerSyncTester : UdonSharpBehaviour
return positions; return positions;
} }
private void IncrementIndex(ref int index)
{
if (index >= positionCaptures.Length - 1)
{
index = 0;
}
else
{
index++;
}
}
} }

View File

@@ -6,6 +6,7 @@ using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using VRC.SDKBase; using VRC.SDKBase;
using VRC.Udon; using VRC.Udon;
using UnityEngine.Tilemaps;
public class TestBallManager : UdonSharpBehaviour public class TestBallManager : UdonSharpBehaviour
{ {