Switched to 1d array CollectSyncedData
This commit is contained in:
@@ -54317,11 +54317,11 @@ MonoBehaviour:
|
|||||||
DynamicPrefabs: []
|
DynamicPrefabs: []
|
||||||
DynamicMaterials:
|
DynamicMaterials:
|
||||||
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
|
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
|
||||||
|
- {fileID: 2100000, guid: fc67956adbc95584ba3ae3b18d1e430d, type: 2}
|
||||||
- {fileID: 2541243872366204002, guid: 7168d13094fcae94b81e672d1f4ab73f, type: 2}
|
- {fileID: 2541243872366204002, guid: 7168d13094fcae94b81e672d1f4ab73f, type: 2}
|
||||||
- {fileID: 10758, guid: 0000000000000000f000000000000000, type: 0}
|
- {fileID: 10758, guid: 0000000000000000f000000000000000, type: 0}
|
||||||
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
|
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
|
||||||
- {fileID: 2100000, guid: a3869014ba4893d409f150224856180a, type: 2}
|
- {fileID: 2100000, guid: a3869014ba4893d409f150224856180a, type: 2}
|
||||||
- {fileID: 2100000, guid: fc67956adbc95584ba3ae3b18d1e430d, type: 2}
|
|
||||||
- {fileID: 2100000, guid: ae0c7562e66fca1469f7ee603e462581, type: 2}
|
- {fileID: 2100000, guid: ae0c7562e66fca1469f7ee603e462581, type: 2}
|
||||||
- {fileID: 2100000, guid: db2b6d76bdd134244912a5c1c9971804, type: 2}
|
- {fileID: 2100000, guid: db2b6d76bdd134244912a5c1c9971804, type: 2}
|
||||||
LightMapsNear: []
|
LightMapsNear: []
|
||||||
|
|||||||
@@ -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
147
Assets/Scripts/ByteUtils.cs
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Marro.PacManUdon
|
||||||
|
{
|
||||||
|
public static class ByteUtils
|
||||||
|
{
|
||||||
|
private static void Append(byte[] value, byte[] target, ref int index)
|
||||||
|
{
|
||||||
|
Debug.Log($"ByteUtils Append value.Length: {value.Length}, array.Length : {target.Length}, index: {index}");
|
||||||
|
Array.Copy(value, 0, target, index, value.Length);
|
||||||
|
index += value.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Append(byte value, byte[] target, ref int index) =>
|
||||||
|
target[index++] = value;
|
||||||
|
|
||||||
|
public static void Append(sbyte value, byte[] target, ref int index) =>
|
||||||
|
target[index++] = (byte)value;
|
||||||
|
|
||||||
|
public static void Append(bool value, byte[] target, ref int index) =>
|
||||||
|
target[index++] = value ? (byte)1 : (byte)1;
|
||||||
|
|
||||||
|
public static void Append(ushort value, byte[] target, ref int index) =>
|
||||||
|
Append(BitConverter.GetBytes(value), target, ref index);
|
||||||
|
|
||||||
|
public static void Append(short value, byte[] target, ref int index) =>
|
||||||
|
Append(BitConverter.GetBytes(value), target, ref index);
|
||||||
|
|
||||||
|
public static void Append(uint value, byte[] target, ref int index) =>
|
||||||
|
Append(BitConverter.GetBytes(value), target, ref index);
|
||||||
|
|
||||||
|
public static void Append(int value, byte[] target, ref int index) =>
|
||||||
|
Append(BitConverter.GetBytes(value), target, ref index);
|
||||||
|
|
||||||
|
public static void Append(ulong value, byte[] target, ref int index) =>
|
||||||
|
Append(BitConverter.GetBytes(value), target, ref index);
|
||||||
|
|
||||||
|
public static void Append(long value, byte[] target, ref int index) =>
|
||||||
|
Append(BitConverter.GetBytes(value), target, ref index);
|
||||||
|
|
||||||
|
public static void Append(float value, byte[] target, ref int index) =>
|
||||||
|
Append(BitConverter.GetBytes(value), target, ref index);
|
||||||
|
|
||||||
|
public static void Append(double value, byte[] target, ref int index) =>
|
||||||
|
Append(BitConverter.GetBytes(value), target, ref index);
|
||||||
|
|
||||||
|
public static void Append(char value, byte[] target, ref int index) =>
|
||||||
|
Append(BitConverter.GetBytes(value), target, ref index);
|
||||||
|
|
||||||
|
public static void Append(Vector2 value, byte[] target, ref int index)
|
||||||
|
{
|
||||||
|
Append(value.x, target, ref index);
|
||||||
|
Append(value.y, target, ref index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Append(Vector3 value, byte[] target, ref int index)
|
||||||
|
{
|
||||||
|
Append(value.x, target, ref index);
|
||||||
|
Append(value.y, target, ref index);
|
||||||
|
Append(value.z, target, ref index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte ReadByte(byte[] source, ref int index) =>
|
||||||
|
source[index++];
|
||||||
|
|
||||||
|
public static bool ReadBool(byte[] source, ref int index) =>
|
||||||
|
source[index++] > 0;
|
||||||
|
|
||||||
|
public static ushort ReadUShort(byte[] source, ref int index)
|
||||||
|
{
|
||||||
|
var value = BitConverter.ToUInt16(source, index);
|
||||||
|
index += 2;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static short ReadShort(byte[] source, ref int index)
|
||||||
|
{
|
||||||
|
var value = BitConverter.ToInt16(source, (int)index);
|
||||||
|
index += 2;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static uint ReadUInt(byte[] source, ref int index)
|
||||||
|
{
|
||||||
|
var value = BitConverter.ToUInt32(source, index);
|
||||||
|
index += 4;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int ReadInt(byte[] source, ref int index)
|
||||||
|
{
|
||||||
|
var value = BitConverter.ToInt32(source, index);
|
||||||
|
index += 4;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ulong ReadULong(byte[] source, ref int index)
|
||||||
|
{
|
||||||
|
var value = BitConverter.ToUInt64(source, index);
|
||||||
|
index += 8;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long ReadLong(byte[] source, ref int index)
|
||||||
|
{
|
||||||
|
var value = BitConverter.ToInt64(source, index);
|
||||||
|
index += 8;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float ReadFloat(byte[] source, ref int index)
|
||||||
|
{
|
||||||
|
var value = BitConverter.ToSingle(source, index);
|
||||||
|
index += 4;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double ReadDouble(byte[] source, ref int index)
|
||||||
|
{
|
||||||
|
var value = BitConverter.ToDouble(source, index);
|
||||||
|
index += 8;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static char ReadChar(byte[] source, ref int index)
|
||||||
|
{
|
||||||
|
var value = BitConverter.ToChar(source, index);
|
||||||
|
index += 2;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Vector2 ReadVector2(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(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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Scripts/ByteUtils.cs.meta
Normal file
11
Assets/Scripts/ByteUtils.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7d2126e683a87e241ad0399cefcda807
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -403,7 +403,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 +411,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)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -470,12 +470,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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
ByteUtils.Append(GetPosition(), data, ref index);
|
||||||
data[offset++] = BitConverter.GetBytes(position.x);
|
ByteUtils.Append(GetDirection(), data, 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(ByteUtils.ReadVector2(data, ref index));
|
||||||
SetDirection(new Vector2(BitConverter.ToSingle(data, offset + 8), BitConverter.ToSingle(data, offset + 12)));
|
SetDirection(ByteUtils.ReadVector2(data, ref index));
|
||||||
offset += 16;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,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 +400,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 +429,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()
|
||||||
@@ -696,7 +685,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)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -336,30 +336,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);
|
ByteUtils.Append(targetDirection, data, 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(ByteUtils.ReadVector2(data, ref index));
|
||||||
offset += 8;
|
|
||||||
|
|
||||||
return base.SetSyncedData(data, ref offset, eventType);
|
return base.WriteSyncedData(data, ref index, eventType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -84,12 +84,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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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);
|
ByteUtils.Append(amountUp, data, ref index);
|
||||||
data[index++] = BitConverter.GetBytes(GetProgress());
|
ByteUtils.Append(GetProgress(), data, 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 = ByteUtils.ReadFloat(data, ref index);
|
||||||
SetProgress(BitConverter.ToSingle(data, index + 4));
|
SetProgress(ByteUtils.ReadFloat(data, 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
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user