More sync
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user