Compare commits

...

7 Commits

Author SHA1 Message Date
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
28 changed files with 2319 additions and 836 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -82,12 +82,12 @@ namespace Marro.PacManUdon
this.active = active; 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; return true;
} }

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

@@ -0,0 +1,147 @@
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)1;
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);
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;
}
}
}

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: Data:
- Name: - Name:
Entry: 12 Entry: 12
Data: 37 Data: 34
- Name: - Name:
Entry: 7 Entry: 7
Data: Data:
@@ -1423,79 +1423,16 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: pelletCountOverride Data: maze
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 86|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor 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 - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: maze Data: maze
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 7
Data: 91|System.RuntimeType, mscorlib Data: 87|System.RuntimeType, mscorlib
- Name: - Name:
Entry: 1 Entry: 1
Data: Marro.PacManUdon.Maze, Assembly-CSharp Data: Marro.PacManUdon.Maze, Assembly-CSharp
@@ -1519,7 +1456,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 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: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0
@@ -1543,13 +1480,13 @@ MonoBehaviour:
Data: intermission2Pole Data: intermission2Pole
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 93|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: intermission2Pole Data: intermission2Pole
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 7 Entry: 7
Data: 94|System.RuntimeType, mscorlib Data: 90|System.RuntimeType, mscorlib
- Name: - Name:
Entry: 1 Entry: 1
Data: Marro.PacManUdon.Intermission2Pole, Assembly-CSharp Data: Marro.PacManUdon.Intermission2Pole, Assembly-CSharp
@@ -1573,7 +1510,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 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: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0
@@ -1597,7 +1534,7 @@ MonoBehaviour:
Data: mazeSpriteAnimator Data: mazeSpriteAnimator
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 96|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 92|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: mazeSpriteAnimator Data: mazeSpriteAnimator
@@ -1621,7 +1558,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 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: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0
@@ -1642,19 +1579,25 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: pelletCountTotal Data: attractScreenElements
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 98|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 94|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: pelletCountTotal Data: attractScreenElements
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 7
Data: 15 Data: 95|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: UnityEngine.GameObject[], UnityEngine.CoreModule
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 15 Data: 95
- 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
@@ -1669,7 +1612,7 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 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: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 0
@@ -1690,16 +1633,70 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: pelletCountRemaining Data: intermissionScreenElements
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 100|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 97|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: pelletCountRemaining Data: intermissionScreenElements
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 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 - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 15 Data: 15
@@ -1739,126 +1736,16 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: attractScreenElements Data: score
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 102|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 102|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 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:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 103
- 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: 104|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: intermissionScreenElements
- Name: $v
Entry: 7
Data: 105|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: intermissionScreenElements
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 103 Data: 15
- Name: <SystemType>k__BackingField
Entry: 9
Data: 103
- 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: 106|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: 107|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: gameState
- Name: <UserType>k__BackingField
Entry: 7
Data: 108|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: Marro.PacManUdon.PacManGameState, Assembly-CSharp
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField - Name: <SystemType>k__BackingField
Entry: 9 Entry: 9
Data: 15 Data: 15
@@ -1866,8 +1753,8 @@ MonoBehaviour:
Entry: 7 Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name: - Name:
Entry: 6 Entry: 3
Data: Data: 1
- Name: - Name:
Entry: 8 Entry: 8
Data: Data:
@@ -1876,11 +1763,23 @@ MonoBehaviour:
Data: false Data: false
- Name: _fieldAttributes - Name: _fieldAttributes
Entry: 7 Entry: 7
Data: 109|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], Data: 103|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib mscorlib
- Name: - Name:
Entry: 12 Entry: 12
Data: 0 Data: 2
- Name:
Entry: 7
Data: 104|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: 105|UdonSharp.FieldChangeCallbackAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
- Name: - Name:
Entry: 13 Entry: 13
Data: Data:
@@ -1898,13 +1797,74 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: score Data: level
- Name: $v
Entry: 7
Data: 106|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: 107|System.Collections.Generic.List`1[[System.Attribute, mscorlib]],
mscorlib
- Name:
Entry: 12
Data: 2
- Name:
Entry: 7
Data: 108|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
- Name:
Entry: 7
Data: 109|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 - Name: $v
Entry: 7 Entry: 7
Data: 110|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 110|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: score Data: highScore
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 15 Data: 15
@@ -1959,13 +1919,13 @@ MonoBehaviour:
Data: Data:
- Name: $k - Name: $k
Entry: 1 Entry: 1
Data: level Data: extraLives
- Name: $v - Name: $v
Entry: 7 Entry: 7
Data: 114|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor Data: 114|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField - Name: <Name>k__BackingField
Entry: 1 Entry: 1
Data: level Data: extraLives
- Name: <UserType>k__BackingField - Name: <UserType>k__BackingField
Entry: 9 Entry: 9
Data: 15 Data: 15
@@ -2015,128 +1975,6 @@ MonoBehaviour:
- Name: - Name:
Entry: 8 Entry: 8
Data: 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: - Name:
Entry: 13 Entry: 13
Data: Data:

View File

@@ -26,15 +26,11 @@ namespace Marro.PacManUdon
[Header("Game settings")] [Header("Game settings")]
[SerializeField] private int startingExtraLives = 3; [SerializeField] private int startingExtraLives = 3;
[SerializeField] private int scoreToExtraLife = 10000; [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 Maze maze;
private Intermission2Pole intermission2Pole; private Intermission2Pole intermission2Pole;
private Animator mazeSpriteAnimator; private Animator mazeSpriteAnimator;
private int pelletCountTotal;
private int pelletCountRemaining;
private GameObject[] attractScreenElements; private GameObject[] attractScreenElements;
private GameObject[] intermissionScreenElements; private GameObject[] intermissionScreenElements;
@@ -63,7 +59,7 @@ namespace Marro.PacManUdon
intermission2Pole = intermissionScreenElements[4].GetComponent<Intermission2Pole>(); intermission2Pole = intermissionScreenElements[4].GetComponent<Intermission2Pole>();
networkManager.Initialize(); 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); pacMan.Initialize(playerInput, maze.pacManStart, this);
bonusFruit.Initialize(); bonusFruit.Initialize();
pelletManager.Initialize(); pelletManager.Initialize();
@@ -138,27 +134,20 @@ namespace Marro.PacManUdon
{ {
Debug.Log($"{gameObject} New level started!"); Debug.Log($"{gameObject} New level started!");
pelletCountTotal = pelletManager.PelletCount;
pelletCountRemaining = pelletCountTotal;
ghostManager.SetPelletsRemaining(pelletCountRemaining);
ghostManager.NewLevel();
pelletManager.RestoreAllPellets(); pelletManager.RestoreAllPellets();
if (pelletCountOverride > 0) ghostManager.NewLevel();
{
pelletCountRemaining = pelletCountOverride;
}
mazeSpriteAnimator.SetBool("Blinking", false); mazeSpriteAnimator.SetBool("Blinking", false);
} }
private void RestartLevel() private void RestartLevel(bool afterLifeLost = false)
{ {
Debug.Log($"{gameObject} (Re)started level!"); Debug.Log($"{gameObject} (Re)started level!");
// SetInGameComponentVisibility(true); // SetInGameComponentVisibility(true);
ghostManager.Reset(); ghostManager.Reset(afterLifeLost);
pacMan.Reset(); pacMan.Reset();
bonusFruit.Despawn(); bonusFruit.Despawn();
soundManager.Reset(); soundManager.Reset();
@@ -172,29 +161,31 @@ namespace Marro.PacManUdon
SetFrozen(true); 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); if (addScore) AddScore(10);
ghostManager.PelletConsumed(); ghostManager.PelletConsumed();
soundManager.PlayPelletSound(); soundManager.PlayPelletSound();
var pelletCountRemaining = pelletManager.PelletCount - pelletCollectedCount;
soundManager.UpdatePelletCount(pelletCountRemaining); soundManager.UpdatePelletCount(pelletCountRemaining);
int pelletsConsumed = pelletCountTotal - pelletCountRemaining;
if (pelletCountRemaining <= 0) if (pelletCountRemaining <= 0)
{ {
StartTimeSequence(PacManTimeSequence.BoardClear); StartTimeSequence(PacManTimeSequence.BoardClear);
} }
else if (pelletsConsumed == 70 || pelletsConsumed == 170) else if (pelletCollectedCount == 70 || pelletCollectedCount == 170)
{ {
bonusFruit.Spawn(); bonusFruit.Spawn();
} }
} }
public void GotPowerPellet() public void GotPowerPellet(Pellet pellet)
{ {
Debug.Log($"{gameObject} GotPowerPellet"); Debug.Log($"{gameObject} GotPowerPellet");
@@ -203,7 +194,7 @@ namespace Marro.PacManUdon
TimeSequenceSkipToNextStep(); TimeSequenceSkipToNextStep();
return; return;
} }
GotPellet(addScore: false); GotPellet(pellet, addScore: false);
AddScore(50); AddScore(50);
ghostManager.SetPowerPellet(true); ghostManager.SetPowerPellet(true);
pacMan.SetPowerPellet(true); pacMan.SetPowerPellet(true);
@@ -240,7 +231,8 @@ namespace Marro.PacManUdon
public void PacManCaught() public void PacManCaught()
{ {
//StartTimeSequence(PacManTimeSequence.PacManCaught); return;
StartTimeSequence(PacManTimeSequence.PacManCaught);
} }
public void NoGhostsScared() public void NoGhostsScared()
@@ -403,7 +395,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++] = new byte[] { NetworkManager.Int32ToByte((int)gameState) };
//data[offset++] = BitConverter.GetBytes(currentlyInTimeSequence); //data[offset++] = BitConverter.GetBytes(currentlyInTimeSequence);
@@ -411,7 +403,7 @@ namespace Marro.PacManUdon
//data[offset++] = BitConverter.GetBytes(timeSequenceSecondsPassed); //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) if (eventType == NetworkEventType.StartGameButtonPressed)
{ {

View File

@@ -32,6 +32,8 @@ namespace Marro.PacManUdon
TargetingIdlePosition2 TargetingIdlePosition2
} }
[RequireComponent(typeof(Renderer))]
[RequireComponent(typeof(Animator))]
public class Ghost : GridMover public class Ghost : GridMover
{ {
[SerializeField] private PacManGhostType ghostType; [SerializeField] private PacManGhostType ghostType;
@@ -73,7 +75,6 @@ namespace Marro.PacManUdon
private bool isScared; private bool isScared;
private bool scattering; private bool scattering;
private PacManGhostFrozenState frozenState; private PacManGhostFrozenState frozenState;
private bool hideUntilUnfrozen;
private int housePelletCounter; private int housePelletCounter;
private bool housePelletCounterActive; private bool housePelletCounterActive;
private bool turnAroundSoon; private bool turnAroundSoon;
@@ -137,12 +138,8 @@ namespace Marro.PacManUdon
public override void SyncedUpdate() public override void SyncedUpdate()
{ {
if (ghostType == PacManGhostType.Blinky)
{
// ghostManager.gameStateManager.statusDisplay.SetDebugText(2, $"{turnAroundSoon}");
}
if (frozenState == PacManGhostFrozenState.Frozen || if (frozenState == PacManGhostFrozenState.Frozen ||
(frozenState == PacManGhostFrozenState.FrozenIfNotCaught && ((ghostState != PacManGhostState.Returning && ghostState != PacManGhostState.Entering) || hideUntilUnfrozen))) (frozenState == PacManGhostFrozenState.FrozenIfNotCaught && ghostState != PacManGhostState.Returning && ghostState != PacManGhostState.Entering))
{ {
return; return;
} }
@@ -642,7 +639,7 @@ namespace Marro.PacManUdon
if (reverseDirection && this.scattering != scattering) if (reverseDirection && this.scattering != scattering)
{ {
if (ghostState == PacManGhostState.Normal || ghostState == PacManGhostState.Home || ghostState == PacManGhostState.Exiting 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 || ghostState == PacManGhostState.Entering && ghostManager.gameController.GameState == PacManGameState.AttractModeDemo
) )
{ {

File diff suppressed because it is too large Load Diff

View File

@@ -7,9 +7,12 @@ namespace Marro.PacManUdon
public class GhostManager : SyncedObject public class GhostManager : SyncedObject
{ {
[NonSerialized] public GameManager gameController; [NonSerialized] public GameManager gameController;
private Ghost[] ghosts; private Ghost[] ghosts;
private Ghost blinky; private Ghost blinky;
private PelletManager pelletManager;
// Level constants // Level constants
private float speedDefault; private float speedDefault;
private float speedScared; private float speedScared;
@@ -42,7 +45,6 @@ namespace Marro.PacManUdon
// Elroy logic // Elroy logic
public int elroyLevel; public int elroyLevel;
private int pelletsRemaining;
// Ghost house logic // Ghost house logic
private bool sharedPelletCounterActive; private bool sharedPelletCounterActive;
@@ -55,9 +57,11 @@ namespace Marro.PacManUdon
private bool kinematic; private bool kinematic;
// This should be called once when the game is initialized // 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.gameController = gameController;
this.pelletManager = pelletManager;
ghosts = transform.GetComponentsInChildren<Ghost>(true); ghosts = transform.GetComponentsInChildren<Ghost>(true);
blinky = ghosts[0]; blinky = ghosts[0];
for (int ghostIndex = 0; ghostIndex < ghosts.Length; ghostIndex++) for (int ghostIndex = 0; ghostIndex < ghosts.Length; ghostIndex++)
@@ -73,7 +77,7 @@ namespace Marro.PacManUdon
} }
// This should be called every time the level is reset // This should be called every time the level is reset
public void Reset() public void Reset(bool afterLifeLost = false)
{ {
ghostScaredQueue = new DataList(); ghostScaredQueue = new DataList();
powerPelletActive = false; powerPelletActive = false;
@@ -84,6 +88,11 @@ namespace Marro.PacManUdon
elroyLevel = 0; elroyLevel = 0;
kinematic = false; kinematic = false;
if (afterLifeLost)
{
SetSharedPelletCounterActive(true);
}
foreach (Ghost ghost in ghosts) foreach (Ghost ghost in ghosts)
{ {
ghost.Reset(); ghost.Reset();
@@ -95,20 +104,15 @@ namespace Marro.PacManUdon
public void NewLevel() public void NewLevel()
{ {
SetSharedPelletCounterActive(false); SetSharedPelletCounterActive(false);
UpdateElroyLevel();
foreach (Ghost ghost in ghosts) foreach (Ghost ghost in ghosts)
{ {
ghost.ResetHousePelletCounter(); ghost.ResetHousePelletCounter();
} }
} }
public void LifeLost()
{
SetSharedPelletCounterActive(true);
}
public override void SyncedUpdate() public override void SyncedUpdate()
{ {
// gameStateManager.statusDisplay.SetDebugText(1, this.blinkCountdown.ToString());
if (frozen || kinematic) if (frozen || kinematic)
{ {
return; return;
@@ -368,7 +372,7 @@ namespace Marro.PacManUdon
Debug.Log($"{gameObject} SetScattering: {scattering}"); Debug.Log($"{gameObject} SetScattering: {scattering}");
foreach (Ghost ghost in ghosts) foreach (Ghost ghost in ghosts)
{ {
if (ghost == blinky && pelletsRemaining <= elroy1PelletCount) if (ghost == blinky && elroyLevel > 0) // Once blinky is elroy he no longer scatters
{ {
continue; continue;
} }
@@ -376,15 +380,13 @@ namespace Marro.PacManUdon
} }
} }
public void SetPelletsRemaining(int pelletsRemaining) /// <summary>
{ /// Whether to use the shared pellet counter for ghost exiting.
this.pelletsRemaining = pelletsRemaining; /// Should be called before ghosts are reset.
UpdateElroyLevel(); /// </summary>
}
void SetSharedPelletCounterActive(bool active) void SetSharedPelletCounterActive(bool active)
{ {
// Debug.Log($"{gameObject} SetSharedPelletCounterActive {active}"); Debug.Log($"{gameObject} SetSharedPelletCounterActive {active}");
sharedPelletCounterActive = active; sharedPelletCounterActive = active;
foreach (Ghost ghost in ghosts) foreach (Ghost ghost in ghosts)
{ {
@@ -394,10 +396,10 @@ namespace Marro.PacManUdon
public void PelletConsumed() public void PelletConsumed()
{ {
SetPelletsRemaining(pelletsRemaining - 1);
pelletTimeout = 0; pelletTimeout = 0;
UpdateElroyLevel();
if (sharedPelletCounterActive) if (sharedPelletCounterActive)
{ {
IncrementSharedPelletCounter(); IncrementSharedPelletCounter();
@@ -411,6 +413,7 @@ namespace Marro.PacManUdon
void IncrementSharedPelletCounter() void IncrementSharedPelletCounter()
{ {
sharedPelletCounter++; sharedPelletCounter++;
//Debug.Log($"Incremented shared pellet counter to {sharedPelletCounter}");
for (int ghostIndex = 0; ghostIndex < sharedPelletCounterReleaseValues.Length; ghostIndex++) for (int ghostIndex = 0; ghostIndex < sharedPelletCounterReleaseValues.Length; ghostIndex++)
{ {
Ghost ghost = ghosts[ghostIndex]; Ghost ghost = ghosts[ghostIndex];
@@ -442,10 +445,13 @@ namespace Marro.PacManUdon
void UpdateElroyLevel() void UpdateElroyLevel()
{ {
// Debug.Log($"{gameObject} Updating Elroy Level with pelletsRemaining {pelletsRemaining} with elroy2PelletCount {elroy2PelletCount} and elroy1PelletCount {elroy1PelletCount}"); // 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; if (pelletsRemaining < elroy2PelletCount) elroyLevel = 2;
else if (pelletsRemaining < elroy1PelletCount) elroyLevel = 1; else if (pelletsRemaining < elroy1PelletCount) elroyLevel = 1;
else elroyLevel = 0; else elroyLevel = 0;
if (elroyLevel != oldElroyLevel) if (elroyLevel != oldElroyLevel)
{ {
blinky.SetElroy(elroyLevel); blinky.SetElroy(elroyLevel);
@@ -470,12 +476,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; return true;
} }

View File

@@ -30,32 +30,26 @@ namespace Marro.PacManUdon
protected abstract void UpdateAnimator(); 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) if (eventType != NetworkEventType.PacManTurn)
{ {
return; return;
} }
var position = GetPosition(); data.Append(GetPosition(), ref index);
data[offset++] = BitConverter.GetBytes(position.x); data.Append(GetDirection(), ref index);
data[offset++] = BitConverter.GetBytes(position.y);
var direction = GetDirection();
data[offset++] = BitConverter.GetBytes(direction.x);
data[offset++] = BitConverter.GetBytes(direction.y);
} }
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) if (eventType != NetworkEventType.PacManTurn)
{ {
return true; return true;
} }
SetPosition(new Vector2(BitConverter.ToSingle(data, offset), BitConverter.ToSingle(data, offset + 4))); SetPosition(data.ReadVector2(ref index));
SetDirection(new Vector2(BitConverter.ToSingle(data, offset + 8), BitConverter.ToSingle(data, offset + 12))); SetDirection(data.ReadVector2(ref index));
offset += 16;
return true; return true;
} }

View File

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

View File

@@ -15,6 +15,7 @@ namespace Marro.PacManUdon
FullSync = 1, FullSync = 1,
PacManTurn = 2, PacManTurn = 2,
StartGameButtonPressed = 3, StartGameButtonPressed = 3,
SyncPellets = 4,
} }
public class NetworkManager : UdonSharpBehaviour public class NetworkManager : UdonSharpBehaviour
@@ -64,6 +65,10 @@ namespace Marro.PacManUdon
/// The maximum amount of events in the buffer. /// The maximum amount of events in the buffer.
/// </summary> /// </summary>
private const int BufferMaxTotalEvents = 255; private const int BufferMaxTotalEvents = 255;
/// <summary>
/// The maximum amount of events in the buffer.
/// </summary>
private const int MaxEventSize = ushort.MaxValue;
/// <summary> /// <summary>
/// The index in an event where the event size is stored. /// The index in an event where the event size is stored.
@@ -396,36 +401,27 @@ namespace Marro.PacManUdon
var eventId = GetNextEventId(lastEventId); 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) 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 // Validate and fill in event size
var eventSize = result.Length; var eventSizeBytes = BitConverter.GetBytes((ushort)index);
Array.Copy(eventSizeBytes, 0, data, HeaderEventSizeIndex, eventSizeBytes.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);
if (IsFullSync(eventType)) if (IsFullSync(eventType))
{ {
hasFullSyncReady = true; 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(); RequestSerializationForEvents();
@@ -434,22 +430,16 @@ namespace Marro.PacManUdon
retriesWithoutSuccess = 0; // We had success! 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 timestampBytes = BitConverter.GetBytes(timestamp);
Array.Copy(timestampBytes, 0, data, HeaderTimestampIndex, timestampBytes.Length);
var header = new byte[HeaderLength]; data[HeaderEventIdIndex] = eventId;
data[HeaderEventTypeIndex] = Int32ToByte((int)eventType);
// Event size is added later index = HeaderLength;
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;
} }
private void RequestSerializationForEvents() private void RequestSerializationForEvents()
@@ -635,7 +625,6 @@ namespace Marro.PacManUdon
if (Synced) if (Synced)
{ {
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)} blaat");
UpdateNextEventTime(); UpdateNextEventTime();
} }
} }
@@ -668,7 +657,6 @@ namespace Marro.PacManUdon
} }
DequeueEventsFromBuffer(1); DequeueEventsFromBuffer(1);
Debug.Log($"({nameof(PacManUdon)} {nameof(NetworkManager)} damn");
UpdateNextEventTime(); UpdateNextEventTime();
} }
} }
@@ -696,7 +684,7 @@ namespace Marro.PacManUdon
foreach (var obj in syncedObjects) foreach (var obj in syncedObjects)
{ {
var success = obj.SetSyncedData(@event, ref index, eventType); var success = obj.WriteSyncedData(@event, ref index, eventType);
if (!success) if (!success)
{ {
@@ -975,6 +963,11 @@ namespace Marro.PacManUdon
{ {
SendEventSoon(NetworkEventType.FullSync); SendEventSoon(NetworkEventType.FullSync);
} }
public void DoPelletSync()
{
SendEventSoon(NetworkEventType.SyncPellets);
}
#endregion #endregion
} }
} }

View File

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

View File

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

View File

@@ -1,12 +1,14 @@
using UdonSharp; using System;
using UnityEngine; using UnityEngine;
namespace Marro.PacManUdon namespace Marro.PacManUdon
{ {
public class PelletManager : SyncedObject public class PelletManager : SyncedObject
{ {
public int PelletCount => pellets.Length;
public int PelletCollectedCount { get; private set; }
Pellet[] pellets; Pellet[] pellets;
Renderer[] pelletRenderers;
Animator[] powerPellets; Animator[] powerPellets;
bool powerPelletBlinkEnabled; bool powerPelletBlinkEnabled;
@@ -14,20 +16,18 @@ namespace Marro.PacManUdon
float powerPelletBlinkProgress; float powerPelletBlinkProgress;
bool powerPelletBlinkCurrentlyVisible; bool powerPelletBlinkCurrentlyVisible;
byte[] syncedPelletsCollected;
public void Initialize() public void Initialize()
{ {
gameObject.SetActive(true); gameObject.SetActive(true);
pellets = GetComponentsInChildren<Pellet>(includeInactive: 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); powerPellets = GetComponentsInChildren<Animator>(true);
powerPelletBlinkToggleInterval = PacManConstants.GetPowerPelletBlinkToggleInterval(); powerPelletBlinkToggleInterval = PacManConstants.GetPowerPelletBlinkToggleInterval();
SetPowerPelletsBlink(false); SetPowerPelletsBlink(false);
RestoreAllPellets();
} }
public override void SyncedUpdate() public override void SyncedUpdate()
@@ -71,29 +71,63 @@ namespace Marro.PacManUdon
powerPelletBlinkEnabled = !frozen; 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) foreach (var pellet in pellets)
{ {
pellet.gameObject.SetActive(true); 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; return true;
} }
public int PelletCount => pellets.Length;
} }
} }

View File

@@ -47,12 +47,12 @@ namespace Marro.PacManUdon
gameObject.SetActive(false); 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; return true;
} }

View File

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

View File

@@ -13,7 +13,7 @@ namespace Marro.PacManUdon
break; break;
case 1: case 1:
// Make maze visible // Make maze visible
RestartLevel(); RestartLevel(afterLifeLost: true);
SetMazeVisible(true); SetMazeVisible(true);
break; break;
case 2: case 2:
@@ -42,7 +42,7 @@ namespace Marro.PacManUdon
SetFrozen(false); SetFrozen(false);
soundManager.SuppressSound(false); soundManager.SuppressSound(false);
soundManager.StartGhostSound(); 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 // Increment level, show ready, show pellets, show lives indicators
IncrementLevel(); IncrementLevel();
statusDisplay.SetExtraLivesDisplayVisible(true); statusDisplay.SetExtraLivesDisplayVisible(true);
statusDisplay.SetLevelDisplayVisible(true);
statusDisplay.SetReadyTextVisible(true); statusDisplay.SetReadyTextVisible(true);
SetPelletsActive(true); SetPelletsActive(true);
break; 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; 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; return true;
} }

View File

@@ -9,7 +9,7 @@ namespace Marro.PacManUdon
public NetworkManager networkManager; public NetworkManager networkManager;
public virtual void SyncedUpdate() { } public virtual void SyncedUpdate() { }
public abstract void AppendSyncedData(byte[][] data, ref int index, NetworkEventType eventType); public abstract void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType);
public abstract bool SetSyncedData(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}."); 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 if (eventType == NetworkEventType.FullSync
|| eventType == NetworkEventType.FullSyncForced) || eventType == NetworkEventType.FullSyncForced)
{ {
Debug.Log($"({nameof(TestBall)}) Sending sync data at progress {GetProgress()} and amountUp {amountUp}."); Debug.Log($"({nameof(TestBall)}) Sending sync data at progress {GetProgress()} and amountUp {amountUp}.");
data[index++] = BitConverter.GetBytes(amountUp); data.Append(amountUp, ref index);
data[index++] = BitConverter.GetBytes(GetProgress()); 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 if (eventType == NetworkEventType.FullSync
|| eventType == NetworkEventType.FullSyncForced) || eventType == NetworkEventType.FullSyncForced)
{ {
amountUp = BitConverter.ToSingle(data, index); amountUp = data.ReadFloat(ref index);
SetProgress(BitConverter.ToSingle(data, index + 4)); SetProgress(data.ReadFloat(ref index));
//Debug.Log($"({nameof(TestBall)}) Received sync event, synced to progress {GetProgress()} and amountUp {amountUp}."); //Debug.Log($"({nameof(TestBall)}) Received sync event, synced to progress {GetProgress()} and amountUp {amountUp}.");
index += 8;
} }
else else
{ {

View File

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