Skip to content

Commit d917530

Browse files
update
adding xml api documentation, tooltips, and some editor adjustments.
1 parent e5dc365 commit d917530

File tree

3 files changed

+111
-15
lines changed

3 files changed

+111
-15
lines changed

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

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public class NetworkTransformEditor : NetcodeEditorBase<NetworkTransform>
3232
private SerializedProperty m_RotationInterpolationTypeProperty;
3333
private SerializedProperty m_ScaleInterpolationTypeProperty;
3434

35+
private SerializedProperty m_PositionMaximumInterpolationTimeProperty;
36+
private SerializedProperty m_RotationMaximumInterpolationTimeProperty;
37+
private SerializedProperty m_ScaleMaximumInterpolationTimeProperty;
38+
3539
private SerializedProperty m_UseQuaternionSynchronization;
3640
private SerializedProperty m_UseQuaternionCompression;
3741
private SerializedProperty m_UseHalfFloatPrecision;
@@ -66,8 +70,11 @@ public override void OnEnable()
6670
m_InterpolateProperty = serializedObject.FindProperty(nameof(NetworkTransform.Interpolate));
6771

6872
m_PositionInterpolationTypeProperty = serializedObject.FindProperty(nameof(NetworkTransform.PositionInterpolationType));
73+
m_PositionMaximumInterpolationTimeProperty = serializedObject.FindProperty(nameof(NetworkTransform.PositionMaxInterpolationTime));
6974
m_RotationInterpolationTypeProperty = serializedObject.FindProperty(nameof(NetworkTransform.RotationInterpolationType));
75+
m_RotationMaximumInterpolationTimeProperty = serializedObject.FindProperty(nameof(NetworkTransform.RotationMaxInterpolationTime));
7076
m_ScaleInterpolationTypeProperty = serializedObject.FindProperty(nameof(NetworkTransform.ScaleInterpolationType));
77+
m_ScaleMaximumInterpolationTimeProperty = serializedObject.FindProperty(nameof(NetworkTransform.ScaleMaxInterpolationTime));
7178

7279

7380
m_UseQuaternionSynchronization = serializedObject.FindProperty(nameof(NetworkTransform.UseQuaternionSynchronization));
@@ -150,9 +157,21 @@ private void DisplayNetworkTransformProperties()
150157
}
151158
EditorGUILayout.Space();
152159
EditorGUILayout.LabelField("Thresholds", EditorStyles.boldLabel);
153-
EditorGUILayout.PropertyField(m_PositionThresholdProperty);
154-
EditorGUILayout.PropertyField(m_RotAngleThresholdProperty);
155-
EditorGUILayout.PropertyField(m_ScaleThresholdProperty);
160+
if (networkTransform.SynchronizePosition)
161+
{
162+
EditorGUILayout.PropertyField(m_PositionThresholdProperty);
163+
}
164+
165+
if (networkTransform.SynchronizeRotation)
166+
{
167+
EditorGUILayout.PropertyField(m_RotAngleThresholdProperty);
168+
}
169+
170+
if (networkTransform.SynchronizeScale)
171+
{
172+
EditorGUILayout.PropertyField(m_ScaleThresholdProperty);
173+
}
174+
156175
EditorGUILayout.Space();
157176
EditorGUILayout.LabelField("Delivery", EditorStyles.boldLabel);
158177
EditorGUILayout.PropertyField(m_TickSyncChildren);
@@ -173,18 +192,37 @@ private void DisplayNetworkTransformProperties()
173192
if (networkTransform.SynchronizePosition)
174193
{
175194
EditorGUILayout.PropertyField(m_PositionInterpolationTypeProperty);
195+
// Only display when using Lerp.
196+
if (networkTransform.PositionInterpolationType == NetworkTransform.InterpolationTypes.Lerp)
197+
{
198+
EditorGUILayout.PropertyField(m_SlerpPosition);
199+
EditorGUILayout.PropertyField(m_PositionMaximumInterpolationTimeProperty);
200+
}
176201
}
177202
if (networkTransform.SynchronizeRotation)
178203
{
179204
EditorGUILayout.PropertyField(m_RotationInterpolationTypeProperty);
205+
206+
// Only display when using Lerp.
207+
if (networkTransform.RotationInterpolationType == NetworkTransform.InterpolationTypes.Lerp)
208+
{
209+
EditorGUILayout.PropertyField(m_RotationMaximumInterpolationTimeProperty);
210+
}
180211
}
181212
if (networkTransform.SynchronizeScale)
182213
{
183214
EditorGUILayout.PropertyField(m_ScaleInterpolationTypeProperty);
215+
// Only display when using Lerp.
216+
if (networkTransform.ScaleInterpolationType == NetworkTransform.InterpolationTypes.Lerp)
217+
{
218+
EditorGUILayout.PropertyField(m_ScaleMaximumInterpolationTimeProperty);
219+
}
184220
}
185221
}
222+
186223
}
187-
EditorGUILayout.PropertyField(m_SlerpPosition);
224+
225+
188226
EditorGUILayout.PropertyField(m_UseQuaternionSynchronization);
189227
if (m_UseQuaternionSynchronization.boolValue)
190228
{

com.unity.netcode.gameobjects/Runtime/Components/Interpolator/BufferedLinearInterpolator.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,15 @@ public void Reset(T currentValue)
134134

135135
private const double k_SmallValue = 9.999999439624929E-11; // copied from Vector3's equal operator
136136

137-
138137
/// <summary>
139-
/// There's two factors affecting interpolation: buffering (set in NetworkManager's NetworkTimeSystem) and interpolation time, which is the amount of time it'll take to reach the target. This is to affect the second one.
138+
/// Determines how much smoothing will be applied to the 2nd lerp when using the <see cref="Update(float, double, double)"/> (i.e. lerping and not smooth dampening).
140139
/// </summary>
140+
/// <remarks>
141+
/// There's two factors affecting interpolation: <br />
142+
/// - Buffering: Which can be adjusted in set in the <see cref="NetworkManager.NetworkTimeSystem"/>.<br />
143+
/// - Interpolation time: The divisor applied to delta time where the quotient is used as the lerp time.
144+
/// </remarks>
145+
[Range(0.016f, 1.0f)]
141146
public float MaximumInterpolationTime = 0.1f;
142147

143148
/// <summary>
@@ -435,7 +440,10 @@ public T Update(float deltaTime, double renderTime, double serverTime)
435440
}
436441
}
437442
var target = Interpolate(InterpolateState.PreviousValue, InterpolateState.Target.Value.Item, t);
438-
InterpolateState.CurrentValue = Interpolate(InterpolateState.CurrentValue, target, deltaTime / MaximumInterpolationTime);
443+
444+
// Assure our MaximumInterpolationTime is valid and that the second lerp time ranges between deltaTime and 1.0f.
445+
var secondLerpTime = Mathf.Clamp(deltaTime / Mathf.Max(deltaTime, MaximumInterpolationTime), deltaTime, 1.0f);
446+
InterpolateState.CurrentValue = Interpolate(InterpolateState.CurrentValue, target, secondLerpTime);
439447
}
440448
m_NbItemsReceivedThisFrame = 0;
441449
return InterpolateState.CurrentValue;

com.unity.netcode.gameobjects/Runtime/Components/NetworkTransform.cs

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -937,55 +937,105 @@ public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReade
937937
#region PROPERTIES AND GENERAL METHODS
938938

939939
/// <summary>
940-
/// The two ways to smooth during interpolation.
940+
/// The different interpolation types used with <see cref="BufferedLinearInterpolator{T}"/> to help smooth interpolation results.
941941
/// </summary>
942942
public enum InterpolationTypes
943943
{
944944
/// <summary>
945945
/// Uses lerping and yields a linear progression between two values.
946946
/// </summary>
947+
/// <remarks>
948+
/// For more information:<br />
949+
/// - <see cref="PositionMaxInterpolationTime"/><br />
950+
/// - <see cref="RotationMaxInterpolationTime"/><br />
951+
/// - <see cref="ScaleMaxInterpolationTime"/><br />
952+
/// </remarks>
947953
Lerp,
948954
/// <summary>
949-
/// Uses a smooth dampening approach and is recommended when <see cref="NetworkRigidbodyBase.UseRigidBodyForMotion"/> is enabled.
955+
/// Uses a smooth dampening approach for interpolating between two data points and adjusts based on rate of change.
950956
/// </summary>
957+
/// <remarks>
958+
/// Unlike <see cref="Lerp"/>, there are no additional values needed to be adjusted for this interpolation type.
959+
/// </remarks>
951960
SmoothDampening
952961
}
953962

954963
/// <summary>
955964
/// The position interpolation type to use for the <see cref="NetworkTransform"/> instance.
956965
/// </summary>
957966
/// <remarks>
958-
/// For more details review <see cref="InterpolationTypes"/>.
967+
/// - <see cref="InterpolationTypes.Lerp"/> yields a traditional linear result.<br />
968+
/// - <see cref="InterpolationTypes.SmoothDampening"/> adjusts based on the rate of change.<br />
969+
/// - You can have mixed interpolation types between position, rotation, and scale on the same <see cref="NetworkTransform"/> instance.<br />
970+
/// - You can change the interpolation type during runtime, but changing between <see cref="InterpolationTypes"/> can result in a slight stutter if the object is in motion.<br />
959971
/// </remarks>
972+
[Tooltip("Lerping yields a traditional linear result where smooth dampening will adjust based on the rate of change. You can mix interpolation types for position, rotation, and scale.")]
960973
public InterpolationTypes PositionInterpolationType;
961974

962975
/// <summary>
963976
/// The rotation interpolation type to use for the <see cref="NetworkTransform"/> instance.
964977
/// </summary>
965978
/// <remarks>
966-
/// For more details review <see cref="InterpolationTypes"/>.
979+
/// - <see cref="InterpolationTypes.Lerp"/> yields a traditional linear result.<br />
980+
/// - <see cref="InterpolationTypes.SmoothDampening"/> adjusts based on the rate of change.<br />
981+
/// - You can have mixed interpolation types between position, rotation, and scale on the same <see cref="NetworkTransform"/> instance.<br />
982+
/// - You can change the interpolation type during runtime, but changing between <see cref="InterpolationTypes"/> can result in a slight stutter if the object is in motion.<br />
967983
/// </remarks>
984+
[Tooltip("Lerping yields a traditional linear result where smooth dampening will adjust based on the rate of change. You can mix interpolation types for position, rotation, and scale.")]
968985
public InterpolationTypes RotationInterpolationType;
969986

970987
/// <summary>
971988
/// The scale interpolation type to use for the <see cref="NetworkTransform"/> instance.
972989
/// </summary>
973990
/// <remarks>
974-
/// For more details review <see cref="InterpolationTypes"/>.
991+
/// - <see cref="InterpolationTypes.Lerp"/> yields a traditional linear result.<br />
992+
/// - <see cref="InterpolationTypes.SmoothDampening"/> adjusts based on the rate of change.<br />
993+
/// - You can have mixed interpolation types between position, rotation, and scale on the same <see cref="NetworkTransform"/> instance.<br />
994+
/// - You can change the interpolation type during runtime, but changing between <see cref="InterpolationTypes"/> can result in a slight stutter if the object is in motion.<br />
975995
/// </remarks>
996+
[Tooltip("Lerping yields a traditional linear result where smooth dampening will adjust based on the rate of change. You can mix interpolation types for position, rotation, and scale.")]
976997
public InterpolationTypes ScaleInterpolationType;
977998

978999
/// <summary>
979-
/// When <see cref="Interpolate"/> is enabled and using <see cref="InterpolationTypes.Lerp"/>, this adjust the maximum interpolation time for position.
1000+
/// The position interoplation time divisor applied to the current delta time (dividend) where the quotient yields the time used for the second smoothing lerp.
1001+
/// - The lower the value the smoother, but can result in lost data points (i.e. quick changes in direct). <br />
1002+
/// - The higher the value the more accurate/precise, but can result in slight stutter (i.e. due to jitter, latency, or a high threshold value). <br />
1003+
/// - This value can be adjusted during runtime in the event you want to dynamically adjust it based on some other value (i.e. velocity or the like).
9801004
/// </summary>
1005+
/// <remarks>
1006+
/// - Only used When <see cref="Interpolate"/> is enabled and using <see cref="InterpolationTypes.Lerp"/>. <br />
1007+
/// - The quotient will be clamped to a value that ranges from 1.0f to the current delta time (i.e. <see cref="Time.deltaTime"/> or <see cref="Time.fixedDeltaTime"/>)
1008+
/// </remarks>
1009+
[Tooltip("The lower the value the smoother, but can result in lost data points (i.e. quick changes in direct). The higher the value the more accurate/precise, but can result in slight stutter (i.e. due to jitter, latency, or a high threshold value).")]
1010+
[Range(0.01f, 1.0f)]
9811011
public float PositionMaxInterpolationTime = 0.1f;
1012+
9821013
/// <summary>
983-
/// When <see cref="Interpolate"/> is enabled and using <see cref="InterpolationTypes.Lerp"/>, this adjust the maximum interpolation time for rotation.
1014+
/// The rotation interoplation time divisor applied to the current delta time (dividend) where the quotient yields the time used for the second smoothing lerp.
1015+
/// - The lower the value the smoother, but can result in lost data points (i.e. quick changes in direct). <br />
1016+
/// - The higher the value the more accurate/precise, but can result in slight stutter (i.e. due to jitter, latency, or a high threshold value). <br />
1017+
/// - This value can be adjusted during runtime in the event you want to dynamically adjust it based on some other value (i.e. velocity or the like).
9841018
/// </summary>
1019+
/// <remarks>
1020+
/// - Only used When <see cref="Interpolate"/> is enabled and using <see cref="InterpolationTypes.Lerp"/>. <br />
1021+
/// - The quotient will be clamped to a value that ranges from 1.0f to the current delta time (i.e. <see cref="Time.deltaTime"/> or <see cref="Time.fixedDeltaTime"/>)
1022+
/// </remarks>
1023+
[Tooltip("The lower the value the smoother, but can result in lost data points (i.e. quick changes in direct). The higher the value the more accurate/precise, but can result in slight stutter (i.e. due to jitter, latency, or a high threshold value).")]
1024+
[Range(0.01f, 1.0f)]
9851025
public float RotationMaxInterpolationTime = 0.1f;
1026+
9861027
/// <summary>
987-
/// When <see cref="Interpolate"/> is enabled and using <see cref="InterpolationTypes.Lerp"/>, this adjust the maximum interpolation time for scale.
1028+
/// The scale interoplation time divisor applied to the current delta time (dividend) where the quotient yields the time used for the second smoothing lerp.
1029+
/// - The lower the value the smoother, but can result in lost data points (i.e. quick changes in direct). <br />
1030+
/// - The higher the value the more accurate/precise, but can result in slight stutter (i.e. due to jitter, latency, or a high threshold value). <br />
1031+
/// - This value can be adjusted during runtime in the event you want to dynamically adjust it based on some other value (i.e. velocity or the like).
9881032
/// </summary>
1033+
/// <remarks>
1034+
/// - Only used When <see cref="Interpolate"/> is enabled and using <see cref="InterpolationTypes.Lerp"/>. <br />
1035+
/// - The quotient will be clamped to a value that ranges from 1.0f to the current delta time (i.e. <see cref="Time.deltaTime"/> or <see cref="Time.fixedDeltaTime"/>)
1036+
/// </remarks>
1037+
[Tooltip("The lower the value the smoother, but can result in lost data points (i.e. quick changes in direct). The higher the value the more accurate/precise, but can result in slight stutter (i.e. due to jitter, latency, or a high threshold value).")]
1038+
[Range(0.01f, 1.0f)]
9891039
public float ScaleMaxInterpolationTime = 0.1f;
9901040

9911041
public enum AuthorityModes

0 commit comments

Comments
 (0)