Skip to content

Commit c16f683

Browse files
committed
AnticipatedNetworkTransform, HalfVector, NetworkDeltaPosition, and Editor folder
1 parent 090b6a7 commit c16f683

File tree

10 files changed

+93
-33
lines changed

10 files changed

+93
-33
lines changed

com.unity.netcode.gameobjects/Components/AnticipatedNetworkTransform.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,24 @@ namespace Unity.Netcode.Components
4646
[DefaultExecutionOrder(100000)] // this is needed to catch the update time after the transform was updated by user scripts
4747
public class AnticipatedNetworkTransform : NetworkTransform
4848
{
49+
/// <summary>
50+
/// Represents the state of a transform, including position, rotation, and scale.
51+
/// </summary>
4952
public struct TransformState
5053
{
54+
/// <summary>
55+
/// The position of the transform.
56+
/// </summary>
5157
public Vector3 Position;
58+
59+
/// <summary>
60+
/// The rotation of the transform.
61+
/// </summary>
5262
public Quaternion Rotation;
63+
64+
/// <summary>
65+
/// The scale of the transform.
66+
/// </summary>
5367
public Vector3 Scale;
5468
}
5569

@@ -242,6 +256,9 @@ public void AnticipateState(TransformState newState)
242256
m_CurrentSmoothTime = 0;
243257
}
244258

259+
/// <summary>
260+
/// Updates the AnticipatedNetworkTransform each frame.
261+
/// </summary>
245262
protected override void Update()
246263
{
247264
// If not spawned or this instance has authority, exit early
@@ -350,6 +367,13 @@ private void ResetAnticipatedState()
350367
m_CurrentSmoothTime = 0;
351368
}
352369

370+
/// <summary>
371+
/// Invoked when a new client joins (server and client sides).
372+
/// Server Side: Serializes as if we were teleporting (everything is sent via NetworkTransformState).
373+
/// Client Side: Adds the interpolated state which applies the NetworkTransformState as well.
374+
/// </summary>
375+
/// <typeparam name="T">The type of the serializer.</typeparam>
376+
/// <param name="serializer">The serializer used to serialize the state.</param>
353377
protected override void OnSynchronize<T>(ref BufferSerializer<T> serializer)
354378
{
355379
base.OnSynchronize(ref serializer);
@@ -361,6 +385,9 @@ protected override void OnSynchronize<T>(ref BufferSerializer<T> serializer)
361385
}
362386
}
363387

388+
/// <summary>
389+
/// Invoked when the NetworkObject is spawned.
390+
/// </summary>
364391
public override void OnNetworkSpawn()
365392
{
366393
base.OnNetworkSpawn();
@@ -373,6 +400,9 @@ public override void OnNetworkSpawn()
373400
NetworkManager.AnticipationSystem.AllAnticipatedObjects.Add(m_AnticipatedObject);
374401
}
375402

403+
/// <summary>
404+
/// Invoked when the NetworkObject is despawned.
405+
/// </summary>
376406
public override void OnNetworkDespawn()
377407
{
378408
if (m_AnticipatedObject != null)
@@ -387,6 +417,9 @@ public override void OnNetworkDespawn()
387417
base.OnNetworkDespawn();
388418
}
389419

420+
/// <summary>
421+
/// Invoked when the NetworkObject is destroyed.
422+
/// </summary>
390423
public override void OnDestroy()
391424
{
392425
if (m_AnticipatedObject != null)
@@ -438,19 +471,30 @@ public void Smooth(TransformState from, TransformState to, float durationSeconds
438471
m_CurrentSmoothTime = 0;
439472
}
440473

474+
/// <summary>
475+
/// Invoked just before the authoritative state is updated and pushed to non-authoritative instances.
476+
/// </summary>
441477
protected override void OnBeforeUpdateTransformState()
442478
{
443479
// this is called when new data comes from the server
444480
m_LastAuthorityUpdateCounter = NetworkManager.AnticipationSystem.LastAnticipationAck;
445481
m_OutstandingAuthorityChange = true;
446482
}
447483

484+
/// <summary>
485+
/// Invoked when the NetworkTransform state is updated.
486+
/// </summary>
487+
/// <param name="oldState">The previous state of the NetworkTransform.</param>
488+
/// <param name="newState">The new state of the NetworkTransform.</param>
448489
protected override void OnNetworkTransformStateUpdated(ref NetworkTransformState oldState, ref NetworkTransformState newState)
449490
{
450491
base.OnNetworkTransformStateUpdated(ref oldState, ref newState);
451492
ApplyAuthoritativeState();
452493
}
453494

495+
/// <summary>
496+
/// Invoked whenever the transform has been updated.
497+
/// </summary>
454498
protected override void OnTransformUpdated()
455499
{
456500
if (CanCommitToTransform || m_AnticipatedObject == null)

com.unity.netcode.gameobjects/Components/HalfVector3.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ private void SerializeRead(FastBufferReader reader)
7777
/// <summary>
7878
/// The serialization implementation of <see cref="INetworkSerializable"/>.
7979
/// </summary>
80+
/// <typeparam name="T">The type of the serializer.</typeparam>
81+
/// <param name="serializer">The serializer used to serialize or deserialize the state.</param>
8082
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
8183
{
8284
if (serializer.IsReader)

com.unity.netcode.gameobjects/Components/HalfVector4.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ private void SerializeRead(FastBufferReader reader)
6161
/// <summary>
6262
/// The serialization implementation of <see cref="INetworkSerializable"/>.
6363
/// </summary>
64+
/// <typeparam name="T">The type of the serializer.</typeparam>
65+
/// <param name="serializer">The serializer used to serialize or deserialize the state.</param>
6466
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
6567
{
6668
if (serializer.IsReader)

com.unity.netcode.gameobjects/Components/NetworkDeltaPosition.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public struct NetworkDeltaPosition : INetworkSerializable
3030
/// <summary>
3131
/// The serialization implementation of <see cref="INetworkSerializable"/>
3232
/// </summary>
33+
/// <typeparam name="T">The type of the serializer.</typeparam>
34+
/// <param name="serializer">The serializer used to serialize or deserialize the state.</param>
3335
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
3436
{
3537
if (!SynchronizeBase)
@@ -105,6 +107,7 @@ public Vector3 GetFullPosition()
105107
/// <remarks>
106108
/// Only applies to the authoritative side for <see cref="NetworkTransform"/> instances.
107109
/// </remarks>
110+
/// <returns>The current delta position as a <see cref="Vector3"/> with half float precision.</returns>
108111
[MethodImpl(MethodImplOptions.AggressiveInlining)]
109112
public Vector3 GetConvertedDelta()
110113
{
@@ -120,6 +123,7 @@ public Vector3 GetConvertedDelta()
120123
/// Precision loss adjustments are one network tick behind on the
121124
/// non-authoritative side.
122125
/// </remarks>
126+
/// <returns>The current delta position as a <see cref="Vector3"/>.</returns>
123127
[MethodImpl(MethodImplOptions.AggressiveInlining)]
124128
public Vector3 GetDeltaPosition()
125129
{

com.unity.netcode.gameobjects/Editor/AnticipatedNetworkTransformEditor.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ namespace Unity.Netcode.Editor
99
[CustomEditor(typeof(AnticipatedNetworkTransform), true)]
1010
public class AnticipatedNetworkTransformEditor : NetworkTransformEditor
1111
{
12+
/// <summary>
13+
/// Gets a value indicating whether the interpolate value should be hidden in the inspector.
14+
/// </summary>
1215
public override bool HideInterpolateValue => true;
1316
}
1417
}

com.unity.netcode.gameobjects/Editor/Configuration/NetcodeForGameObjectsProjectSettings.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,30 @@
33

44
namespace Unity.Netcode.Editor.Configuration
55
{
6+
/// <summary>
7+
/// Project settings for Netcode for GameObjects.
8+
/// </summary>
69
[FilePath("ProjectSettings/NetcodeForGameObjects.asset", FilePathAttribute.Location.ProjectFolder)]
710
public class NetcodeForGameObjectsProjectSettings : ScriptableSingleton<NetcodeForGameObjectsProjectSettings>
811
{
12+
/// <summary>
13+
/// The default path for network prefabs.
14+
/// </summary>
915
internal static readonly string DefaultNetworkPrefabsPath = "Assets/DefaultNetworkPrefabs.asset";
16+
17+
/// <summary>
18+
/// The path to the network prefabs.
19+
/// </summary>
1020
[SerializeField] public string NetworkPrefabsPath = DefaultNetworkPrefabsPath;
21+
22+
/// <summary>
23+
/// A temporary path to the network prefabs.
24+
/// </summary>
1125
public string TempNetworkPrefabsPath;
1226

27+
/// <summary>
28+
/// Called when the script instance is being loaded.
29+
/// </summary>
1330
private void OnEnable()
1431
{
1532
if (NetworkPrefabsPath == "")
@@ -19,9 +36,15 @@ private void OnEnable()
1936
TempNetworkPrefabsPath = NetworkPrefabsPath;
2037
}
2138

39+
/// <summary>
40+
/// Indicates whether to generate default network prefabs.
41+
/// </summary>
2242
[SerializeField]
2343
public bool GenerateDefaultNetworkPrefabs = true;
2444

45+
/// <summary>
46+
/// Saves the project settings.
47+
/// </summary>
2548
internal void SaveSettings()
2649
{
2750
Save(true);

com.unity.netcode.gameobjects/Editor/Configuration/NetworkPrefabProcessor.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ namespace Unity.Netcode.Editor.Configuration
99
/// </summary>
1010
public class NetworkPrefabProcessor : AssetPostprocessor
1111
{
12+
/// <summary>
13+
/// Gets or sets the default path for network prefabs.
14+
/// </summary>
1215
public static string DefaultNetworkPrefabsPath
1316
{
1417
get

com.unity.netcode.gameobjects/Editor/Configuration/NetworkPrefabsEditor.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@
44

55
namespace Unity.Netcode.Editor
66
{
7+
/// <summary>
8+
/// Custom editor for the <see cref="NetworkPrefabsList"/> class.
9+
/// </summary>
710
[CustomEditor(typeof(NetworkPrefabsList), true)]
811
[CanEditMultipleObjects]
912
public class NetworkPrefabsEditor : UnityEditor.Editor
1013
{
1114
private ReorderableList m_NetworkPrefabsList;
1215
private SerializedProperty m_IsDefaultBool;
1316

17+
/// <summary>
18+
/// Initializes the custom editor when it is enabled.
19+
/// </summary>
1420
private void OnEnable()
1521
{
1622
m_IsDefaultBool = serializedObject.FindProperty(nameof(NetworkPrefabsList.IsDefault));

com.unity.netcode.gameobjects/Editor/NetworkTransformEditor.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,14 @@ public class NetworkTransformEditor : UnityEditor.Editor
3737
private static GUIContent s_RotationLabel = EditorGUIUtility.TrTextContent("Rotation");
3838
private static GUIContent s_ScaleLabel = EditorGUIUtility.TrTextContent("Scale");
3939

40+
/// <summary>
41+
/// Gets a value indicating whether the interpolate value should be hidden in the inspector.
42+
/// </summary>
4043
public virtual bool HideInterpolateValue => false;
4144

42-
/// <inheritdoc cref="UnityEditor.Editor.OnEnable"/>
45+
/// <summary>
46+
/// Called when the editor is enabled.
47+
/// </summary>
4348
public void OnEnable()
4449
{
4550
m_UseUnreliableDeltas = serializedObject.FindProperty(nameof(NetworkTransform.UseUnreliableDeltas));

pvpExceptions.json

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,6 @@
1515
},
1616
"PVP-151-1": {
1717
"errors": [
18-
"Unity.Netcode.Components.AnticipatedNetworkTransform: void Update(): undocumented",
19-
"Unity.Netcode.Components.AnticipatedNetworkTransform: void OnSynchronize(ref BufferSerializer<T>): undocumented",
20-
"Unity.Netcode.Components.AnticipatedNetworkTransform: void OnNetworkSpawn(): undocumented",
21-
"Unity.Netcode.Components.AnticipatedNetworkTransform: void OnNetworkDespawn(): undocumented",
22-
"Unity.Netcode.Components.AnticipatedNetworkTransform: void OnDestroy(): undocumented",
23-
"Unity.Netcode.Components.AnticipatedNetworkTransform: void OnBeforeUpdateTransformState(): undocumented",
24-
"Unity.Netcode.Components.AnticipatedNetworkTransform: void OnNetworkTransformStateUpdated(ref NetworkTransformState, ref NetworkTransformState): undocumented",
25-
"Unity.Netcode.Components.AnticipatedNetworkTransform: void OnTransformUpdated(): undocumented",
26-
"Unity.Netcode.Components.AnticipatedNetworkTransform.TransformState: undocumented",
27-
"Unity.Netcode.Components.AnticipatedNetworkTransform.TransformState: Position: undocumented",
28-
"Unity.Netcode.Components.AnticipatedNetworkTransform.TransformState: Rotation: undocumented",
29-
"Unity.Netcode.Components.AnticipatedNetworkTransform.TransformState: Scale: undocumented",
30-
"Unity.Netcode.Components.HalfVector3: XML is not well-formed: End tag 'remarks' does not match the start tag 'ushort'",
31-
"Unity.Netcode.Components.HalfVector3: void NetworkSerialize(BufferSerializer<T>): missing <param name=\"serializer\">",
32-
"Unity.Netcode.Components.HalfVector3: void NetworkSerialize(BufferSerializer<T>): missing <typeparam name=\"T\">",
33-
"Unity.Netcode.Components.HalfVector4: XML is not well-formed: End tag 'remarks' does not match the start tag 'ushort'",
34-
"Unity.Netcode.Components.HalfVector4: void NetworkSerialize(BufferSerializer<T>): missing <param name=\"serializer\">",
35-
"Unity.Netcode.Components.HalfVector4: void NetworkSerialize(BufferSerializer<T>): missing <typeparam name=\"T\">",
36-
"Unity.Netcode.Components.NetworkDeltaPosition: void NetworkSerialize(BufferSerializer<T>): missing <param name=\"serializer\">",
37-
"Unity.Netcode.Components.NetworkDeltaPosition: void NetworkSerialize(BufferSerializer<T>): missing <typeparam name=\"T\">",
38-
"Unity.Netcode.Components.NetworkDeltaPosition: Vector3 GetConvertedDelta(): missing <returns>",
39-
"Unity.Netcode.Components.NetworkDeltaPosition: Vector3 GetDeltaPosition(): missing <returns>",
40-
"Unity.Netcode.Editor.AnticipatedNetworkTransformEditor: HideInterpolateValue: undocumented",
41-
"Unity.Netcode.Editor.Configuration.NetcodeForGameObjectsProjectSettings: undocumented",
42-
"Unity.Netcode.Editor.Configuration.NetcodeForGameObjectsProjectSettings: NetworkPrefabsPath: undocumented",
43-
"Unity.Netcode.Editor.Configuration.NetcodeForGameObjectsProjectSettings: TempNetworkPrefabsPath: undocumented",
44-
"Unity.Netcode.Editor.Configuration.NetcodeForGameObjectsProjectSettings: GenerateDefaultNetworkPrefabs: undocumented",
45-
"Unity.Netcode.Editor.Configuration.NetworkPrefabProcessor: DefaultNetworkPrefabsPath: undocumented",
46-
"Unity.Netcode.Editor.NetworkPrefabsEditor: undocumented",
47-
"Unity.Netcode.Editor.NetworkPrefabsEditor: void OnInspectorGUI(): undocumented",
48-
"Unity.Netcode.Editor.NetworkTransformEditor: HideInterpolateValue: undocumented",
49-
"Unity.Netcode.Editor.NetworkTransformEditor: void OnEnable(): missing <summary>",
5018
"Unity.Netcode.NetworkConfig: Prefabs: undocumented",
5119
"Unity.Netcode.NetworkPrefab: bool Equals(NetworkPrefab): undocumented",
5220
"Unity.Netcode.NetworkPrefab: SourcePrefabGlobalObjectIdHash: undocumented",

0 commit comments

Comments
 (0)