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:
Unity Technologies
2024-09-12 00:00:00 +00:00
parent eab996f3ac
commit 48c6a6121c
46 changed files with 1987 additions and 492 deletions

View File

@@ -239,19 +239,13 @@ namespace Unity.Netcode.Components
m_CurrentSmoothTime = 0;
}
public override void OnUpdate()
private void ProcessSmoothing()
{
// If not spawned or this instance has authority, exit early
if (!IsSpawned)
{
return;
}
// Do not call the base class implementation...
// AnticipatedNetworkTransform applies its authoritative state immediately rather than waiting for update
// This is because AnticipatedNetworkTransforms may need to reference each other in reanticipating
// and we will want all reanticipation done before anything else wants to reference the transform in
// OnUpdate()
//base.Update();
if (m_CurrentSmoothTime < m_SmoothDuration)
{
@@ -262,7 +256,7 @@ namespace Unity.Netcode.Components
m_AnticipatedTransform = new TransformState
{
Position = Vector3.Lerp(m_SmoothFrom.Position, m_SmoothTo.Position, pct),
Rotation = Quaternion.Slerp(m_SmoothFrom.Rotation, m_SmoothTo.Rotation, pct),
Rotation = Quaternion.Lerp(m_SmoothFrom.Rotation, m_SmoothTo.Rotation, pct),
Scale = Vector3.Lerp(m_SmoothFrom.Scale, m_SmoothTo.Scale, pct)
};
m_PreviousAnticipatedTransform = m_AnticipatedTransform;
@@ -275,6 +269,32 @@ namespace Unity.Netcode.Components
}
}
// TODO: This does not handle OnFixedUpdate
// This requires a complete overhaul in this class to switch between using
// NetworkRigidbody's position and rotation values.
public override void OnUpdate()
{
ProcessSmoothing();
// Do not call the base class implementation...
// AnticipatedNetworkTransform applies its authoritative state immediately rather than waiting for update
// This is because AnticipatedNetworkTransforms may need to reference each other in reanticipating
// and we will want all reanticipation done before anything else wants to reference the transform in
// OnUpdate()
//base.OnUpdate();
}
/// <summary>
/// Since authority does not subscribe to updates (OnUpdate or OnFixedUpdate),
/// we have to update every frame to assure authority processes soothing.
/// </summary>
private void Update()
{
if (CanCommitToTransform && IsSpawned)
{
ProcessSmoothing();
}
}
internal class AnticipatedObject : IAnticipationEventReceiver, IAnticipatedObject
{
public AnticipatedNetworkTransform Transform;
@@ -347,14 +367,44 @@ namespace Unity.Netcode.Components
m_CurrentSmoothTime = 0;
}
protected override void OnSynchronize<T>(ref BufferSerializer<T> serializer)
/// <summary>
/// (This replaces the first OnSynchronize for NetworkTransforms)
/// This is needed to initialize when fully synchronized since non-authority instances
/// don't apply the initial synchronization (new client synchronization) until after
/// everything has been spawned and synchronized.
/// </summary>
protected internal override void InternalOnNetworkSessionSynchronized()
{
base.OnSynchronize(ref serializer);
if (!CanCommitToTransform)
var wasSynchronizing = SynchronizeState.IsSynchronizing;
base.InternalOnNetworkSessionSynchronized();
if (!CanCommitToTransform && wasSynchronizing && !SynchronizeState.IsSynchronizing)
{
m_OutstandingAuthorityChange = true;
ApplyAuthoritativeState();
ResetAnticipatedState();
m_AnticipatedObject = new AnticipatedObject { Transform = this };
NetworkManager.AnticipationSystem.RegisterForAnticipationEvents(m_AnticipatedObject);
NetworkManager.AnticipationSystem.AllAnticipatedObjects.Add(m_AnticipatedObject);
}
}
/// <summary>
/// (This replaces the any subsequent OnSynchronize for NetworkTransforms post client synchronization)
/// This occurs on already connected clients when dynamically spawning a NetworkObject for
/// non-authoritative instances.
/// </summary>
protected internal override void InternalOnNetworkPostSpawn()
{
base.InternalOnNetworkPostSpawn();
if (!CanCommitToTransform && NetworkManager.IsConnectedClient && !SynchronizeState.IsSynchronizing)
{
m_OutstandingAuthorityChange = true;
ApplyAuthoritativeState();
ResetAnticipatedState();
m_AnticipatedObject = new AnticipatedObject { Transform = this };
NetworkManager.AnticipationSystem.RegisterForAnticipationEvents(m_AnticipatedObject);
NetworkManager.AnticipationSystem.AllAnticipatedObjects.Add(m_AnticipatedObject);
}
}
@@ -365,6 +415,13 @@ namespace Unity.Netcode.Components
Debug.LogWarning($"This component is not currently supported in distributed authority.");
}
base.OnNetworkSpawn();
// Non-authoritative instances exit early if the synchronization has yet to
// be applied at this point
if (SynchronizeState.IsSynchronizing && !CanCommitToTransform)
{
return;
}
m_OutstandingAuthorityChange = true;
ApplyAuthoritativeState();
ResetAnticipatedState();

View File

@@ -12,7 +12,7 @@ namespace Unity.Netcode
public abstract class BufferedLinearInterpolator<T> where T : struct
{
internal float MaxInterpolationBound = 3.0f;
private struct BufferedItem
protected internal struct BufferedItem
{
public T Item;
public double TimeSent;
@@ -31,14 +31,16 @@ namespace Unity.Netcode
private const double k_SmallValue = 9.999999439624929E-11; // copied from Vector3's equal operator
private T m_InterpStartValue;
private T m_CurrentInterpValue;
private T m_InterpEndValue;
protected internal T m_InterpStartValue;
protected internal T m_CurrentInterpValue;
protected internal T m_InterpEndValue;
private double m_EndTimeConsumed;
private double m_StartTimeConsumed;
private readonly List<BufferedItem> m_Buffer = new List<BufferedItem>(k_BufferCountLimit);
protected internal readonly List<BufferedItem> m_Buffer = new List<BufferedItem>(k_BufferCountLimit);
// Buffer consumption scenarios
// Perfect case consumption
@@ -73,6 +75,21 @@ namespace Unity.Netcode
private bool InvalidState => m_Buffer.Count == 0 && m_LifetimeConsumedCount == 0;
internal bool EndOfBuffer => m_Buffer.Count == 0;
internal bool InLocalSpace;
protected internal virtual void OnConvertTransformSpace(Transform transform, bool inLocalSpace)
{
}
internal void ConvertTransformSpace(Transform transform, bool inLocalSpace)
{
OnConvertTransformSpace(transform, inLocalSpace);
InLocalSpace = inLocalSpace;
}
/// <summary>
/// Resets interpolator to initial state
/// </summary>
@@ -351,6 +368,35 @@ namespace Unity.Netcode
return Quaternion.Lerp(start, end, time);
}
}
private Quaternion ConvertToNewTransformSpace(Transform transform, Quaternion rotation, bool inLocalSpace)
{
if (inLocalSpace)
{
return Quaternion.Inverse(transform.rotation) * rotation;
}
else
{
return transform.rotation * rotation;
}
}
protected internal override void OnConvertTransformSpace(Transform transform, bool inLocalSpace)
{
for (int i = 0; i < m_Buffer.Count; i++)
{
var entry = m_Buffer[i];
entry.Item = ConvertToNewTransformSpace(transform, entry.Item, inLocalSpace);
m_Buffer[i] = entry;
}
m_InterpStartValue = ConvertToNewTransformSpace(transform, m_InterpStartValue, inLocalSpace);
m_CurrentInterpValue = ConvertToNewTransformSpace(transform, m_CurrentInterpValue, inLocalSpace);
m_InterpEndValue = ConvertToNewTransformSpace(transform, m_InterpEndValue, inLocalSpace);
base.OnConvertTransformSpace(transform, inLocalSpace);
}
}
/// <summary>
@@ -388,5 +434,34 @@ namespace Unity.Netcode
return Vector3.Lerp(start, end, time);
}
}
private Vector3 ConvertToNewTransformSpace(Transform transform, Vector3 position, bool inLocalSpace)
{
if (inLocalSpace)
{
return transform.InverseTransformPoint(position);
}
else
{
return transform.TransformPoint(position);
}
}
protected internal override void OnConvertTransformSpace(Transform transform, bool inLocalSpace)
{
for (int i = 0; i < m_Buffer.Count; i++)
{
var entry = m_Buffer[i];
entry.Item = ConvertToNewTransformSpace(transform, entry.Item, inLocalSpace);
m_Buffer[i] = entry;
}
m_InterpStartValue = ConvertToNewTransformSpace(transform, m_InterpStartValue, inLocalSpace);
m_CurrentInterpValue = ConvertToNewTransformSpace(transform, m_CurrentInterpValue, inLocalSpace);
m_InterpEndValue = ConvertToNewTransformSpace(transform, m_InterpEndValue, inLocalSpace);
base.OnConvertTransformSpace(transform, inLocalSpace);
}
}
}

View File

@@ -584,7 +584,7 @@ namespace Unity.Netcode.Components
base.OnDestroy();
}
private void Awake()
protected virtual void Awake()
{
int layers = m_Animator.layerCount;
// Initializing the below arrays for everyone handles an issue
@@ -952,8 +952,14 @@ namespace Unity.Netcode.Components
{
// Just notify all remote clients and not the local server
m_ClientSendList.Clear();
m_ClientSendList.AddRange(NetworkManager.ConnectedClientsIds);
m_ClientSendList.Remove(NetworkManager.LocalClientId);
foreach (var clientId in NetworkManager.ConnectedClientsIds)
{
if (clientId == NetworkManager.LocalClientId || !NetworkObject.Observers.Contains(clientId))
{
continue;
}
m_ClientSendList.Add(clientId);
}
m_ClientRpcParams.Send.TargetClientIds = m_ClientSendList;
SendAnimStateClientRpc(m_AnimationMessage, m_ClientRpcParams);
}
@@ -1264,9 +1270,15 @@ namespace Unity.Netcode.Components
if (NetworkManager.ConnectedClientsIds.Count > (IsHost ? 2 : 1))
{
m_ClientSendList.Clear();
m_ClientSendList.AddRange(NetworkManager.ConnectedClientsIds);
m_ClientSendList.Remove(serverRpcParams.Receive.SenderClientId);
m_ClientSendList.Remove(NetworkManager.ServerClientId);
foreach (var clientId in NetworkManager.ConnectedClientsIds)
{
if (clientId == serverRpcParams.Receive.SenderClientId || clientId == NetworkManager.ServerClientId || !NetworkObject.Observers.Contains(clientId))
{
continue;
}
m_ClientSendList.Add(clientId);
}
m_ClientRpcParams.Send.TargetClientIds = m_ClientSendList;
m_NetworkAnimatorStateChangeHandler.SendParameterUpdate(parametersUpdate, m_ClientRpcParams);
}
@@ -1321,9 +1333,14 @@ namespace Unity.Netcode.Components
if (NetworkManager.ConnectedClientsIds.Count > (IsHost ? 2 : 1))
{
m_ClientSendList.Clear();
m_ClientSendList.AddRange(NetworkManager.ConnectedClientsIds);
m_ClientSendList.Remove(serverRpcParams.Receive.SenderClientId);
m_ClientSendList.Remove(NetworkManager.ServerClientId);
foreach (var clientId in NetworkManager.ConnectedClientsIds)
{
if (clientId == serverRpcParams.Receive.SenderClientId || clientId == NetworkManager.ServerClientId || !NetworkObject.Observers.Contains(clientId))
{
continue;
}
m_ClientSendList.Add(clientId);
}
m_ClientRpcParams.Send.TargetClientIds = m_ClientSendList;
m_NetworkAnimatorStateChangeHandler.SendAnimationUpdate(animationMessage, m_ClientRpcParams);
}
@@ -1390,9 +1407,14 @@ namespace Unity.Netcode.Components
InternalSetTrigger(animationTriggerMessage.Hash, animationTriggerMessage.IsTriggerSet);
m_ClientSendList.Clear();
m_ClientSendList.AddRange(NetworkManager.ConnectedClientsIds);
m_ClientSendList.Remove(NetworkManager.ServerClientId);
foreach (var clientId in NetworkManager.ConnectedClientsIds)
{
if (clientId == NetworkManager.ServerClientId || !NetworkObject.Observers.Contains(clientId))
{
continue;
}
m_ClientSendList.Add(clientId);
}
if (IsServerAuthoritative())
{
m_NetworkAnimatorStateChangeHandler.QueueTriggerUpdateToClient(animationTriggerMessage, m_ClientRpcParams);

View File

@@ -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();

View File

@@ -12,6 +12,9 @@ namespace Unity.Netcode.Components
[AddComponentMenu("Netcode/Network Rigidbody")]
public class NetworkRigidbody : NetworkRigidbodyBase
{
public Rigidbody Rigidbody => m_InternalRigidbody;
protected virtual void Awake()
{
Initialize(RigidbodyTypes.Rigidbody);

View File

@@ -12,6 +12,7 @@ namespace Unity.Netcode.Components
[AddComponentMenu("Netcode/Network Rigidbody 2D")]
public class NetworkRigidbody2D : NetworkRigidbodyBase
{
public Rigidbody2D Rigidbody2D => m_InternalRigidbody2D;
protected virtual void Awake()
{
Initialize(RigidbodyTypes.Rigidbody2D);

File diff suppressed because it is too large Load Diff