com.unity.netcode.gameobjects@2.0.0
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com). ## [2.0.0] - 2024-09-12 ### Added - Added tooltips for all of the `NetworkObject` component's properties. (#3052) - Added message size validation to named and unnamed message sending functions for better error messages. (#3049) - Added "Check for NetworkObject Component" property to the Multiplayer->Netcode for GameObjects project settings. When disabled, this will bypass the in-editor `NetworkObject` check on `NetworkBehaviour` components. (#3031) - Added `NetworkTransform.SwitchTransformSpaceWhenParented` property that, when enabled, will handle the world to local, local to world, and local to local transform space transitions when interpolation is enabled. (#3013) - Added `NetworkTransform.TickSyncChildren` that, when enabled, will tick synchronize nested and/or child `NetworkTransform` components to eliminate any potential visual jittering that could occur if the `NetworkTransform` instances get into a state where their state updates are landing on different network ticks. (#3013) - Added `NetworkObject.AllowOwnerToParent` property to provide the ability to allow clients to parent owned objects when running in a client-server network topology. (#3013) - Added `NetworkObject.SyncOwnerTransformWhenParented` property to provide a way to disable applying the server's transform information in the parenting message on the client owner instance which can be useful for owner authoritative motion models. (#3013) - Added `NetcodeEditorBase` editor helper class to provide easier modification and extension of the SDK's components. (#3013) ### Fixed - Fixed issue where `NetworkAnimator` would send updates to non-observer clients. (#3057) - Fixed issue where an exception could occur when receiving a universal RPC for a `NetworkObject` that has been despawned. (#3052) - Fixed issue where a NetworkObject hidden from a client that is then promoted to be session owner was not being synchronized with newly joining clients.(#3051) - Fixed issue where clients could have a wrong time delta on `NetworkVariableBase` which could prevent from sending delta state updates. (#3045) - Fixed issue where setting a prefab hash value during connection approval but not having a player prefab assigned could cause an exception when spawning a player. (#3042) - Fixed issue where the `NetworkSpawnManager.HandleNetworkObjectShow` could throw an exception if one of the `NetworkObject` components to show was destroyed during the same frame. (#3030) - Fixed issue where the `NetworkManagerHelper` was continuing to check for hierarchy changes when in play mode. (#3026) - Fixed issue with newly/late joined clients and `NetworkTransform` synchronization of parented `NetworkObject` instances. (#3013) - Fixed issue with smooth transitions between transform spaces when interpolation is enabled (requires `NetworkTransform.SwitchTransformSpaceWhenParented` to be enabled). (#3013) ### Changed - Changed `NetworkTransformEditor` now uses `NetworkTransform` as the base type class to assure it doesn't display a foldout group when using the base `NetworkTransform` component class. (#3052) - Changed `NetworkAnimator.Awake` is now a protected virtual method. (#3052) - Changed when invoking `NetworkManager.ConnectionManager.DisconnectClient` during a distributed authority session a more appropriate message is logged. (#3052) - Changed `NetworkTransformEditor` so it now derives from `NetcodeEditorBase`. (#3013) - Changed `NetworkRigidbodyBaseEditor` so it now derives from `NetcodeEditorBase`. (#3013) - Changed `NetworkManagerEditor` so it now derives from `NetcodeEditorBase`. (#3013)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#if COM_UNITY_MODULES_PHYSICS
|
||||
#if COM_UNITY_MODULES_PHYSICS || COM_UNITY_MODULES_PHYSICS2D
|
||||
using System.Runtime.CompilerServices;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -14,6 +14,12 @@ namespace Unity.Netcode.Components
|
||||
/// </remarks>
|
||||
public abstract class NetworkRigidbodyBase : NetworkBehaviour
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[HideInInspector]
|
||||
[SerializeField]
|
||||
internal bool NetworkRigidbodyBaseExpanded;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// When enabled, the associated <see cref="NetworkTransform"/> will use the Rigidbody/Rigidbody2D to apply and synchronize changes in position, rotation, and
|
||||
/// allows for the use of Rigidbody interpolation/extrapolation.
|
||||
@@ -42,8 +48,10 @@ namespace Unity.Netcode.Components
|
||||
private bool m_IsRigidbody2D => RigidbodyType == RigidbodyTypes.Rigidbody2D;
|
||||
// Used to cache the authority state of this Rigidbody during the last frame
|
||||
private bool m_IsAuthority;
|
||||
private Rigidbody m_Rigidbody;
|
||||
private Rigidbody2D m_Rigidbody2D;
|
||||
|
||||
protected internal Rigidbody m_InternalRigidbody { get; private set; }
|
||||
protected internal Rigidbody2D m_InternalRigidbody2D { get; private set; }
|
||||
|
||||
internal NetworkTransform NetworkTransform;
|
||||
private float m_TickFrequency;
|
||||
private float m_TickRate;
|
||||
@@ -87,18 +95,18 @@ namespace Unity.Netcode.Components
|
||||
return;
|
||||
}
|
||||
RigidbodyType = rigidbodyType;
|
||||
m_Rigidbody2D = rigidbody2D;
|
||||
m_Rigidbody = rigidbody;
|
||||
m_InternalRigidbody2D = rigidbody2D;
|
||||
m_InternalRigidbody = rigidbody;
|
||||
NetworkTransform = networkTransform;
|
||||
|
||||
if (m_IsRigidbody2D && m_Rigidbody2D == null)
|
||||
if (m_IsRigidbody2D && m_InternalRigidbody2D == null)
|
||||
{
|
||||
m_Rigidbody2D = GetComponent<Rigidbody2D>();
|
||||
m_InternalRigidbody2D = GetComponent<Rigidbody2D>();
|
||||
|
||||
}
|
||||
else if (m_Rigidbody == null)
|
||||
else if (m_InternalRigidbody == null)
|
||||
{
|
||||
m_Rigidbody = GetComponent<Rigidbody>();
|
||||
m_InternalRigidbody = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
SetOriginalInterpolation();
|
||||
@@ -178,14 +186,14 @@ namespace Unity.Netcode.Components
|
||||
if (m_IsRigidbody2D)
|
||||
{
|
||||
#if COM_UNITY_MODULES_PHYSICS2D_LINEAR
|
||||
m_Rigidbody2D.linearVelocity = linearVelocity;
|
||||
m_InternalRigidbody2D.linearVelocity = linearVelocity;
|
||||
#else
|
||||
m_Rigidbody2D.velocity = linearVelocity;
|
||||
m_InternalRigidbody2D.velocity = linearVelocity;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Rigidbody.linearVelocity = linearVelocity;
|
||||
m_InternalRigidbody.linearVelocity = linearVelocity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,14 +210,14 @@ namespace Unity.Netcode.Components
|
||||
if (m_IsRigidbody2D)
|
||||
{
|
||||
#if COM_UNITY_MODULES_PHYSICS2D_LINEAR
|
||||
return m_Rigidbody2D.linearVelocity;
|
||||
return m_InternalRigidbody2D.linearVelocity;
|
||||
#else
|
||||
return m_Rigidbody2D.velocity;
|
||||
return m_InternalRigidbody2D.velocity;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_Rigidbody.linearVelocity;
|
||||
return m_InternalRigidbody.linearVelocity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,11 +234,11 @@ namespace Unity.Netcode.Components
|
||||
{
|
||||
if (m_IsRigidbody2D)
|
||||
{
|
||||
m_Rigidbody2D.angularVelocity = angularVelocity.z;
|
||||
m_InternalRigidbody2D.angularVelocity = angularVelocity.z;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Rigidbody.angularVelocity = angularVelocity;
|
||||
m_InternalRigidbody.angularVelocity = angularVelocity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,11 +254,11 @@ namespace Unity.Netcode.Components
|
||||
{
|
||||
if (m_IsRigidbody2D)
|
||||
{
|
||||
return Vector3.forward * m_Rigidbody2D.angularVelocity;
|
||||
return Vector3.forward * m_InternalRigidbody2D.angularVelocity;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_Rigidbody.angularVelocity;
|
||||
return m_InternalRigidbody.angularVelocity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,11 +271,11 @@ namespace Unity.Netcode.Components
|
||||
{
|
||||
if (m_IsRigidbody2D)
|
||||
{
|
||||
return m_Rigidbody2D.position;
|
||||
return m_InternalRigidbody2D.position;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_Rigidbody.position;
|
||||
return m_InternalRigidbody.position;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,13 +290,13 @@ namespace Unity.Netcode.Components
|
||||
{
|
||||
var quaternion = Quaternion.identity;
|
||||
var angles = quaternion.eulerAngles;
|
||||
angles.z = m_Rigidbody2D.rotation;
|
||||
angles.z = m_InternalRigidbody2D.rotation;
|
||||
quaternion.eulerAngles = angles;
|
||||
return quaternion;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_Rigidbody.rotation;
|
||||
return m_InternalRigidbody.rotation;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,11 +309,11 @@ namespace Unity.Netcode.Components
|
||||
{
|
||||
if (m_IsRigidbody2D)
|
||||
{
|
||||
m_Rigidbody2D.MovePosition(position);
|
||||
m_InternalRigidbody2D.MovePosition(position);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Rigidbody.MovePosition(position);
|
||||
m_InternalRigidbody.MovePosition(position);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,11 +326,11 @@ namespace Unity.Netcode.Components
|
||||
{
|
||||
if (m_IsRigidbody2D)
|
||||
{
|
||||
m_Rigidbody2D.position = position;
|
||||
m_InternalRigidbody2D.position = position;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Rigidbody.position = position;
|
||||
m_InternalRigidbody.position = position;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,13 +342,13 @@ namespace Unity.Netcode.Components
|
||||
{
|
||||
if (m_IsRigidbody2D)
|
||||
{
|
||||
m_Rigidbody2D.position = transform.position;
|
||||
m_Rigidbody2D.rotation = transform.eulerAngles.z;
|
||||
m_InternalRigidbody2D.position = transform.position;
|
||||
m_InternalRigidbody2D.rotation = transform.eulerAngles.z;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Rigidbody.position = transform.position;
|
||||
m_Rigidbody.rotation = transform.rotation;
|
||||
m_InternalRigidbody.position = transform.position;
|
||||
m_InternalRigidbody.rotation = transform.rotation;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -358,9 +366,9 @@ namespace Unity.Netcode.Components
|
||||
{
|
||||
var quaternion = Quaternion.identity;
|
||||
var angles = quaternion.eulerAngles;
|
||||
angles.z = m_Rigidbody2D.rotation;
|
||||
angles.z = m_InternalRigidbody2D.rotation;
|
||||
quaternion.eulerAngles = angles;
|
||||
m_Rigidbody2D.MoveRotation(quaternion);
|
||||
m_InternalRigidbody2D.MoveRotation(quaternion);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -375,7 +383,7 @@ namespace Unity.Netcode.Components
|
||||
{
|
||||
rotation.Normalize();
|
||||
}
|
||||
m_Rigidbody.MoveRotation(rotation);
|
||||
m_InternalRigidbody.MoveRotation(rotation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -388,11 +396,11 @@ namespace Unity.Netcode.Components
|
||||
{
|
||||
if (m_IsRigidbody2D)
|
||||
{
|
||||
m_Rigidbody2D.rotation = rotation.eulerAngles.z;
|
||||
m_InternalRigidbody2D.rotation = rotation.eulerAngles.z;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Rigidbody.rotation = rotation;
|
||||
m_InternalRigidbody.rotation = rotation;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -404,7 +412,7 @@ namespace Unity.Netcode.Components
|
||||
{
|
||||
if (m_IsRigidbody2D)
|
||||
{
|
||||
switch (m_Rigidbody2D.interpolation)
|
||||
switch (m_InternalRigidbody2D.interpolation)
|
||||
{
|
||||
case RigidbodyInterpolation2D.None:
|
||||
{
|
||||
@@ -425,7 +433,7 @@ namespace Unity.Netcode.Components
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (m_Rigidbody.interpolation)
|
||||
switch (m_InternalRigidbody.interpolation)
|
||||
{
|
||||
case RigidbodyInterpolation.None:
|
||||
{
|
||||
@@ -454,16 +462,16 @@ namespace Unity.Netcode.Components
|
||||
{
|
||||
if (m_IsRigidbody2D)
|
||||
{
|
||||
if (m_Rigidbody2D.IsSleeping())
|
||||
if (m_InternalRigidbody2D.IsSleeping())
|
||||
{
|
||||
m_Rigidbody2D.WakeUp();
|
||||
m_InternalRigidbody2D.WakeUp();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_Rigidbody.IsSleeping())
|
||||
if (m_InternalRigidbody.IsSleeping())
|
||||
{
|
||||
m_Rigidbody.WakeUp();
|
||||
m_InternalRigidbody.WakeUp();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -476,11 +484,11 @@ namespace Unity.Netcode.Components
|
||||
{
|
||||
if (m_IsRigidbody2D)
|
||||
{
|
||||
m_Rigidbody2D.Sleep();
|
||||
m_InternalRigidbody2D.Sleep();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Rigidbody.Sleep();
|
||||
m_InternalRigidbody.Sleep();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -489,11 +497,11 @@ namespace Unity.Netcode.Components
|
||||
{
|
||||
if (m_IsRigidbody2D)
|
||||
{
|
||||
return m_Rigidbody2D.bodyType == RigidbodyType2D.Kinematic;
|
||||
return m_InternalRigidbody2D.bodyType == RigidbodyType2D.Kinematic;
|
||||
}
|
||||
else
|
||||
{
|
||||
return m_Rigidbody.isKinematic;
|
||||
return m_InternalRigidbody.isKinematic;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -518,11 +526,11 @@ namespace Unity.Netcode.Components
|
||||
{
|
||||
if (m_IsRigidbody2D)
|
||||
{
|
||||
m_Rigidbody2D.bodyType = isKinematic ? RigidbodyType2D.Kinematic : RigidbodyType2D.Dynamic;
|
||||
m_InternalRigidbody2D.bodyType = isKinematic ? RigidbodyType2D.Kinematic : RigidbodyType2D.Dynamic;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Rigidbody.isKinematic = isKinematic;
|
||||
m_InternalRigidbody.isKinematic = isKinematic;
|
||||
}
|
||||
|
||||
// If we are not spawned, then exit early
|
||||
@@ -539,7 +547,7 @@ namespace Unity.Netcode.Components
|
||||
if (IsKinematic())
|
||||
{
|
||||
// If not already set to interpolate then set the Rigidbody to interpolate
|
||||
if (m_Rigidbody.interpolation == RigidbodyInterpolation.Extrapolate)
|
||||
if (m_InternalRigidbody.interpolation == RigidbodyInterpolation.Extrapolate)
|
||||
{
|
||||
// Sleep until the next fixed update when switching from extrapolation to interpolation
|
||||
SleepRigidbody();
|
||||
@@ -568,11 +576,11 @@ namespace Unity.Netcode.Components
|
||||
{
|
||||
if (m_IsRigidbody2D)
|
||||
{
|
||||
m_Rigidbody2D.interpolation = RigidbodyInterpolation2D.None;
|
||||
m_InternalRigidbody2D.interpolation = RigidbodyInterpolation2D.None;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Rigidbody.interpolation = RigidbodyInterpolation.None;
|
||||
m_InternalRigidbody.interpolation = RigidbodyInterpolation.None;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -580,11 +588,11 @@ namespace Unity.Netcode.Components
|
||||
{
|
||||
if (m_IsRigidbody2D)
|
||||
{
|
||||
m_Rigidbody2D.interpolation = RigidbodyInterpolation2D.Interpolate;
|
||||
m_InternalRigidbody2D.interpolation = RigidbodyInterpolation2D.Interpolate;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Rigidbody.interpolation = RigidbodyInterpolation.Interpolate;
|
||||
m_InternalRigidbody.interpolation = RigidbodyInterpolation.Interpolate;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -592,11 +600,11 @@ namespace Unity.Netcode.Components
|
||||
{
|
||||
if (m_IsRigidbody2D)
|
||||
{
|
||||
m_Rigidbody2D.interpolation = RigidbodyInterpolation2D.Extrapolate;
|
||||
m_InternalRigidbody2D.interpolation = RigidbodyInterpolation2D.Extrapolate;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Rigidbody.interpolation = RigidbodyInterpolation.Extrapolate;
|
||||
m_InternalRigidbody.interpolation = RigidbodyInterpolation.Extrapolate;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -711,28 +719,28 @@ namespace Unity.Netcode.Components
|
||||
private void ApplyFixedJoint2D(NetworkRigidbodyBase bodyToConnect, Vector3 position, float connectedMassScale = 0.0f, float massScale = 1.0f, bool useGravity = false, bool zeroVelocity = true)
|
||||
{
|
||||
transform.position = position;
|
||||
m_Rigidbody2D.position = position;
|
||||
m_OriginalGravitySetting = bodyToConnect.m_Rigidbody.useGravity;
|
||||
m_InternalRigidbody2D.position = position;
|
||||
m_OriginalGravitySetting = bodyToConnect.m_InternalRigidbody.useGravity;
|
||||
m_FixedJoint2DUsingGravity = useGravity;
|
||||
|
||||
if (!useGravity)
|
||||
{
|
||||
m_OriginalGravityScale = m_Rigidbody2D.gravityScale;
|
||||
m_Rigidbody2D.gravityScale = 0.0f;
|
||||
m_OriginalGravityScale = m_InternalRigidbody2D.gravityScale;
|
||||
m_InternalRigidbody2D.gravityScale = 0.0f;
|
||||
}
|
||||
|
||||
if (zeroVelocity)
|
||||
{
|
||||
#if COM_UNITY_MODULES_PHYSICS2D_LINEAR
|
||||
m_Rigidbody2D.linearVelocity = Vector2.zero;
|
||||
m_InternalRigidbody2D.linearVelocity = Vector2.zero;
|
||||
#else
|
||||
m_Rigidbody2D.velocity = Vector2.zero;
|
||||
m_InternalRigidbody2D.velocity = Vector2.zero;
|
||||
#endif
|
||||
m_Rigidbody2D.angularVelocity = 0.0f;
|
||||
m_InternalRigidbody2D.angularVelocity = 0.0f;
|
||||
}
|
||||
|
||||
FixedJoint2D = gameObject.AddComponent<FixedJoint2D>();
|
||||
FixedJoint2D.connectedBody = bodyToConnect.m_Rigidbody2D;
|
||||
FixedJoint2D.connectedBody = bodyToConnect.m_InternalRigidbody2D;
|
||||
OnFixedJoint2DCreated();
|
||||
}
|
||||
|
||||
@@ -740,16 +748,16 @@ namespace Unity.Netcode.Components
|
||||
private void ApplyFixedJoint(NetworkRigidbodyBase bodyToConnectTo, Vector3 position, float connectedMassScale = 0.0f, float massScale = 1.0f, bool useGravity = false, bool zeroVelocity = true)
|
||||
{
|
||||
transform.position = position;
|
||||
m_Rigidbody.position = position;
|
||||
m_InternalRigidbody.position = position;
|
||||
if (zeroVelocity)
|
||||
{
|
||||
m_Rigidbody.linearVelocity = Vector3.zero;
|
||||
m_Rigidbody.angularVelocity = Vector3.zero;
|
||||
m_InternalRigidbody.linearVelocity = Vector3.zero;
|
||||
m_InternalRigidbody.angularVelocity = Vector3.zero;
|
||||
}
|
||||
m_OriginalGravitySetting = m_Rigidbody.useGravity;
|
||||
m_Rigidbody.useGravity = useGravity;
|
||||
m_OriginalGravitySetting = m_InternalRigidbody.useGravity;
|
||||
m_InternalRigidbody.useGravity = useGravity;
|
||||
FixedJoint = gameObject.AddComponent<FixedJoint>();
|
||||
FixedJoint.connectedBody = bodyToConnectTo.m_Rigidbody;
|
||||
FixedJoint.connectedBody = bodyToConnectTo.m_InternalRigidbody;
|
||||
FixedJoint.connectedMassScale = connectedMassScale;
|
||||
FixedJoint.massScale = massScale;
|
||||
OnFixedJointCreated();
|
||||
@@ -861,7 +869,7 @@ namespace Unity.Netcode.Components
|
||||
if (FixedJoint != null)
|
||||
{
|
||||
FixedJoint.connectedBody = null;
|
||||
m_Rigidbody.useGravity = m_OriginalGravitySetting;
|
||||
m_InternalRigidbody.useGravity = m_OriginalGravitySetting;
|
||||
Destroy(FixedJoint);
|
||||
FixedJoint = null;
|
||||
ResetInterpolation();
|
||||
|
||||
Reference in New Issue
Block a user