Skip to content

Commit dece89c

Browse files
committed
chore: Separate updates
1 parent 54e8a5a commit dece89c

8 files changed

Lines changed: 196 additions & 31 deletions

File tree

com.unity.netcode.gameobjects/Editor/Icons.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
16.3 KB
Loading

com.unity.netcode.gameobjects/Editor/Icons/NOBridgeIcon.png.meta

Lines changed: 156 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -326,14 +326,8 @@ private void OnEnable()
326326
/// </summary>
327327
/// <param name="transform">The current <see cref="Transform"/> we are inspecting for a parent</param>
328328
/// <returns>the root parent for the first <see cref="Transform"/> passed into the method</returns>
329-
public static Transform GetRootParentTransform(Transform transform)
330-
{
331-
if (transform.parent == null || transform.parent == transform)
332-
{
333-
return transform;
334-
}
335-
return GetRootParentTransform(transform.parent);
336-
}
329+
[Obsolete("Use transform.root instead", true)]
330+
public static Transform GetRootParentTransform(Transform transform) => transform.root;
337331

338332
/// <summary>
339333
/// Used to determine if a GameObject has one or more NetworkBehaviours but

com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#pragma warning disable IDE0005
22
using System;
33
using System.Collections.Generic;
4-
using System.Runtime.CompilerServices;
54
using Unity.Collections;
5+
#if MULTIPLAYER_TOOLS && (DEVELOPMENT_BUILD || UNITY_EDITOR || UNITY_MP_TOOLS_NET_STATS_MONITOR_ENABLED_IN_RELEASE)
6+
using System.Runtime.CompilerServices;
7+
#endif
68
using UnityEngine;
79
#pragma warning restore IDE0005
810

com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,10 +1010,10 @@ internal bool NetworkManagerCheckForParent(bool ignoreNetworkManagerCache = fals
10101010
#if UNITY_EDITOR
10111011
var isParented = NetworkManagerHelper.NotifyUserOfNestedNetworkManager(this, ignoreNetworkManagerCache);
10121012
#else
1013-
var isParented = transform.root != transform;
1013+
var isParented = transform.parent != null;
10141014
if (isParented)
10151015
{
1016-
throw new Exception(GenerateNestedNetworkManagerMessage(transform));
1016+
Log.Error(new Context(LogLevel.Error, GenerateNestedNetworkManagerMessage(transform)));
10171017
}
10181018
#endif
10191019
return isParented;
@@ -1029,7 +1029,17 @@ internal static string GenerateNestedNetworkManagerMessage(Transform transform)
10291029
/// </summary>
10301030
private void OnTransformParentChanged()
10311031
{
1032+
#if UNITY_EDITOR
1033+
// During editor playmode, we log the message as a dialog box
1034+
// and that script sets the parent back to root/null.
10321035
NetworkManagerCheckForParent();
1036+
#else
1037+
if (NetworkManagerCheckForParent())
1038+
{
1039+
// During runtime, we log the message and set our parent back to root/null.
1040+
transform.parent = null;
1041+
}
1042+
#endif
10331043
}
10341044

10351045
/// <summary>

com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
using Unity.Netcode.Runtime;
88
#if UNITY_EDITOR
99
using UnityEditor;
10-
#if UNITY_2021_2_OR_NEWER
1110
using UnityEditor.SceneManagement;
12-
#else
13-
using UnityEditor.Experimental.SceneManagement;
14-
#endif
1511
#endif
1612
using UnityEngine;
1713
using UnityEngine.SceneManagement;
@@ -2665,7 +2661,7 @@ internal void InvokeBehaviourNetworkSpawn()
26652661
childBehaviour.InternalOnNetworkSpawn();
26662662
}
26672663

2668-
// After initialization, we can then invoke OnNetworkSpawn on each child NetworkBehaviour.
2664+
// After internally spawning, we can then invoke OnNetworkSpawn on each child NetworkBehaviour.
26692665
foreach (var childBehaviour in ChildNetworkBehaviours.Values)
26702666
{
26712667
if (!childBehaviour.gameObject.activeInHierarchy)
@@ -2740,6 +2736,7 @@ internal string GenerateDisabledNetworkBehaviourWarning(NetworkBehaviour network
27402736
}
27412737

27422738
internal Dictionary<ushort, NetworkBehaviour> ChildNetworkBehaviours;
2739+
27432740
internal bool InitializeChildNetworkBehaviours()
27442741
{
27452742
ChildNetworkBehaviours = new Dictionary<ushort, NetworkBehaviour>();
@@ -2770,9 +2767,7 @@ internal bool InitializeChildNetworkBehaviours()
27702767
networkTransform.IsNested = networkTransform.gameObject != gameObject;
27712768
NetworkTransforms.Add(networkTransform);
27722769
}
2773-
27742770
#if COM_UNITY_MODULES_PHYSICS || COM_UNITY_MODULES_PHYSICS2D
2775-
27762771
var rigidbodyBase = behaviour as NetworkRigidbodyBase;
27772772
if (rigidbodyBase != null)
27782773
{
@@ -2914,18 +2909,18 @@ internal struct SerializedObject
29142909
public ulong OwnerClientId;
29152910
public ushort OwnershipFlags;
29162911

2917-
private const ushort k_IsPlayerObject = 0x001;
2918-
private const ushort k_HasParent = 0x002;
2919-
private const ushort k_IsSceneObject = 0x004;
2920-
private const ushort k_HasTransform = 0x008;
2921-
private const ushort k_IsLatestParentSet = 0x010;
2922-
private const ushort k_WorldPositionStays = 0x020;
2923-
private const ushort k_DestroyWithScene = 0x040;
2924-
private const ushort k_DontDestroyWithOwner = 0x080;
2925-
private const ushort k_HasOwnershipFlags = 0x100;
2926-
private const ushort k_SyncObservers = 0x200;
2927-
private const ushort k_SpawnWithObservers = 0x400;
2928-
private const ushort k_HasInstantiationData = 0x800;
2912+
private const ushort k_IsPlayerObject = 0x0001;
2913+
private const ushort k_HasParent = 0x0002;
2914+
private const ushort k_IsSceneObject = 0x0004;
2915+
private const ushort k_HasTransform = 0x0008;
2916+
private const ushort k_IsLatestParentSet = 0x0010;
2917+
private const ushort k_WorldPositionStays = 0x0020;
2918+
private const ushort k_DestroyWithScene = 0x0040;
2919+
private const ushort k_DontDestroyWithOwner = 0x0080;
2920+
private const ushort k_HasOwnershipFlags = 0x0100;
2921+
private const ushort k_SyncObservers = 0x0200;
2922+
private const ushort k_SpawnWithObservers = 0x0400;
2923+
private const ushort k_HasInstantiationData = 0x0800;
29292924

29302925
public bool IsPlayerObject;
29312926
public bool HasParent;

com.unity.netcode.gameobjects/Runtime/SceneManagement/SceneEventData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,9 +1120,9 @@ internal void SynchronizeSceneNetworkObjects(NetworkManager networkManager)
11201120
}
11211121
var spawnedNetworkObject = NetworkObject.Deserialize(serializedObject, InternalBuffer, networkManager);
11221122

1123-
var noStop = InternalBuffer.Position;
11241123
if (EnableSerializationLogs)
11251124
{
1125+
var noStop = InternalBuffer.Position;
11261126
builder.AppendLine($"[Head: {noStart}][Tail: {noStop}][Size: {noStop - noStart}][{spawnedNetworkObject.name}][NID-{spawnedNetworkObject.NetworkObjectId}][Children: {spawnedNetworkObject.ChildNetworkBehaviours.Count}]");
11271127
LogArray(InternalBuffer.ToArray(), noStart, noStop, builder);
11281128
}

0 commit comments

Comments
 (0)