More sync

This commit is contained in:
2026-06-22 15:51:55 +02:00
parent a32df1bd09
commit 18499ab576
5 changed files with 1105 additions and 1071 deletions

View File

@@ -8,15 +8,16 @@ namespace Marro.PacManUdon
[RequireComponent(typeof(Renderer))]
public class BonusFruit : SyncedObject
{
PacManFruitType fruitType;
private PacManFruitType fruitType;
Animator animator;
new Renderer renderer;
ScoreBonusDisplay scoreBonusDisplay;
private Animator animator;
private new Renderer renderer;
private ScoreBonusDisplay scoreBonusDisplay;
[UdonSynced] bool active;
private int value;
private bool active;
private float activeCountdown;
private int value;
private bool frozen;
public void Initialize()
@@ -30,13 +31,15 @@ namespace Marro.PacManUdon
public override void SyncedUpdate()
{
if (active && !frozen)
if (!active || frozen)
{
activeCountdown -= networkManager.SyncedDeltaTime;
if (activeCountdown <= 0)
{
SetActive(false);
}
return;
}
activeCountdown -= networkManager.SyncedDeltaTime;
if (activeCountdown <= 0)
{
SetActive(false);
}
}
@@ -62,7 +65,6 @@ namespace Marro.PacManUdon
public void SetFruitType(PacManFruitType fruitType)
{
this.fruitType = fruitType;
value = (int)fruitScoreValue[PacManConstants.FruitTypeToValue(fruitType)];
animator.SetFloat("FruitType", PacManConstants.FruitTypeToValue(fruitType));
}
@@ -80,31 +82,33 @@ namespace Marro.PacManUdon
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
data.Append(active, ref index);
if (!active)
{
return;
}
data.Append(activeCountdown, ref index);
data.Append(frozen, ref index);
}
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
SetActive(data.ReadBool(ref index));
if (!active)
{
return true;
}
activeCountdown = data.ReadFloat(ref index);
frozen = data.ReadBool(ref index);
return true;
}
public PacManFruitType FruitType
{
set
{
SetFruitType(value);
}
get => fruitType;
}
public bool Active
{
set
{
SetActive(value);
}
get => active;
}
public bool Active => active;
private readonly DataDictionary fruitScoreValue = new DataDictionary()
{

View File

@@ -354,8 +354,8 @@ MonoBehaviour:
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
- Name:
Entry: 3
Data: 1
Entry: 6
Data:
- Name:
Entry: 8
Data:
@@ -367,13 +367,7 @@ MonoBehaviour:
Data: 21|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 1
- Name:
Entry: 7
Data: 22|UdonSharp.UdonSyncedAttribute, UdonSharp.Runtime
- Name:
Entry: 8
Data:
Data: 0
- Name:
Entry: 13
Data:
@@ -391,19 +385,25 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: value
Data: activeCountdown
- Name: $v
Entry: 7
Data: 23|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 22|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: value
Data: activeCountdown
- Name: <UserType>k__BackingField
Entry: 9
Data: 8
Entry: 7
Data: 23|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Single, mscorlib
- Name:
Entry: 8
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 8
Data: 23
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -439,25 +439,19 @@ MonoBehaviour:
Data:
- Name: $k
Entry: 1
Data: activeCountdown
Data: value
- Name: $v
Entry: 7
Data: 25|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: activeCountdown
Data: value
- Name: <UserType>k__BackingField
Entry: 7
Data: 26|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: System.Single, mscorlib
- Name:
Entry: 8
Data:
Entry: 9
Data: 8
- Name: <SystemType>k__BackingField
Entry: 9
Data: 26
Data: 8
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -472,7 +466,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 27|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 26|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -496,7 +490,7 @@ MonoBehaviour:
Data: frozen
- Name: $v
Entry: 7
Data: 28|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 27|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: frozen
@@ -520,7 +514,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 29|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 28|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0
@@ -544,13 +538,13 @@ MonoBehaviour:
Data: fruitScoreValue
- Name: $v
Entry: 7
Data: 30|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
Data: 29|UdonSharp.Compiler.FieldDefinition, UdonSharp.Editor
- Name: <Name>k__BackingField
Entry: 1
Data: fruitScoreValue
- Name: <UserType>k__BackingField
Entry: 7
Data: 31|System.RuntimeType, mscorlib
Data: 30|System.RuntimeType, mscorlib
- Name:
Entry: 1
Data: VRC.SDK3.Data.DataDictionary, VRCSDK3
@@ -559,7 +553,7 @@ MonoBehaviour:
Data:
- Name: <SystemType>k__BackingField
Entry: 9
Data: 31
Data: 30
- Name: <SyncMode>k__BackingField
Entry: 7
Data: System.Nullable`1[[UdonSharp.UdonSyncMode, UdonSharp.Runtime]], mscorlib
@@ -574,7 +568,7 @@ MonoBehaviour:
Data: false
- Name: _fieldAttributes
Entry: 7
Data: 32|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
Data: 31|System.Collections.Generic.List`1[[System.Attribute, mscorlib]], mscorlib
- Name:
Entry: 12
Data: 0

File diff suppressed because it is too large Load Diff

View File

@@ -384,27 +384,30 @@ namespace Marro.PacManUdon
public override void CollectSyncedData(byte[] data, ref int index, NetworkEventType eventType)
{
if (eventType == NetworkEventType.FullSync)
if (eventType != NetworkEventType.FullSync)
{
data.Append(currentlyInTimeSequence, ref index);
if (currentlyInTimeSequence)
{
data.AppendAsByte((int)currentTimeSequence, ref index);
data.Append(timeSequenceSecondsPassed, ref index);
}
collisionManager.CollectSyncedData(data, ref index, eventType);
ghostManager.CollectSyncedData(data, ref index, eventType);
pacMan.CollectSyncedData(data, ref index, eventType);
return;
}
//data[offset++] = new byte[] { NetworkManager.Int32ToByte((int)gameState) };
//data[offset++] = BitConverter.GetBytes(currentlyInTimeSequence);
//data[offset++] = new byte[] { NetworkManager.Int32ToByte((int)currentTimeSequence) };
//data[offset++] = BitConverter.GetBytes(timeSequenceSecondsPassed);
data.Append(currentlyInTimeSequence, ref index);
if (currentlyInTimeSequence)
{
data.AppendAsByte((int)currentTimeSequence, ref index);
data.Append(timeSequenceSecondsPassed, ref index);
}
data.AppendAsByte(level, ref index);
data.Append(score, ref index);
data.AppendAsByte(extraLives, ref index);
bonusFruit.CollectSyncedData(data, ref index, eventType);
collisionManager.CollectSyncedData(data, ref index, eventType);
ghostManager.CollectSyncedData(data, ref index, eventType);
pacMan.CollectSyncedData(data, ref index, eventType);
}
public override bool WriteSyncedData(byte[] data, ref int index, NetworkEventType eventType)
@@ -415,34 +418,34 @@ namespace Marro.PacManUdon
return true;
}
if (eventType == NetworkEventType.FullSync)
if (eventType != NetworkEventType.FullSync)
{
var currentlyInTimeSequence = data.ReadBool(ref index);
if (currentlyInTimeSequence)
{
var currentTimeSequence = (PacManTimeSequence)data.ReadByte(ref index);
var timeSequenceSecondsPassed = data.ReadFloat(ref index);
TimeSequenceSyncWithRemote(currentTimeSequence, timeSequenceSecondsPassed);
}
else
{
TimeSequenceTryEndCurrent();
}
collisionManager.WriteSyncedData(data, ref index, eventType);
ghostManager.WriteSyncedData(data, ref index, eventType);
pacMan.WriteSyncedData(data, ref index, eventType);
return true;
}
//SetGameState((PacManGameState)data[offset++]);
var currentlyInTimeSequence = data.ReadBool(ref index);
if (currentlyInTimeSequence)
{
var currentTimeSequence = (PacManTimeSequence)data.ReadByte(ref index);
var timeSequenceSecondsPassed = data.ReadFloat(ref index);
TimeSequenceSyncWithRemote(currentTimeSequence, timeSequenceSecondsPassed);
}
else
{
TimeSequenceTryEndCurrent();
}
//var currentlyInTimeSequence = BitConverter.ToBoolean(data, offset++);
//var currentTimeSequence = (PacManTimeSequence)data[offset++];
//var timeSequenceSecondsPassed = BitConverter.ToSingle(data, offset);
//offset += 4;
//TimeSequenceSyncWithRemote(currentlyInTimeSequence, currentTimeSequence, timeSequenceSecondsPassed);
SetLevel(data.ReadByte(ref index));
SetScore(data.ReadInt(ref index));
SetExtraLives(data.ReadByte(ref index));
bonusFruit.WriteSyncedData(data, ref index, eventType);
collisionManager.WriteSyncedData(data, ref index, eventType);
ghostManager.WriteSyncedData(data, ref index, eventType);
pacMan.WriteSyncedData(data, ref index, eventType);
return true;
}