Skip to content

Commit f0f822f

Browse files
committed
Fix pvp exceptions
1 parent 280320f commit f0f822f

2 files changed

Lines changed: 72 additions & 19 deletions

File tree

com.unity.netcode.gameobjects/Tests/Editor/DocumentationCodeSamples/Serialization/SerializationCustomization.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,48 @@
11
using NUnit.Framework;
22
using Unity.Collections;
3+
using Unity.Netcode;
34

4-
namespace Unity.Netcode.EditorTests.Documentation.Serialization
5+
namespace DocumentationCodeSamples
56
{
67
#region HealthStruct
8+
/// <summary>Container for storing health data for a player or item.</summary>
79
public struct Health
810
{
11+
/// <summary>
12+
/// The maximum health that this player or item can have.
13+
/// This is unlikely to change often.
14+
/// </summary>
915
public uint MaxHealth;
16+
17+
/// <summary>
18+
/// The current level of health that this player or item has.
19+
/// This is likely to change regularly.
20+
/// </summary>
1021
public int CurrentHealth;
1122
}
1223
#endregion
1324

1425
#region FastBuffer
15-
// Tells the Netcode how to serialize and deserialize our custom type.
26+
/// <summary>Tells the Netcode how to serialize and deserialize our custom type.</summary>
1627
// The class name doesn't matter here.
1728
public static class FastBufferExtensions
1829
{
30+
/// <summary>
31+
/// Extension method to override the serialization for a custom type.
32+
/// </summary>
33+
/// <param name="writer">Buffer to write values into.</param>
34+
/// <param name="health">The type to customize or override.</param>
1935
public static void WriteValueSafe(this FastBufferWriter writer, in Health health)
2036
{
2137
writer.WriteValueSafe(health.MaxHealth);
2238
writer.WriteValueSafe(health.CurrentHealth);
2339
}
2440

41+
/// <summary>
42+
/// Extension method to override the de-serialization for a custom type.
43+
/// </summary>
44+
/// <param name="reader">Buffer to read values from.</param>
45+
/// <param name="health">The type to customize or override.</param>
2546
public static void ReadValueSafe(this FastBufferReader reader, out Health health)
2647
{
2748
reader.ReadValueSafe(out uint max);
@@ -32,9 +53,16 @@ public static void ReadValueSafe(this FastBufferReader reader, out Health health
3253
#endregion
3354

3455
#region BufferSerializer
56+
/// <summary>Tells the <see cref="BufferSerializer{TReaderWriter}"/> how to serialize and deserialize our custom type.</summary>
3557
// The class name doesn't matter here.
3658
public static class BufferSerializerExtensions
3759
{
60+
/// <summary>
61+
/// Extension method to override bi-directional serialization for a custom type.
62+
/// </summary>
63+
/// <param name="serializer">Bi-directional serial</param>
64+
/// <param name="health">The type to customize or override.</param>
65+
/// <typeparam name="TReaderWriter">Boilerplate syntax to enable the bi-directional serialization.</typeparam>
3866
public static void SerializeValue<TReaderWriter>(this BufferSerializer<TReaderWriter> serializer, ref Health health) where TReaderWriter : IReaderWriter
3967
{
4068
// Because the BufferSerializer already knows how to read and write the primitive types

com.unity.netcode.gameobjects/Tests/Runtime/DocumentationCodeSamples/NetworkVariable/CustomNetworkVariable.cs

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,15 @@ public override void OnNetworkSpawn()
4040
}
4141
}
4242

43-
// Bare minimum example of NetworkVariableBase derived class
43+
/// <summary>
44+
/// Bare minimum example of NetworkVariableBase derived class
45+
/// </summary>
4446
[Serializable]
4547
public class MyCustomNetworkVariable : NetworkVariableBase
4648
{
47-
// Managed list of class instances
49+
/// <summary>
50+
/// Managed list of class instances
51+
/// </summary>
4852
public List<SomeData> SomeDataToSynchronize = new List<SomeData>();
4953

5054
/// <summary>
@@ -96,25 +100,37 @@ public override void ReadField(FastBufferReader reader)
96100
}
97101
}
98102

103+
/// <summary>
104+
/// Used to write partial updates rather than synchronizing the full state on every change.
105+
/// </summary>
106+
/// <param name="writer">The stream to write the state to</param>
107+
public override void WriteDelta(FastBufferWriter writer)
108+
{
109+
// Not implemented for this example, instead we can write the field
110+
WriteField(writer);
111+
}
112+
113+
/// <summary>
114+
/// Used to read partial updates rather than synchronizing the full state on every change.
115+
/// </summary>
116+
/// <inheritdoc/>
99117
public override void ReadDelta(FastBufferReader reader, bool keepDirtyDelta)
100118
{
101119
// Not implemented for this example, instead we can read the field
102120
ReadField(reader);
103121
}
104122

105-
public override void WriteDelta(FastBufferWriter writer)
106-
{
107-
// Not implemented for this example, instead we can write the field
108-
WriteField(writer);
109-
}
110123
}
111124

112-
// Bare minimum example of generic NetworkVariableBase derived class
125+
/// <summary>
126+
/// Bare minimum example of generic NetworkVariableBase derived class
127+
/// </summary>
128+
/// <typeparam name="T">Generic type marker</typeparam>
113129
[Serializable]
114130
[GenerateSerializationForGenericParameter(0)]
115131
public class MyCustomGenericNetworkVariable<T> : NetworkVariableBase
116132
{
117-
// Managed list of class instances
133+
/// <summary>Managed list of class instances</summary>
118134
public List<T> SomeDataToSynchronize = new List<T>();
119135

120136
/// <summary>
@@ -152,21 +168,30 @@ public override void ReadField(FastBufferReader reader)
152168
}
153169
}
154170

155-
public override void ReadDelta(FastBufferReader reader, bool keepDirtyDelta)
156-
{
157-
// Not implemented for this example, instead we can read the field
158-
ReadField(reader);
159-
}
160-
171+
/// <summary>
172+
/// Used to write partial updates rather than synchronizing the full state on every change.
173+
/// </summary>
174+
/// <param name="writer">The stream to write the state to</param>
161175
public override void WriteDelta(FastBufferWriter writer)
162176
{
163177
// Not implemented for this example, instead we can write the field
164178
WriteField(writer);
165179
}
180+
181+
/// <summary>
182+
/// Used to read partial updates rather than synchronizing the full state on every change.
183+
/// </summary>
184+
/// <inheritdoc/>
185+
public override void ReadDelta(FastBufferReader reader, bool keepDirtyDelta)
186+
{
187+
// Not implemented for this example, instead we can read the field
188+
ReadField(reader);
189+
}
166190
}
167191

168-
// Example managed class used as the item type in the
169-
// MyCustomNetworkVariable.SomeDataToSynchronize list
192+
/// <summary>
193+
/// Example managed class used as the item type in <see cref="MyCustomNetworkVariable.SomeDataToSynchronize"/>
194+
/// </summary>
170195
[Serializable]
171196
public class SomeData
172197
{

0 commit comments

Comments
 (0)