Compare commits

...

12 Commits

Author SHA1 Message Date
a8b395b1d3 Fixed bug 2026-02-01 15:42:33 +01:00
d03d06b5a7 Applied constant update rate 2026-02-01 15:03:52 +01:00
912be35172 Working on ghost issues 2026-01-24 16:23:53 +01:00
1433b9bdfc Ghosts synced with some issues 2026-01-24 15:04:54 +01:00
9554d1c512 Working on ghost sync 2026-01-19 20:08:06 +01:00
c3a19cc53e Pellet sync 2026-01-18 19:28:12 +01:00
eef7084e21 Fixed ghost bug 2026-01-18 17:14:15 +01:00
f2910d7506 Fix 2026-01-18 17:12:25 +01:00
9f86308d8a Test files 2026-01-18 16:47:11 +01:00
305a0ec3a1 ByteUtils to extension methods 2026-01-18 16:45:47 +01:00
b68b3d1c25 Switched to 1d array CollectSyncedData 2026-01-17 19:25:45 +01:00
3642006bb2 Fixed bugs 2026-01-17 16:37:23 +01:00
31 changed files with 3787 additions and 1855 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -82,12 +82,12 @@ namespace Marro.PacManUdon
this.active = active;
}
public override void AppendSyncedData(byte[][] data, ref int index, NetworkEventType eventType)
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
}
public override bool SetSyncedData(byte[] data, ref int index, NetworkEventType eventType)
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
return true;
}

161
Assets/Scripts/ByteUtils.cs Normal file
View File

@@ -0,0 +1,161 @@
using System;
using UnityEngine;
namespace Marro.PacManUdon
{
public static class ByteUtils
{
public static void Append(this byte[] target, byte[] value, ref int index)
{
//Debug.Log($"ByteUtils Append {nameof(value)}.Length: {value.Length}, {nameof(target)}.Length : {target.Length}, {nameof(index)}: {index}");
Array.Copy(value, 0, target, index, value.Length);
index += value.Length;
}
public static void Append(this byte[] target, byte value, ref int index) =>
target[index++] = value;
public static void Append(this byte[] target, sbyte value, ref int index) =>
target[index++] = (byte)value;
public static void Append(this byte[] target, bool value, ref int index) =>
target[index++] = value ? (byte)1 : (byte)0;
public static void Append(this byte[] target, ushort value, ref int index) =>
target.Append(BitConverter.GetBytes(value), ref index);
public static void Append(this byte[] target, short value, ref int index) =>
target.Append(BitConverter.GetBytes(value), ref index);
public static void Append(this byte[] target, uint value, ref int index) =>
target.Append(BitConverter.GetBytes(value), ref index);
public static void Append(this byte[] target, int value, ref int index) =>
target.Append(BitConverter.GetBytes(value), ref index);
/// <summary>
/// Casts <paramref name="value"/> to a byte and then appends it.
/// Safer than doing <c>Append((byte)value, ref index)</c>, which can crash the Udonbehaviour.
/// </summary>
public static void AppendAsByte(this byte[] target, int value, ref int index) =>
target.Append(value.ToByte(), ref index);
public static void Append(this byte[] target, ulong value, ref int index) =>
target.Append(BitConverter.GetBytes(value), ref index);
public static void Append(this byte[] target, long value, ref int index) =>
target.Append(BitConverter.GetBytes(value), ref index);
public static void Append(this byte[] target, float value, ref int index) =>
target.Append(BitConverter.GetBytes(value), ref index);
public static void Append(this byte[] target, double value, ref int index) =>
target.Append(BitConverter.GetBytes(value), ref index);
public static void Append(this byte[] target, char value, ref int index) =>
target.Append(BitConverter.GetBytes(value), ref index);
public static void Append(this byte[] target, Vector2 value, ref int index)
{
target.Append(value.x, ref index);
target.Append(value.y, ref index);
}
public static void Append(this byte[] target, Vector3 value, ref int index)
{
target.Append(value.x, ref index);
target.Append(value.y, ref index);
target.Append(value.z, ref index);
}
public static byte ReadByte(this byte[] source, ref int index) =>
source[index++];
public static bool ReadBool(this byte[] source, ref int index) =>
source[index++] > 0;
public static ushort ReadUShort(this byte[] source, ref int index)
{
var value = BitConverter.ToUInt16(source, index);
index += 2;
return value;
}
public static short ReadShort(this byte[] source, ref int index)
{
var value = BitConverter.ToInt16(source, (int)index);
index += 2;
return value;
}
public static uint ReadUInt(this byte[] source, ref int index)
{
var value = BitConverter.ToUInt32(source, index);
index += 4;
return value;
}
public static int ReadInt(this byte[] source, ref int index)
{
var value = BitConverter.ToInt32(source, index);
index += 4;
return value;
}
public static ulong ReadULong(this byte[] source, ref int index)
{
var value = BitConverter.ToUInt64(source, index);
index += 8;
return value;
}
public static long ReadLong(this byte[] source, ref int index)
{
var value = BitConverter.ToInt64(source, index);
index += 8;
return value;
}
public static float ReadFloat(this byte[] source, ref int index)
{
var value = BitConverter.ToSingle(source, index);
index += 4;
return value;
}
public static double ReadDouble(this byte[] source, ref int index)
{
var value = BitConverter.ToDouble(source, index);
index += 8;
return value;
}
public static char ReadChar(this byte[] source, ref int index)
{
var value = BitConverter.ToChar(source, index);
index += 2;
return value;
}
public static Vector2 ReadVector2(this byte[] source, ref int index)
{
var value = new Vector2(BitConverter.ToSingle(source, index), BitConverter.ToSingle(source, index + 4));
index += 8;
return value;
}
public static Vector3 ReadVector3(this byte[] source, ref int index)
{
var value = new Vector3(BitConverter.ToSingle(source, index), BitConverter.ToSingle(source, index + 4), BitConverter.ToSingle(source, index + 8));
index += 12;
return value;
}
/// <summary>
/// Casts an Int32 to a byte.
/// Doing this inline sometimes causes an udon exception, but doing it via a separate method seems to work fine.
/// </summary>
public static byte ToByte(this int value) =>
(byte)value;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7d2126e683a87e241ad0399cefcda807
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -43,7 +43,7 @@ MonoBehaviour:
Data:
- Name:
Entry: 12
Data: 37
Data: 34
- Name:
Entry: 7
Data:
@@ -1423,79 +1423,16 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: pelletCountOverride
Data: maze
- Name: $v
Entry: 7
Data: 86|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: pelletCountOverride
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
- Name: <SystemType>k__BackingField
Entry: 9
Data: 15
- 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: 87|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 2
- Name:
Entry: 7
Data: 88|UnityEngine.TooltipAttribute, UnityEngine.CoreModule
- Name: tooltip
Entry: 1
Data: Override amount of pellets needed to clear stage, set to -1 to disable.
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: 89|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: maze
- Name: $v
Entry: 7
Data: 90|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: maze
- Name: <UserType>k__BackingField
Entry: 7
Data: 91|System.RuntimeType, mscorlib
Data: 87|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.Maze, Assembly-CSharp
@@ -1519,7 +1456,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 92|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 88|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1543,13 +1480,13 @@ MonoBehaviour:
Data: intermission2Pole
- Name: $v
Entry: 7
Data: 93|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 89|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: intermission2Pole
- Name: <UserType>k__BackingField
Entry: 7
Data: 94|System.RuntimeType, mscorlib
Data: 90|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.Intermission2Pole, Assembly-CSharp
@@ -1573,7 +1510,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 95|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 91|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1597,7 +1534,7 @@ MonoBehaviour:
Data: mazeSpriteAnimator
- Name: $v
Entry: 7
Data: 96|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 92|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: mazeSpriteAnimator
@@ -1621,7 +1558,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 97|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 93|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1642,19 +1579,25 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: pelletCountTotal
Data: attractScreenElements
- Name: $v
Entry: 7
Data: 98|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 94|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: pelletCountTotal
Data: attractScreenElements
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
Entry: 7
Data: 95|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.GameObject[], UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 15
Data: 95
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1669,7 +1612,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 99|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 96|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1690,16 +1633,70 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: pelletCountRemaining
Data: intermissionScreenElements
- Name: $v
Entry: 7
Data: 100|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 97|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: pelletCountRemaining
Data: intermissionScreenElements
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
Data: 95
- Name: <SystemType>k__BackingField
Entry: 9
Data: 95
- 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: 98|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: gameState
- Name: $v
Entry: 7
Data: 99|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: gameState
- Name: <UserType>k__BackingField
Entry: 7
Data: 100|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.PacManGameState, Assembly-CSharp
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 15
@@ -1739,25 +1736,19 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: attractScreenElements
Data: score
- Name: $v
Entry: 7
Data: 102|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: attractScreenElements
Data: score
- Name: <UserType>k__BackingField
Entry: 7
Data: 103|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.GameObject[], UnityEngine.CoreModule
- Name:
Entry: 8
Data:
Entry: 9
Data: 15
- Name: <SystemType>k__BackingField
Entry: 9
Data: 103
Data: 15
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1772,7 +1763,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 104|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
Data: 103|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib
- Name:
Entry: 12
@@ -1794,19 +1785,19 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: intermissionScreenElements
Data: level
- Name: $v
Entry: 7
Data: 105|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 104|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: intermissionScreenElements
Data: level
- Name: <UserType>k__BackingField
Entry: 9
Data: 103
Data: 15
- Name: <SystemType>k__BackingField
Entry: 9
Data: 103
Data: 15
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1821,7 +1812,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 106|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
Data: 105|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib
- Name:
Entry: 12
@@ -1843,22 +1834,65 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: gameState
Data: highScore
- Name: $v
Entry: 7
Data: 107|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 106|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: gameState
Data: highScore
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
- Name: <SystemType>k__BackingField
Entry: 9
Data: 15
- Name: <SyncMode>k__BackingField
Entry: 7
Data: 108|System.RuntimeType, mscorlib
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.PacManGameState, Assembly-CSharp
Entry: 6
Data:
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 107|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: extraLives
- Name: $v
Entry: 7
Data: 108|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: extraLives
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
- Name: <SystemType>k__BackingField
Entry: 9
Data: 15
@@ -1893,250 +1927,6 @@ MonoBehaviour:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: score
- Name: $v
Entry: 7
Data: 110|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: score
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
- Name: <SystemType>k__BackingField
Entry: 9
Data: 15
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 3
Data: 1
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 111|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib
- Name:
Entry: 12
Data: 2
- Name:
Entry: 7
Data: 112|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: 113|UdonSharp.FieldChangeCallbackAttribute, UdonSharp.Runtime
- 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: level
- Name: $v
Entry: 7
Data: 114|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: level
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
- Name: <SystemType>k__BackingField
Entry: 9
Data: 15
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 3
Data: 1
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 115|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib
- Name:
Entry: 12
Data: 2
- Name:
Entry: 7
Data: 116|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: 117|UdonSharp.FieldChangeCallbackAttribute, UdonSharp.Runtime
- 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: highScore
- Name: $v
Entry: 7
Data: 118|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: highScore
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
- Name: <SystemType>k__BackingField
Entry: 9
Data: 15
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 3
Data: 1
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 119|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib
- Name:
Entry: 12
Data: 2
- Name:
Entry: 7
Data: 120|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: 121|UdonSharp.FieldChangeCallbackAttribute, UdonSharp.Runtime
- 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: extraLives
- Name: $v
Entry: 7
Data: 122|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: extraLives
- Name: <UserType>k__BackingField
Entry: 9
Data: 15
- Name: <SystemType>k__BackingField
Entry: 9
Data: 15
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 3
Data: 1
- Name:
Entry: 8
Data:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 123|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib
- Name:
Entry: 12
Data: 2
- Name:
Entry: 7
Data: 124|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: 125|UdonSharp.FieldChangeCallbackAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 8
Data:
- Name:
Entry: 13
Data:

View File

@@ -22,27 +22,22 @@ namespace Marro.PacManUdon
[SerializeField] private GameObject recorder;
[Header("Game settings")]
[SerializeField] private int startingExtraLives = 3;
[SerializeField] private int scoreToExtraLife = 10000;
[Tooltip("Override amount of pellets needed to clear stage, set to -1 to disable.")]
[SerializeField] private int pelletCountOverride = -1;
private Maze maze;
private Intermission2Pole intermission2Pole;
private Animator mazeSpriteAnimator;
private int pelletCountTotal;
private int pelletCountRemaining;
private GameObject[] attractScreenElements;
private GameObject[] intermissionScreenElements;
private PacManGameState gameState;
[UdonSynced, FieldChangeCallback(nameof(Score))] private int score;
[UdonSynced, FieldChangeCallback(nameof(Level))] private int level;
[UdonSynced, FieldChangeCallback(nameof(HighScore))] private int highScore;
[UdonSynced, FieldChangeCallback(nameof(ExtraLives))] private int extraLives;
private int score;
private int level;
private int highScore;
private int extraLives;
public void Start()
{
@@ -63,7 +58,7 @@ namespace Marro.PacManUdon
intermission2Pole = intermissionScreenElements[4].GetComponent<Intermission2Pole>();
networkManager.Initialize();
ghostManager.Initialize(maze.ghostStarts, maze.ghostTargets, pacMan, this);
ghostManager.Initialize(maze.ghostStarts, maze.ghostTargets, pacMan, pelletManager, this);
pacMan.Initialize(playerInput, maze.pacManStart, this);
bonusFruit.Initialize();
pelletManager.Initialize();
@@ -138,27 +133,20 @@ namespace Marro.PacManUdon
{
Debug.Log($"{gameObject} New level started!");
pelletCountTotal = pelletManager.PelletCount;
pelletCountRemaining = pelletCountTotal;
ghostManager.SetPelletsRemaining(pelletCountRemaining);
ghostManager.NewLevel();
pelletManager.RestoreAllPellets();
if (pelletCountOverride > 0)
{
pelletCountRemaining = pelletCountOverride;
}
ghostManager.NewLevel();
mazeSpriteAnimator.SetBool("Blinking", false);
}
private void RestartLevel()
private void RestartLevel(bool afterLifeLost = false)
{
Debug.Log($"{gameObject} (Re)started level!");
// SetInGameComponentVisibility(true);
ghostManager.Reset();
ghostManager.RestartLevel(afterLifeLost);
pacMan.Reset();
bonusFruit.Despawn();
soundManager.Reset();
@@ -172,29 +160,31 @@ namespace Marro.PacManUdon
SetFrozen(true);
}
public void GotPellet(bool addScore = true)
public void GotPellet(Pellet pellet, bool addScore = true)
{
pelletCountRemaining--;
var pelletCollectedCount = pelletManager.PelletCollected(pellet);
if (addScore) AddScore(10);
ghostManager.PelletConsumed();
soundManager.PlayPelletSound();
var pelletCountRemaining = pelletManager.PelletCount - pelletCollectedCount;
soundManager.UpdatePelletCount(pelletCountRemaining);
int pelletsConsumed = pelletCountTotal - pelletCountRemaining;
if (pelletCountRemaining <= 0)
{
StartTimeSequence(PacManTimeSequence.BoardClear);
}
else if (pelletsConsumed == 70 || pelletsConsumed == 170)
else if (pelletCollectedCount == 70 || pelletCollectedCount == 170)
{
bonusFruit.Spawn();
}
}
public void GotPowerPellet()
public void GotPowerPellet(Pellet pellet)
{
Debug.Log($"{gameObject} GotPowerPellet");
@@ -203,7 +193,7 @@ namespace Marro.PacManUdon
TimeSequenceSkipToNextStep();
return;
}
GotPellet(addScore: false);
GotPellet(pellet, addScore: false);
AddScore(50);
ghostManager.SetPowerPellet(true);
pacMan.SetPowerPellet(true);
@@ -240,7 +230,8 @@ namespace Marro.PacManUdon
public void PacManCaught()
{
//StartTimeSequence(PacManTimeSequence.PacManCaught);
return;
StartTimeSequence(PacManTimeSequence.PacManCaught);
}
public void NoGhostsScared()
@@ -403,7 +394,7 @@ namespace Marro.PacManUdon
}
}
public override void AppendSyncedData(byte[][] data, ref int offset, NetworkEventType eventType)
public override void CollectSyncedData(byte[] data, ref int offset, NetworkEventType eventType)
{
//data[offset++] = new byte[] { NetworkManager.Int32ToByte((int)gameState) };
//data[offset++] = BitConverter.GetBytes(currentlyInTimeSequence);
@@ -411,7 +402,7 @@ namespace Marro.PacManUdon
//data[offset++] = BitConverter.GetBytes(timeSequenceSecondsPassed);
}
public override bool SetSyncedData(byte[] data, ref int offset, NetworkEventType eventType)
public override bool WriteSyncedData(byte[] data, ref int offset, NetworkEventType eventType)
{
if (eventType == NetworkEventType.StartGameButtonPressed)
{
@@ -429,58 +420,8 @@ namespace Marro.PacManUdon
return true;
}
public int ExtraLives
{
set
{
SetExtraLives(value);
}
get => extraLives;
}
public PacManGameState GameState => gameState;
public PacManGameState GameState
{
set
{
SetGameState(value);
}
get => gameState;
}
public bool GhostsScared
{
set
{
}
get => GhostsScared;
}
public int Score
{
set
{
SetScore(value);
}
get => score;
}
public int HighScore
{
set
{
SetHighScore(value);
}
get => score;
}
public int Level
{
set
{
SetLevel(value);
}
get => level;
}
public int Level => level;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -32,11 +32,14 @@ namespace Marro.PacManUdon
TargetingIdlePosition2
}
[RequireComponent(typeof(Renderer))]
[RequireComponent(typeof(Animator))]
public class Ghost : GridMover
{
[SerializeField] private PacManGhostType ghostType;
[SerializeField] private PacManGhostStartState startState;
// External references
private GhostManager ghostManager;
private Animator animator;
private new Renderer renderer;
@@ -52,33 +55,40 @@ namespace Marro.PacManUdon
private Vector2 idlePosition2;
private Vector2 cornerPosition;
private bool kinematic;
// Pathfinding
private Vector2 target;
private bool horizontalOnly;
private int housePelletCounterLimit;
private bool inTunnel;
private int rngState;
private bool turnAroundSoon;
private float speed;
// State
private PacManGhostState ghostState;
private bool isScared;
private bool scattering;
private PacManGhostFrozenState frozenState;
// Home
private bool offGrid;
private int housePelletCounter;
private bool housePelletCounterActive;
private int housePelletCounterLimit;
private bool faceInStartingDirectionUntilUnfrozen;
// Cutscene
private bool kinematic;
private bool specialLook;
private bool followingPredefinedPath;
private Vector2[] predefinedPath;
private int predefinedPathIndex;
int rngState;
private float speed;
private Vector2 target;
private bool offGrid;
private bool inTunnel;
private PacManGhostState ghostState;
private bool isScared;
private bool scattering;
private PacManGhostFrozenState frozenState;
private bool hideUntilUnfrozen;
private int housePelletCounter;
private bool housePelletCounterActive;
private bool turnAroundSoon;
public bool IsScared => isScared;
public int Index { get; private set; }
public void Initialize(PacMan pacMan, Ghost blinky, Transform startTransform, Vector2 homePosition, Vector2 idlePosition1, Vector2 idlePosition2, Vector2 cornerPosition)
public void Initialize(PacMan pacMan, Ghost blinky, Transform startTransform, Vector2 homePosition, Vector2 idlePosition1, Vector2 idlePosition2, Vector2 cornerPosition, int index)
{
ghostManager = transform.parent.GetComponent<GhostManager>();
animator = GetComponent<Animator>();
@@ -97,6 +107,8 @@ namespace Marro.PacManUdon
startRotation = startTransform.localRotation;
frozenState = PacManGhostFrozenState.Frozen;
Index = index;
}
public void Reset()
@@ -137,12 +149,8 @@ namespace Marro.PacManUdon
public override void SyncedUpdate()
{
if (ghostType == PacManGhostType.Blinky)
{
// ghostManager.gameStateManager.statusDisplay.SetDebugText(2, $"{turnAroundSoon}");
}
if (frozenState == PacManGhostFrozenState.Frozen ||
(frozenState == PacManGhostFrozenState.FrozenIfNotCaught && ((ghostState != PacManGhostState.Returning && ghostState != PacManGhostState.Entering) || hideUntilUnfrozen)))
(frozenState == PacManGhostFrozenState.FrozenIfNotCaught && ghostState != PacManGhostState.Returning && ghostState != PacManGhostState.Entering))
{
return;
}
@@ -155,14 +163,15 @@ namespace Marro.PacManUdon
SetPosition(nextPosition);
}
private Vector2 ProcessNextPosition(Vector2 position, Vector2 nextPosition)
private Vector2 ProcessNextPosition(Vector2 position, Vector2 nextPosition)
{
if (turnAroundSoon && ghostState == PacManGhostState.Normal
&& GridMoverTools.CrossesTileBorder(position, nextPosition, direction.x != 0, direction.y != 0))
{
// Debug.Log($"{gameObject} turned around");
SetDirection(direction * -1);
Debug.Log($"{gameObject} turned around to direction {GetDirection()}");
turnAroundSoon = false;
return nextPosition;
}
if (kinematic)
@@ -224,6 +233,12 @@ namespace Marro.PacManUdon
// Debug.Log($"{gameObject} crossed tile center {gridPosition}, new target: {target}, new direction: {direction}");
}
var distance = Vector2.Distance(position, nextPosition);
if (distance > 0.5f)
{
Debug.LogError($"{gameObject} Just jumped by distance {distance}! position: {position}, nextPosition: {nextPosition}, direction: {direction}, offGrid: {offGrid}, ghostState: {ghostState}");
}
return nextPosition;
}
@@ -642,7 +657,7 @@ namespace Marro.PacManUdon
if (reverseDirection && this.scattering != scattering)
{
if (ghostState == PacManGhostState.Normal || ghostState == PacManGhostState.Home || ghostState == PacManGhostState.Exiting
// This is afaik not normal PacMan behaviour, but is needed to accomidate slight timing differences
// This is afaik not normal PacMan behaviour, but is needed to accomidate slight timing differences during the demo
|| ghostState == PacManGhostState.Entering && ghostManager.gameController.GameState == PacManGameState.AttractModeDemo
)
{
@@ -755,14 +770,69 @@ namespace Marro.PacManUdon
return ghostState;
}
public bool IsScared => isScared;
public void SetSpeed(float speed)
{
this.speed = speed;
UpdateAnimator();
}
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
if (eventType != NetworkEventType.GhostUpdate)
{
return;
}
data.Append(target, ref index);
data.Append(horizontalOnly, ref index);
data.Append(inTunnel, ref index);
data.Append(rngState, ref index);
data.Append(turnAroundSoon, ref index);
data.Append(speed, ref index);
data.AppendAsByte((int)ghostState, ref index);
data.Append(isScared, ref index);
data.Append(scattering, ref index);
data.AppendAsByte((int)frozenState, ref index);
data.Append(offGrid, ref index);
data.AppendAsByte(housePelletCounter, ref index);
data.Append(housePelletCounterActive, ref index);
data.AppendAsByte(housePelletCounterLimit, ref index);
data.Append(faceInStartingDirectionUntilUnfrozen, ref index);
base.CollectSyncedData(data, ref index, eventType);
}
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
if (eventType != NetworkEventType.GhostUpdate)
{
return true;
}
target = data.ReadVector2(ref index);
horizontalOnly = data.ReadBool(ref index);
inTunnel = data.ReadBool(ref index);
rngState = data.ReadInt(ref index);
turnAroundSoon = data.ReadBool(ref index);
Debug.Log($"{gameObject} turnAroundSoon = {turnAroundSoon}");
speed = data.ReadFloat(ref index);
ghostState = (PacManGhostState)data.ReadByte(ref index);
isScared = data.ReadBool(ref index);
scattering = data.ReadBool(ref index);
frozenState = (PacManGhostFrozenState)data.ReadByte(ref index);
offGrid = data.ReadBool(ref index);
housePelletCounter = data.ReadByte(ref index);
housePelletCounterActive = data.ReadBool(ref index);
housePelletCounterLimit = data.ReadByte(ref index);
faceInStartingDirectionUntilUnfrozen = data.ReadBool(ref index);
return base.WriteSyncedData(data, ref index, eventType);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.GetComponent<PacManGhostCollider>())
@@ -799,14 +869,5 @@ namespace Marro.PacManUdon
SetInTunnel(false);
}
}
PacManGhostState State
{
set
{
SetState(value);
}
get => ghostState;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -7,9 +7,12 @@ namespace Marro.PacManUdon
public class GhostManager : SyncedObject
{
[NonSerialized] public GameManager gameController;
private Ghost[] ghosts;
private Ghost blinky;
private PelletManager pelletManager;
// Level constants
private float speedDefault;
private float speedScared;
@@ -21,9 +24,12 @@ namespace Marro.PacManUdon
private int elroy1PelletCount;
private int elroy2PelletCount;
private float powerPelletDuration;
private float[] scatterPattern;
private float pelletTimeoutLimit;
// Power Pellet logic
private bool powerPelletActive;
private float powerPelletDuration;
private float powerPelletCountdown;
private int powerPelletMultiplier;
@@ -37,27 +43,25 @@ namespace Marro.PacManUdon
// Scattering logic
private float scatterCounter;
private float[] scatterPattern;
private int scatterPatternIndex;
// Elroy logic
public int elroyLevel;
private int pelletsRemaining;
// Ghost house logic
private bool sharedPelletCounterActive;
private int sharedPelletCounter;
private readonly int[] sharedPelletCounterReleaseValues = { 0, 7, 17, 32 };
private float pelletTimeout;
private float pelletTimeoutLimit;
private bool frozen;
private bool kinematic;
// This should be called once when the game is initialized
public void Initialize(Transform[] ghostStarts, Transform[] ghostTargets, PacMan pacMan, GameManager gameController)
public void Initialize(Transform[] ghostStarts, Transform[] ghostTargets, PacMan pacMan, PelletManager pelletManager, GameManager gameController)
{
this.gameController = gameController;
this.pelletManager = pelletManager;
ghosts = transform.GetComponentsInChildren<Ghost>(true);
blinky = ghosts[0];
for (int ghostIndex = 0; ghostIndex < ghosts.Length; ghostIndex++)
@@ -68,12 +72,11 @@ namespace Marro.PacManUdon
Vector2 idlePosition2 = ghostTargets[2 + ghostIndex * 3].localPosition;
Vector2 cornerPosition = ghostTargets[3 + ghostIndex * 3].localPosition;
ghosts[ghostIndex].Initialize(pacMan, blinky, startTransform, homePosition, idlePosition1, idlePosition2, cornerPosition);
ghosts[ghostIndex].Initialize(pacMan, blinky, startTransform, homePosition, idlePosition1, idlePosition2, cornerPosition, ghostIndex);
}
}
// This should be called every time the level is reset
public void Reset()
public void RestartLevel(bool afterLifeLost = false)
{
ghostScaredQueue = new DataList();
powerPelletActive = false;
@@ -84,6 +87,11 @@ namespace Marro.PacManUdon
elroyLevel = 0;
kinematic = false;
if (afterLifeLost)
{
SetSharedPelletCounterActive(true);
}
foreach (Ghost ghost in ghosts)
{
ghost.Reset();
@@ -95,20 +103,15 @@ namespace Marro.PacManUdon
public void NewLevel()
{
SetSharedPelletCounterActive(false);
UpdateElroyLevel();
foreach (Ghost ghost in ghosts)
{
ghost.ResetHousePelletCounter();
}
}
public void LifeLost()
{
SetSharedPelletCounterActive(true);
}
public override void SyncedUpdate()
{
// gameStateManager.statusDisplay.SetDebugText(1, this.blinkCountdown.ToString());
if (frozen || kinematic)
{
return;
@@ -188,7 +191,10 @@ namespace Marro.PacManUdon
gameController.GhostCaught(0);
return;
}
// Debug.Log($"{gameObject} GhostCaughtQueue with ghost {ghost}");
//networkManager.SendEventSoon(NetworkEventType.GhostUpdate);
ghostScaredQueue.Add(ghost);
GhostCaughtExecute(ghost);
}
@@ -310,6 +316,18 @@ namespace Marro.PacManUdon
public void SetLevel(int level)
{
Debug.Log($"GhostManager: SetLevel {level}");
SetLevelConstants(level);
int[] privatePelletCounterReleaseValues = PacManConstants.GetGhostHousePrivatePelletCounterLimitForLevel(level);
for (int i = 0; i < ghosts.Length; i++)
{
ghosts[i].SetHousePelletCounterLimit(privatePelletCounterReleaseValues[i]);
RestartLevel(); // Reset needed to properly apply level
}
}
private void SetLevelConstants(int level)
{
speedDefault = PacManConstants.GetGhostDefaultSpeedForLevel(level);
speedScared = PacManConstants.GetGhostScaredSpeedForLevel(level);
speedReturn = 15f;
@@ -322,13 +340,6 @@ namespace Marro.PacManUdon
powerPelletDuration = PacManConstants.GetScaredDurationForLevel(level);
scatterPattern = PacManConstants.GetScatterPatternForLevel(level);
pelletTimeoutLimit = PacManConstants.GetGhostHousePelletTimeoutLimitForLevel(level);
int[] privatePelletCounterReleaseValues = PacManConstants.GetGhostHousePrivatePelletCounterLimitForLevel(level);
for (int i = 0; i < ghosts.Length; i++)
{
ghosts[i].SetHousePelletCounterLimit(privatePelletCounterReleaseValues[i]);
Reset(); // Reset needed to properly apply level
}
}
public float GetTargetSpeed(Ghost ghost, PacManGhostState ghostState, bool isScared, bool inTunnel)
@@ -368,7 +379,7 @@ namespace Marro.PacManUdon
Debug.Log($"{gameObject} SetScattering: {scattering}");
foreach (Ghost ghost in ghosts)
{
if (ghost == blinky && pelletsRemaining <= elroy1PelletCount)
if (ghost == blinky && elroyLevel > 0) // Once blinky is elroy he no longer scatters
{
continue;
}
@@ -376,15 +387,13 @@ namespace Marro.PacManUdon
}
}
public void SetPelletsRemaining(int pelletsRemaining)
{
this.pelletsRemaining = pelletsRemaining;
UpdateElroyLevel();
}
/// <summary>
/// Whether to use the shared pellet counter for ghost exiting.
/// Should be called before ghosts are reset.
/// </summary>
void SetSharedPelletCounterActive(bool active)
{
// Debug.Log($"{gameObject} SetSharedPelletCounterActive {active}");
Debug.Log($"{gameObject} SetSharedPelletCounterActive {active}");
sharedPelletCounterActive = active;
foreach (Ghost ghost in ghosts)
{
@@ -394,10 +403,10 @@ namespace Marro.PacManUdon
public void PelletConsumed()
{
SetPelletsRemaining(pelletsRemaining - 1);
pelletTimeout = 0;
UpdateElroyLevel();
if (sharedPelletCounterActive)
{
IncrementSharedPelletCounter();
@@ -411,6 +420,7 @@ namespace Marro.PacManUdon
void IncrementSharedPelletCounter()
{
sharedPelletCounter++;
//Debug.Log($"Incremented shared pellet counter to {sharedPelletCounter}");
for (int ghostIndex = 0; ghostIndex < sharedPelletCounterReleaseValues.Length; ghostIndex++)
{
Ghost ghost = ghosts[ghostIndex];
@@ -442,10 +452,13 @@ namespace Marro.PacManUdon
void UpdateElroyLevel()
{
// Debug.Log($"{gameObject} Updating Elroy Level with pelletsRemaining {pelletsRemaining} with elroy2PelletCount {elroy2PelletCount} and elroy1PelletCount {elroy1PelletCount}");
int oldElroyLevel = elroyLevel;
var oldElroyLevel = elroyLevel;
var pelletsRemaining = pelletManager.PelletCount - pelletManager.PelletCollectedCount;
if (pelletsRemaining < elroy2PelletCount) elroyLevel = 2;
else if (pelletsRemaining < elroy1PelletCount) elroyLevel = 1;
else elroyLevel = 0;
if (elroyLevel != oldElroyLevel)
{
blinky.SetElroy(elroyLevel);
@@ -470,13 +483,103 @@ namespace Marro.PacManUdon
}
}
public override void AppendSyncedData(byte[][] data, ref int index, NetworkEventType eventType)
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
if (eventType != NetworkEventType.GhostUpdate)
{
return;
}
// Power Pellet logic
data.Append(powerPelletActive, ref index);
data.Append(powerPelletCountdown, ref index);
data.AppendAsByte(powerPelletMultiplier, ref index);
// Blink logic
data.Append(blinkingActivated, ref index);
data.Append(blinkCountdown, ref index);
data.Append(blinkCurrentlyWhite, ref index);
// Scattering logic
data.Append(scatterCounter, ref index);
data.AppendAsByte(scatterPatternIndex, ref index);
// Elroy logic
data.AppendAsByte(elroyLevel, ref index);
// Ghost house logic
data.Append(sharedPelletCounterActive, ref index);
data.AppendAsByte(sharedPelletCounter, ref index);
data.Append(pelletTimeout, ref index);
data.Append(frozen, ref index);
data.Append(kinematic, ref index);
data.AppendAsByte(gameController.Level, ref index);
var ghostScaredQueueArray = new byte[ghosts.Length];
for (int i = 0; i < ghostScaredQueueArray.Length; i++)
{
var add = ghostScaredQueue.TryGetValue(i, out var ghost);
if (!add)
{
ghostScaredQueueArray[i] = byte.MaxValue; // Add a terminator
break;
}
ghostScaredQueueArray[i] = (byte)((Ghost)ghost.Reference).Index;
}
Debug.Log($"{gameObject} Sent a ghostScareQueue of length {ghostScaredQueue.Count}");
data.Append(ghostScaredQueueArray, ref index);
}
public override bool SetSyncedData(byte[] data, ref int index, NetworkEventType eventType)
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
if (eventType != NetworkEventType.GhostUpdate)
{
return true;
}
// Power Pellet logic
powerPelletActive = data.ReadBool(ref index);
powerPelletCountdown = data.ReadFloat(ref index);
powerPelletMultiplier = data.ReadByte(ref index);
// Blink logic
blinkingActivated = data.ReadBool(ref index);
blinkCountdown = data.ReadFloat(ref index);
blinkCurrentlyWhite = data.ReadBool(ref index);
// Scattering logic
scatterCounter = data.ReadFloat(ref index);
scatterPatternIndex = data.ReadByte(ref index);
// Elroy logic
elroyLevel = data.ReadByte(ref index);
// Ghost house logic
sharedPelletCounterActive = data.ReadBool(ref index);
sharedPelletCounter = data.ReadByte(ref index);
pelletTimeout = data.ReadFloat(ref index);
frozen = data.ReadBool(ref index);
kinematic = data.ReadBool(ref index);
var level = data.ReadByte(ref index);
SetLevelConstants(level);
ghostScaredQueue.Clear();
for (int i = 0; i < ghosts.Length; i++)
{
var ghostIndex = data[index + i];
if (ghostIndex > ghosts.Length) // Reached terminator
{
break;
}
ghostScaredQueue.Add(ghosts[ghostIndex]);
}
index += ghosts.Length;
Debug.Log($"{gameObject} Read back a ghostScareQueue of length {ghostScaredQueue.Count}");
return true;
}

View File

@@ -30,32 +30,16 @@ namespace Marro.PacManUdon
protected abstract void UpdateAnimator();
public override void AppendSyncedData(byte[][] data, ref int offset, NetworkEventType eventType)
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
if (eventType != NetworkEventType.PacManTurn)
{
return;
}
var position = GetPosition();
data[offset++] = BitConverter.GetBytes(position.x);
data[offset++] = BitConverter.GetBytes(position.y);
var direction = GetDirection();
data[offset++] = BitConverter.GetBytes(direction.x);
data[offset++] = BitConverter.GetBytes(direction.y);
data.Append(GetPosition(), ref index);
data.Append(GetDirection(), ref index);
}
public override bool SetSyncedData(byte[] data, ref int offset, NetworkEventType eventType)
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
if (eventType != NetworkEventType.PacManTurn)
{
return true;
}
SetPosition(new Vector2(BitConverter.ToSingle(data, offset), BitConverter.ToSingle(data, offset + 4)));
SetDirection(new Vector2(BitConverter.ToSingle(data, offset + 8), BitConverter.ToSingle(data, offset + 12)));
offset += 16;
SetPosition(data.ReadVector2(ref index));
SetDirection(data.ReadVector2(ref index));
return true;
}

View File

@@ -2,6 +2,7 @@
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;
using static Cinemachine.DocumentationSortingAttribute;
namespace Marro.PacManUdon
{
@@ -34,6 +35,7 @@ namespace Marro.PacManUdon
_ghost = ghost;
_gameManager = gameManager;
_animator = GetComponent<Animator>();
SetActive(false); // Should only activate for intermission 2
Reset();
}
@@ -41,11 +43,11 @@ namespace Marro.PacManUdon
{
_lastUpdate = PoleStrechLevels.None;
SetStrechLevel(PoleStrechLevels.None);
SetActive(false); // Should only activate for intermission 2
}
public void SetActive(bool isActive)
{
Debug.Log($"({nameof(PacManUdon)} {nameof(Intermission2Pole)}) SetActive {isActive}.");
gameObject.SetActive(isActive);
}
@@ -113,6 +115,7 @@ namespace Marro.PacManUdon
public void SetStrechLevel(PoleStrechLevels level)
{
Debug.Log($"({nameof(PacManUdon)} {nameof(Intermission2Pole)}) Set strech level to {level}.");
_animator.SetFloat("Strech", GetAnimatorValueForStrechLevel(level));
}
@@ -141,12 +144,12 @@ namespace Marro.PacManUdon
return (Vector2)transform.localPosition;
}
public override void AppendSyncedData(byte[][] data, ref int index, NetworkEventType eventType)
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
}
public override bool SetSyncedData(byte[] data, ref int index, NetworkEventType eventType)
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
return true;
}

View File

@@ -43,7 +43,7 @@ MonoBehaviour:
Data:
- Name:
Entry: 12
Data: 28
Data: 30
- Name:
Entry: 7
Data:
@@ -283,16 +283,70 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: syncedObjects
Data: updateRate
- Name: $v
Entry: 7
Data: 17|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: updateRate
- Name: <UserType>k__BackingField
Entry: 9
Data: 7
- Name: <SystemType>k__BackingField
Entry: 9
Data: 7
- 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: 18|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data: 19|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: syncedObjects
- Name: $v
Entry: 7
Data: 20|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: syncedObjects
- Name: <UserType>k__BackingField
Entry: 7
Data: 18|System.RuntimeType, mscorlib
Data: 21|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.SyncedObject[], Assembly-CSharp
@@ -301,7 +355,7 @@ MonoBehaviour:
Data:
- Name: <SystemType>k__BackingField
Entry: 7
Data: 19|System.RuntimeType, mscorlib
Data: 22|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.Component[], UnityEngine.CoreModule
@@ -322,7 +376,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 20|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 23|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -346,7 +400,7 @@ MonoBehaviour:
Data: offsetTime
- Name: $v
Entry: 7
Data: 21|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 24|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: offsetTime
@@ -370,7 +424,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 22|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 25|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -394,7 +448,7 @@ MonoBehaviour:
Data: internalTime
- Name: $v
Entry: 7
Data: 23|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 26|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: internalTime
@@ -418,7 +472,55 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 24|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 27|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: nextUpdateTime
- Name: $v
Entry: 7
Data: 28|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: nextUpdateTime
- Name: <UserType>k__BackingField
Entry: 9
Data: 7
- Name: <SystemType>k__BackingField
Entry: 9
Data: 7
- 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: 29|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -442,7 +544,7 @@ MonoBehaviour:
Data: nextEventTime
- Name: $v
Entry: 7
Data: 25|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 30|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: nextEventTime
@@ -464,108 +566,6 @@ MonoBehaviour:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 26|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: retriesWithoutSuccess
- Name: $v
Entry: 7
Data: 27|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: retriesWithoutSuccess
- 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: 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: hasFullSyncReady
- Name: $v
Entry: 7
Data: 29|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: hasFullSyncReady
- Name: <UserType>k__BackingField
Entry: 7
Data: 30|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Boolean, 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
@@ -589,19 +589,19 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: serializationRequested
Data: retriesWithoutSuccess
- Name: $v
Entry: 7
Data: 32|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: serializationRequested
Data: retriesWithoutSuccess
- Name: <UserType>k__BackingField
Entry: 9
Data: 30
Data: 11
- Name: <SystemType>k__BackingField
Entry: 9
Data: 30
Data: 11
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -637,16 +637,118 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: eventsToSend
Data: hasFullSyncReady
- Name: $v
Entry: 7
Data: 34|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: eventsToSend
Data: hasFullSyncReady
- Name: <UserType>k__BackingField
Entry: 7
Data: 35|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Boolean, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 35
- 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: 36|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: serializationRequested
- Name: $v
Entry: 7
Data: 37|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: serializationRequested
- Name: <UserType>k__BackingField
Entry: 9
Data: 35
- Name: <SystemType>k__BackingField
Entry: 9
Data: 35
- 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: 38|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: eventsToSend
- Name: $v
Entry: 7
Data: 39|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: eventsToSend
- Name: <UserType>k__BackingField
Entry: 7
Data: 40|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.NetworkEventType[], Assembly-CSharp
@@ -655,7 +757,7 @@ MonoBehaviour:
Data:
- Name: <SystemType>k__BackingField
Entry: 7
Data: 36|System.RuntimeType, mscorlib
Data: 41|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Int32[], mscorlib
@@ -676,7 +778,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 37|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 42|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -700,7 +802,7 @@ MonoBehaviour:
Data: eventsToSendIndex
- Name: $v
Entry: 7
Data: 38|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 43|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: eventsToSendIndex
@@ -724,7 +826,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 39|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 44|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -748,13 +850,13 @@ MonoBehaviour:
Data: eventsQueue
- Name: $v
Entry: 7
Data: 40|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 45|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: eventsQueue
- Name: <UserType>k__BackingField
Entry: 7
Data: 41|System.RuntimeType, mscorlib
Data: 46|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Byte[][], mscorlib
@@ -763,7 +865,7 @@ MonoBehaviour:
Data:
- Name: <SystemType>k__BackingField
Entry: 7
Data: 42|System.RuntimeType, mscorlib
Data: 47|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Object[], mscorlib
@@ -784,7 +886,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 43|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 48|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -808,7 +910,7 @@ MonoBehaviour:
Data: eventsQueueIndex
- Name: $v
Entry: 7
Data: 44|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 49|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: eventsQueueIndex
@@ -832,7 +934,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 45|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 50|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -856,7 +958,7 @@ MonoBehaviour:
Data: eventsQueueIndexAtLastTransmission
- Name: $v
Entry: 7
Data: 46|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 51|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: eventsQueueIndexAtLastTransmission
@@ -880,7 +982,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 47|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 52|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -904,16 +1006,16 @@ MonoBehaviour:
Data: eventTransmissionHistory
- Name: $v
Entry: 7
Data: 48|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 53|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: eventTransmissionHistory
- Name: <UserType>k__BackingField
Entry: 9
Data: 36
Data: 41
- Name: <SystemType>k__BackingField
Entry: 9
Data: 36
Data: 41
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -928,7 +1030,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 49|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 54|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -952,7 +1054,7 @@ MonoBehaviour:
Data: eventTransmissionHistoryIndex
- Name: $v
Entry: 7
Data: 50|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 55|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: eventTransmissionHistoryIndex
@@ -974,108 +1076,6 @@ MonoBehaviour:
- Name: <IsSerialized>k__BackingField
Entry: 5
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 51|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: lastEventTransmissionTime
- Name: $v
Entry: 7
Data: 52|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: lastEventTransmissionTime
- Name: <UserType>k__BackingField
Entry: 9
Data: 7
- Name: <SystemType>k__BackingField
Entry: 9
Data: 7
- 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: 53|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: 54|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: lastEventId
- Name: <UserType>k__BackingField
Entry: 7
Data: 55|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Byte, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 55
- 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: 56|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
@@ -1099,16 +1099,118 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: networkedData
Data: lastEventTransmissionTime
- Name: $v
Entry: 7
Data: 57|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: lastEventTransmissionTime
- Name: <UserType>k__BackingField
Entry: 9
Data: 7
- Name: <SystemType>k__BackingField
Entry: 9
Data: 7
- 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: 58|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: 59|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: lastEventId
- Name: <UserType>k__BackingField
Entry: 7
Data: 60|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Byte, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 60
- 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: 61|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: networkedData
- Name: $v
Entry: 7
Data: 62|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: networkedData
- Name: <UserType>k__BackingField
Entry: 7
Data: 58|System.RuntimeType, mscorlib
Data: 63|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Byte[], mscorlib
@@ -1117,7 +1219,7 @@ MonoBehaviour:
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 58
Data: 63
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1132,13 +1234,13 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 59|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 64|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data: 60|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime
Data: 65|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
@@ -1162,16 +1264,16 @@ MonoBehaviour:
Data: <Ready>k__BackingField
- Name: $v
Entry: 7
Data: 61|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 66|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: <Ready>k__BackingField
- Name: <UserType>k__BackingField
Entry: 9
Data: 30
Data: 35
- Name: <SystemType>k__BackingField
Entry: 9
Data: 30
Data: 35
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1186,7 +1288,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 62|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 67|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1210,16 +1312,16 @@ MonoBehaviour:
Data: <Synced>k__BackingField
- Name: $v
Entry: 7
Data: 63|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 68|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: <Synced>k__BackingField
- Name: <UserType>k__BackingField
Entry: 9
Data: 30
Data: 35
- Name: <SystemType>k__BackingField
Entry: 9
Data: 30
Data: 35
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1234,7 +1336,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 64|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 69|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1258,7 +1360,7 @@ MonoBehaviour:
Data: <SyncedTime>k__BackingField
- Name: $v
Entry: 7
Data: 65|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 70|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: <SyncedTime>k__BackingField
@@ -1282,7 +1384,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 66|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 71|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1306,7 +1408,7 @@ MonoBehaviour:
Data: <SyncedDeltaTime>k__BackingField
- Name: $v
Entry: 7
Data: 67|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 72|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: <SyncedDeltaTime>k__BackingField
@@ -1330,7 +1432,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 68|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 73|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1354,16 +1456,16 @@ MonoBehaviour:
Data: <IsEventUpdate>k__BackingField
- Name: $v
Entry: 7
Data: 69|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 74|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: <IsEventUpdate>k__BackingField
- Name: <UserType>k__BackingField
Entry: 9
Data: 30
Data: 35
- Name: <SystemType>k__BackingField
Entry: 9
Data: 30
Data: 35
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1378,7 +1480,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 70|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 75|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1402,16 +1504,16 @@ MonoBehaviour:
Data: <IsOwner>k__BackingField
- Name: $v
Entry: 7
Data: 71|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 76|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: <IsOwner>k__BackingField
- Name: <UserType>k__BackingField
Entry: 9
Data: 30
Data: 35
- Name: <SystemType>k__BackingField
Entry: 9
Data: 30
Data: 35
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1426,7 +1528,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 72|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 77|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -1450,13 +1552,13 @@ MonoBehaviour:
Data: DebugImageToIndicateOwner
- Name: $v
Entry: 7
Data: 73|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 78|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: DebugImageToIndicateOwner
- Name: <UserType>k__BackingField
Entry: 7
Data: 74|System.RuntimeType, mscorlib
Data: 79|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.Animator, UnityEngine.AnimationModule
@@ -1465,7 +1567,7 @@ MonoBehaviour:
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 74
Data: 79
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -1480,13 +1582,13 @@ MonoBehaviour:
Data: true
- Name: _fieldAttributes
Entry: 7
Data: 75|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 80|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data: 76|UnityEngine.SerializeField, UnityEngine.CoreModule
Data: 81|UnityEngine.SerializeField, UnityEngine.CoreModule
- Name:
Entry: 8
Data:

View File

@@ -15,6 +15,8 @@ namespace Marro.PacManUdon
FullSync = 1,
PacManTurn = 2,
StartGameButtonPressed = 3,
SyncPellets = 4,
GhostUpdate = 5,
}
public class NetworkManager : UdonSharpBehaviour
@@ -57,6 +59,10 @@ namespace Marro.PacManUdon
/// How long to wait since last message to send next ping.
/// </summary>
[SerializeField] private float pingDelay = 0.3f;
/// <summary>
/// The rate at which updates occur.
/// </summary>
[SerializeField] private float updateRate = 0.0166666667f;
#endregion
#region Constants
@@ -64,6 +70,10 @@ namespace Marro.PacManUdon
/// The maximum amount of events in the buffer.
/// </summary>
private const int BufferMaxTotalEvents = 255;
/// <summary>
/// The maximum amount of events in the buffer.
/// </summary>
private const int MaxEventSize = ushort.MaxValue;
/// <summary>
/// The index in an event where the event size is stored.
@@ -102,6 +112,10 @@ namespace Marro.PacManUdon
/// </summary>
private float internalTime;
/// <summary>
/// Time at which the latest update occured
/// </summary>
private float nextUpdateTime;
/// <summary>
/// Time at which next received event occured.
/// </summary>
@@ -206,16 +220,6 @@ namespace Marro.PacManUdon
#endregion
#region General
public void Awake()
{
// I would set the instance variable here, but it's somehow null by the time Initialize() is called... Udon moment?
var syncedObjects = root.GetComponentsInChildren<SyncedObject>(includeInactive: true);
foreach (var obj in syncedObjects)
{
obj.networkManager = this;
}
}
public void Initialize()
{
if (!BitConverter.IsLittleEndian)
@@ -225,8 +229,12 @@ namespace Marro.PacManUdon
return;
}
syncedObjects = root.GetComponentsInChildren<SyncedObject>(includeInactive: true);
if (root == null)
{
root = transform.parent.gameObject;
}
syncedObjects = root.GetComponentsInChildren<SyncedObject>(includeInactive: true);
foreach (var obj in syncedObjects)
{
obj.networkManager = this;
@@ -246,13 +254,19 @@ namespace Marro.PacManUdon
internalTime = 0;
SyncedTime = 0;
SyncedDeltaTime = Time.fixedDeltaTime;
nextUpdateTime = SyncedTime;
if (!Synced)
{
RequestEvent(NetworkEventType.FullSync); // See if we can sync up
}
Ready = true;
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Initialized, time offset: {offsetTime}");
}
public void FixedUpdate()
public void Update()
{
if (!Ready)
{
@@ -266,20 +280,21 @@ namespace Marro.PacManUdon
{
if (IsOwner)
{
ProcessEventsToSend(); // Prepare events from last cycle
ProgressPingTime(); // See if we need to send a ping
}
else
{
ProgressEventTime(); // See if there's events that need to be replayed
ApplyReceivedEvents(); // See if there's events that need to be replayed
}
}
// Forwards simulated time at the FixedUpdate pace
PerformFixedSyncedUpdate();
if (IsOwner)
// Forwards simulated time at the updateRate pace
while (nextUpdateTime <= internalTime)
{
ProcessEventsToSend();
ProgressSyncedTime(nextUpdateTime);
PerformFixedSyncedUpdate();
nextUpdateTime = SyncedTime + updateRate;
}
}
@@ -291,7 +306,6 @@ namespace Marro.PacManUdon
private void PerformFixedSyncedUpdate()
{
IsEventUpdate = false;
ProgressSyncedTime(internalTime);
for (int i = 0; i < syncedObjects.Length; i++)
{
@@ -396,36 +410,27 @@ namespace Marro.PacManUdon
var eventId = GetNextEventId(lastEventId);
InitializeEvent(eventType, timestamp, eventId, BufferMaxTotalEvents, out byte[][] data, out var index);
InitializeEvent(eventType, timestamp, eventId, out byte[] data, out var index);
foreach (var obj in syncedObjects)
{
obj.AppendSyncedData(data, ref index, eventType);
obj.CollectSyncedData(data, ref index, eventType);
}
var result = Flatten(data, 0, index);
// Validate and fill in event size
var eventSize = result.Length;
if (eventSize > ushort.MaxValue || eventSize < 0)
{
Debug.LogError($"({nameof(PacManUdon)} {nameof(NetworkManager)}) New event is too large or negative! Size is {eventSize}, maximum allowed is {ushort.MaxValue}");
HandleError(false);
return;
}
var eventSizeBytes = BitConverter.GetBytes((ushort)eventSize);
Array.Copy(eventSizeBytes, 0, result, HeaderEventSizeIndex, eventSizeBytes.Length);
var eventSizeBytes = BitConverter.GetBytes((ushort)index);
Array.Copy(eventSizeBytes, 0, data, HeaderEventSizeIndex, eventSizeBytes.Length);
if (IsFullSync(eventType))
{
hasFullSyncReady = true;
}
QueueEventInBuffer(result);
data = GetArrayPart(data, 0, index);
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Prepared event of type {eventType} with {eventSize} bytes, timestamp {timestamp} and id {eventId} for serialization.");
QueueEventInBuffer(data);
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Prepared event of type {eventType} with {data.Length} bytes, timestamp {timestamp} and id {eventId} for serialization.");
RequestSerializationForEvents();
@@ -434,22 +439,16 @@ namespace Marro.PacManUdon
retriesWithoutSuccess = 0; // We had success!
}
private static void InitializeEvent(NetworkEventType eventType, float timestamp, byte eventId, int maxSize, out byte[][] data, out int index)
private static void InitializeEvent(NetworkEventType eventType, float timestamp, byte eventId, out byte[] data, out int index)
{
// Create header
data = new byte[MaxEventSize];
// Create header (note: event size is added later)
var timestampBytes = BitConverter.GetBytes(timestamp);
var header = new byte[HeaderLength];
// Event size is added later
Array.Copy(timestampBytes, 0, header, HeaderTimestampIndex, timestampBytes.Length);
header[HeaderEventIdIndex] = eventId;
header[HeaderEventTypeIndex] = Int32ToByte((int)eventType);
// Initialize event container
data = new byte[maxSize][];
data[0] = header;
index = 1;
Array.Copy(timestampBytes, 0, data, HeaderTimestampIndex, timestampBytes.Length);
data[HeaderEventIdIndex] = eventId;
data[HeaderEventTypeIndex] = ((int)eventType).ToByte();
index = HeaderLength;
}
private void RequestSerializationForEvents()
@@ -635,7 +634,6 @@ namespace Marro.PacManUdon
if (Synced)
{
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)} blaat");
UpdateNextEventTime();
}
}
@@ -654,13 +652,13 @@ namespace Marro.PacManUdon
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Queued full sync in buffer, should execute at {nextEventTime}.");
}
private void ProgressEventTime()
private void ApplyReceivedEvents()
{
IsEventUpdate = true;
while (eventsQueueIndex > 0 && nextEventTime <= internalTime)
{
var success = PerformEvent(eventsQueue[0]);
var success = ApplyEvent(eventsQueue[0]);
if (!success)
{
@@ -668,12 +666,11 @@ namespace Marro.PacManUdon
}
DequeueEventsFromBuffer(1);
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)} damn");
UpdateNextEventTime();
}
}
private bool PerformEvent(byte[] @event)
private bool ApplyEvent(byte[] @event)
{
var timestamp = GetTimestampFromHeader(@event);
var eventType = GetEventTypeFromHeader(@event);
@@ -696,7 +693,7 @@ namespace Marro.PacManUdon
foreach (var obj in syncedObjects)
{
var success = obj.SetSyncedData(@event, ref index, eventType);
var success = obj.WriteSyncedData(@event, ref index, eventType);
if (!success)
{
@@ -720,7 +717,7 @@ namespace Marro.PacManUdon
Synced = true;
}
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Processed incoming event! Total {index} bytes.");
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)}) Performed incoming eventof type {eventType}! Total {index} bytes.");
retriesWithoutSuccess = 0; // We had success!
@@ -937,9 +934,6 @@ namespace Marro.PacManUdon
Array.Copy(data, start, result, 0, length);
return result;
}
public static byte Int32ToByte(int value) =>
(byte)value; // Doing this inline causes an error...?
#endregion
#region Debug
@@ -975,6 +969,16 @@ namespace Marro.PacManUdon
{
SendEventSoon(NetworkEventType.FullSync);
}
public void DoPelletSync()
{
SendEventSoon(NetworkEventType.SyncPellets);
}
public void DoGhostSync()
{
SendEventSoon(NetworkEventType.GhostUpdate);
}
#endregion
}
}

View File

@@ -316,16 +316,14 @@ namespace Marro.PacManUdon
Pellet pellet = other.gameObject.GetComponent<Pellet>();
if (pellet)
{
pellet.gameObject.SetActive(false);
if (pellet.isPowerPellet)
{
gameController.GotPowerPellet();
gameController.GotPowerPellet(pellet);
freezeSeconds = 0.05f;
}
else
{
gameController.GotPellet();
gameController.GotPellet(pellet);
freezeSeconds = 0.0166666666666667f;
}
return;
@@ -336,30 +334,28 @@ namespace Marro.PacManUdon
}
}
public override void AppendSyncedData(byte[][] data, ref int offset, NetworkEventType eventType)
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
if (eventType != NetworkEventType.PacManTurn || kinematic || frozen || !enabled)
{
return;
}
data[offset++] = BitConverter.GetBytes(targetDirection.x);
data[offset++] = BitConverter.GetBytes(targetDirection.y);
data.Append(targetDirection, ref index);
base.AppendSyncedData(data, ref offset, eventType);
base.CollectSyncedData(data, ref index, eventType);
}
public override bool SetSyncedData(byte[] data, ref int offset, NetworkEventType eventType)
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
if (eventType != NetworkEventType.PacManTurn || kinematic || frozen || !enabled)
{
return true;
}
SetTargetDirection(new Vector2(BitConverter.ToSingle(data, offset), BitConverter.ToSingle(data, offset + 4)));
offset += 8;
SetTargetDirection(data.ReadVector2(ref index));
return base.SetSyncedData(data, ref offset, eventType);
return base.WriteSyncedData(data, ref index, eventType);
}
}
}

View File

@@ -43,7 +43,7 @@ MonoBehaviour:
Data:
- Name:
Entry: 12
Data: 8
Data: 9
- Name:
Entry: 7
Data:
@@ -109,31 +109,25 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: pellets
Data: <PelletCollectedCount>k__BackingField
- Name: $v
Entry: 7
Data: 6|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: pellets
Data: <PelletCollectedCount>k__BackingField
- Name: <UserType>k__BackingField
Entry: 7
Data: 7|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.Pellet[], Assembly-CSharp
Data: System.Int32, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 7
Data: 8|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.Component[], UnityEngine.CoreModule
- Name:
Entry: 8
Data:
Entry: 9
Data: 7
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -148,7 +142,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 9|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 8|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -169,25 +163,31 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: pelletRenderers
Data: pellets
- Name: $v
Entry: 7
Data: 10|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 9|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: pelletRenderers
Data: pellets
- Name: <UserType>k__BackingField
Entry: 7
Data: 11|System.RuntimeType, mscorlib
Data: 10|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.Renderer[], UnityEngine.CoreModule
Data: Marro.PacManUdon.Pellet[], Assembly-CSharp
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 11
Entry: 7
Data: 11|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.Component[], UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -476,6 +476,60 @@ MonoBehaviour:
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: syncedPelletsCollected
- Name: $v
Entry: 7
Data: 26|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: syncedPelletsCollected
- Name: <UserType>k__BackingField
Entry: 7
Data: 27|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Byte[], mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 27
- 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: 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: 13
Data:

View File

@@ -1,12 +1,14 @@
using UdonSharp;
using System;
using UnityEngine;
namespace Marro.PacManUdon
{
public class PelletManager : SyncedObject
{
public int PelletCount => pellets.Length;
public int PelletCollectedCount { get; private set; }
Pellet[] pellets;
Renderer[] pelletRenderers;
Animator[] powerPellets;
bool powerPelletBlinkEnabled;
@@ -14,20 +16,18 @@ namespace Marro.PacManUdon
float powerPelletBlinkProgress;
bool powerPelletBlinkCurrentlyVisible;
byte[] syncedPelletsCollected;
public void Initialize()
{
gameObject.SetActive(true);
pellets = GetComponentsInChildren<Pellet>(includeInactive: true);
pelletRenderers = new Renderer[pellets.Length];
for (int i = 0; i < pelletRenderers.Length; i++)
{
pelletRenderers[i] = pellets[i].GetComponent<Renderer>();
}
powerPellets = GetComponentsInChildren<Animator>(true);
powerPelletBlinkToggleInterval = PacManConstants.GetPowerPelletBlinkToggleInterval();
SetPowerPelletsBlink(false);
RestoreAllPellets();
}
public override void SyncedUpdate()
@@ -71,29 +71,63 @@ namespace Marro.PacManUdon
powerPelletBlinkEnabled = !frozen;
}
public void RestoreAllPellets()
public int PelletCollected(Pellet pellet)
{
pellet.gameObject.SetActive(false);
var index = pellet.transform.GetSiblingIndex();
syncedPelletsCollected[index/8] |= (byte)(1 << index%8);
PelletCollectedCount++;
return PelletCollectedCount;
}
public int RestoreAllPellets()
{
foreach (var pellet in pellets)
{
pellet.gameObject.SetActive(true);
}
foreach (Renderer pelletRenderer in pelletRenderers)
syncedPelletsCollected = new byte[pellets.Length/8 + 1];
PelletCollectedCount = 0;
return PelletCount;
}
private void SetPelletsCollectedFromSync()
{
for (int i = 0; i < pellets.Length; i++)
{
pelletRenderer.enabled = true;
var active = (syncedPelletsCollected[i/8] & (byte)(1 << i%8)) == 0;
pellets[i].gameObject.SetActive(active);
}
}
public override void AppendSyncedData(byte[][] data, ref int index, NetworkEventType eventType)
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
if (eventType != NetworkEventType.SyncPellets)
{
return;
}
data.Append((byte)PelletCollectedCount, ref index);
data.Append(syncedPelletsCollected, ref index);
}
public override bool SetSyncedData(byte[] data, ref int index, NetworkEventType eventType)
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
if (eventType != NetworkEventType.SyncPellets)
{
return true;
}
PelletCollectedCount = data.ReadByte(ref index);
Array.Copy(data, index, syncedPelletsCollected, 0, syncedPelletsCollected.Length);
index += syncedPelletsCollected.Length;
SetPelletsCollectedFromSync();
return true;
}
public int PelletCount => pellets.Length;
}
}

View File

@@ -47,12 +47,12 @@ namespace Marro.PacManUdon
gameObject.SetActive(false);
}
public override void AppendSyncedData(byte[][] data, ref int index, NetworkEventType eventType)
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
}
public override bool SetSyncedData(byte[] data, ref int index, NetworkEventType eventType)
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
return true;
}

View File

@@ -92,7 +92,7 @@ namespace Marro.PacManUdon
pacMan.SetPosition(attractScreenElements[16].transform.localPosition);
pacMan.SetDirection(Vector2.left);
ghostManager.Reset();
ghostManager.RestartLevel();
ghostManager.SetLevel(2);
ghostManager.SetKinematic(true);
ghostManager.SetActive(true);

View File

@@ -19,8 +19,8 @@ namespace Marro.PacManUdon
case 1:
// Show pole
SetIntermissionScreenVisible(true);
intermission2Pole.Reset();
intermission2Pole.SetActive(true);
intermission2Pole.Reset();
break;
case 2:
// Start music

View File

@@ -13,7 +13,7 @@ namespace Marro.PacManUdon
break;
case 1:
// Make maze visible
RestartLevel();
RestartLevel(afterLifeLost: true);
SetMazeVisible(true);
break;
case 2:
@@ -42,7 +42,7 @@ namespace Marro.PacManUdon
SetFrozen(false);
soundManager.SuppressSound(false);
soundManager.StartGhostSound();
soundManager.UpdatePelletCount(pelletCountRemaining);
soundManager.UpdatePelletCount(pelletManager.PelletCount - pelletManager.PelletCollectedCount);
}
}
}

View File

@@ -18,6 +18,7 @@ namespace Marro.PacManUdon
// Increment level, show ready, show pellets, show lives indicators
IncrementLevel();
statusDisplay.SetExtraLivesDisplayVisible(true);
statusDisplay.SetLevelDisplayVisible(true);
statusDisplay.SetReadyTextVisible(true);
SetPelletsActive(true);
break;

View File

@@ -254,12 +254,12 @@ public class SoundManager : SyncedObject
};
}
public override void AppendSyncedData(byte[][] data, ref int index, NetworkEventType eventType)
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
}
public override bool SetSyncedData(byte[] data, ref int index, NetworkEventType eventType)
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
return true;
}

View File

@@ -167,12 +167,12 @@ namespace Marro.PacManUdon
}
}
public override void AppendSyncedData(byte[][] data, ref int index, NetworkEventType eventType)
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
}
public override bool SetSyncedData(byte[] data, ref int index, NetworkEventType eventType)
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
return true;
}

View File

@@ -9,7 +9,7 @@ namespace Marro.PacManUdon
public NetworkManager networkManager;
public virtual void SyncedUpdate() { }
public abstract void AppendSyncedData(byte[][] data, ref int index, NetworkEventType eventType);
public abstract bool SetSyncedData(byte[] data, ref int index, NetworkEventType eventType);
public abstract void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType);
public abstract bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType);
}
}

14
Assets/Scripts/Test.cs Normal file
View File

@@ -0,0 +1,14 @@
namespace Marro.PacManUdon
{
using UdonSharp;
using UnityEngine;
public class Test : UdonSharpBehaviour
{
[SerializeField] Pellet pellet;
public void Start()
{
Debug.Log(pellet.enabled);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0227a738d77ab0849bdc9047b5b27c78
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

118
Assets/Scripts/Test1.asset Normal file
View File

@@ -0,0 +1,118 @@
%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: Test1
m_EditorClassIdentifier:
serializedUdonProgramAsset: {fileID: 11400000, guid: 6457f9f1332ac0742bdff23291631f30, type: 2}
udonAssembly:
assemblyError:
sourceCsScript: {fileID: 11500000, guid: 0227a738d77ab0849bdc9047b5b27c78, type: 3}
scriptVersion: 2
compiledVersion: 2
behaviourSyncMode: 0
hasInteractEvent: 0
scriptID: -4571266787425106669
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: 1
- Name:
Entry: 7
Data:
- Name: $k
Entry: 1
Data: pellet
- Name: $v
Entry: 7
Data: 2|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: pellet
- Name: <UserType>k__BackingField
Entry: 7
Data: 3|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.Pellet, Assembly-CSharp
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 7
Data: 4|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: VRC.Udon.UdonBehaviour, VRC.Udon
- Name:
Entry: 8
Data:
- 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: 5|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data: 6|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: 13
Data:
- Name:
Entry: 8
Data:

View File

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

View File

@@ -128,26 +128,25 @@ public class TestBall : SyncedObject
Debug.Log($"({nameof(TestBall)}) Up button pressed, jumped up at {GetProgress()} to {amountUp}.");
}
public override void AppendSyncedData(byte[][] data, ref int index, NetworkEventType eventType)
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
if (eventType == NetworkEventType.FullSync
|| eventType == NetworkEventType.FullSyncForced)
{
Debug.Log($"({nameof(TestBall)}) Sending sync data at progress {GetProgress()} and amountUp {amountUp}.");
data[index++] = BitConverter.GetBytes(amountUp);
data[index++] = BitConverter.GetBytes(GetProgress());
data.Append(amountUp, ref index);
data.Append(GetProgress(), ref index);
}
}
public override bool SetSyncedData(byte[] data, ref int index, NetworkEventType eventType)
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
if (eventType == NetworkEventType.FullSync
|| eventType == NetworkEventType.FullSyncForced)
{
amountUp = BitConverter.ToSingle(data, index);
SetProgress(BitConverter.ToSingle(data, index + 4));
amountUp = data.ReadFloat(ref index);
SetProgress(data.ReadFloat(ref index));
//Debug.Log($"({nameof(TestBall)}) Received sync event, synced to progress {GetProgress()} and amountUp {amountUp}.");
index += 8;
}
else
{

View File

@@ -207,4 +207,6 @@ QualitySettings:
excludedTargetPlatforms:
- Standalone
m_TextureMipmapLimitGroupNames: []
m_PerPlatformDefaultQuality: {}
m_PerPlatformDefaultQuality:
Server: 0
Standalone: 0