Skip to content

Commit 8aa723b

Browse files
chore: updates for most recent unified changes (#4094)
* update This aligns with the recent changes to the ngo-unified trunk updates. * update Fixes and updates based on the most recent changes in the unified API. * style Removing whitespace * update Removing all of the original prefab registration flow, per request within unified PR, to remove the code on the unified side that this code depends on. * update Bumping the test project's project version to 6000.7.0a1. * Revert "update" This reverts commit 69f73b7. * update Mirroring what the standards check is requiring. * fix: PVP-301-1 Assuring that only when either physics module is present will it define the local hasGhost variable.
1 parent 122db34 commit 8aa723b

10 files changed

Lines changed: 190 additions & 154 deletions

File tree

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
#if BYPASS_DEFAULT_ENUM_DRAWER && MULTIPLAYER_SERVICES_SDK_INSTALLED
33
using System.Linq;
44
#endif
5+
#if UNIFIED_NETCODE
6+
using Unity.NetCode;
7+
using Unity.NetCode.Editor;
8+
#endif
59
using UnityEditor;
610
using UnityEngine;
711

@@ -23,6 +27,34 @@ public class NetworkObjectEditor : UnityEditor.Editor
2327

2428
private static readonly string[] k_HiddenFields = { "m_Script" };
2529

30+
#if UNIFIED_NETCODE
31+
/// <summary>
32+
/// Register for the GhostAdapter removal event.
33+
/// </summary>
34+
[InitializeOnLoadMethod]
35+
private static void OnApplicationStart()
36+
{
37+
GhostAdapterEditor.OnGhostAdapterPreRemoval = OnGhostAdapterPreRemoval;
38+
}
39+
40+
/// <summary>
41+
/// Callback to remove the GhostBehaviours prior to removing GhostAdapter.
42+
/// </summary>
43+
/// <param name="gameObject">The <see cref="GameObject"/> with the <see cref="GhostAdapter"/> component being removed.</param>
44+
private static void OnGhostAdapterPreRemoval(GameObject gameObject)
45+
{
46+
var ghostBehaviours = gameObject.GetComponentsInChildren<GhostBehaviour>();
47+
for (int i = ghostBehaviours.Length - 1; i >= 0; i--)
48+
{
49+
DestroyImmediate(ghostBehaviours[i], true);
50+
}
51+
var networkObject = gameObject.GetComponent<NetworkObject>();
52+
networkObject.GhostAdapter = null;
53+
networkObject.HasGhost = false;
54+
networkObject.HadBridge = true;
55+
}
56+
#endif
57+
2658
private void Initialize()
2759
{
2860
if (m_Initialized)

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

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Runtime.CompilerServices;
12
using Unity.Netcode.Components;
23
using UnityEditor;
34
using UnityEngine;
@@ -94,9 +95,40 @@ public override void OnEnable()
9495
base.OnEnable();
9596
}
9697

98+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
99+
private void SetGUIActive(bool active = true)
100+
{
101+
#if UNIFIED_NETCODE
102+
if (Application.IsPlaying(m_NetworkObject) && m_NetworkObject.HasGhost)
103+
{
104+
GUI.enabled = false;
105+
}
106+
else
107+
{
108+
GUI.enabled = active;
109+
}
110+
#else
111+
GUI.enabled = active;
112+
#endif
113+
114+
}
115+
116+
private NetworkObject m_NetworkObject;
117+
97118
private void DisplayNetworkTransformProperties()
98119
{
99120
var networkTransform = target as NetworkTransform;
121+
122+
#if UNIFIED_NETCODE
123+
m_NetworkObject = networkTransform.GetComponent<NetworkObject>();
124+
var hasGhost = m_NetworkObject.HasGhost;
125+
SetGUIActive();
126+
#else
127+
#if COM_UNITY_MODULES_PHYSICS || COM_UNITY_MODULES_PHYSICS2D
128+
var hasGhost = false;
129+
#endif
130+
#endif
131+
100132
EditorGUILayout.LabelField("Axis to Synchronize", EditorStyles.boldLabel);
101133
{
102134
GUILayout.BeginHorizontal();
@@ -190,7 +222,7 @@ private void DisplayNetworkTransformProperties()
190222
{
191223
networkTransform.UseUnreliableDeltas = false;
192224
}
193-
GUI.enabled = !networkTransform.SwitchTransformSpaceWhenParented;
225+
SetGUIActive(!networkTransform.SwitchTransformSpaceWhenParented);
194226
if (networkTransform.SwitchTransformSpaceWhenParented)
195227
{
196228
EditorGUILayout.BeginHorizontal();
@@ -202,11 +234,13 @@ private void DisplayNetworkTransformProperties()
202234
{
203235
EditorGUILayout.PropertyField(m_UseUnreliableDeltas);
204236
}
205-
GUI.enabled = true;
237+
238+
SetGUIActive(true);
206239

207240
EditorGUILayout.Space();
208241
EditorGUILayout.LabelField("Configurations", EditorStyles.boldLabel);
209-
GUI.enabled = !networkTransform.UseUnreliableDeltas;
242+
243+
SetGUIActive(!networkTransform.UseUnreliableDeltas);
210244
if (networkTransform.UseUnreliableDeltas)
211245
{
212246
EditorGUILayout.BeginHorizontal();
@@ -218,7 +252,7 @@ private void DisplayNetworkTransformProperties()
218252
{
219253
EditorGUILayout.PropertyField(m_SwitchTransformSpaceWhenParented);
220254
}
221-
GUI.enabled = true;
255+
SetGUIActive(true);
222256
if (m_SwitchTransformSpaceWhenParented.boolValue)
223257
{
224258
m_TickSyncChildren.boolValue = true;
@@ -297,20 +331,23 @@ private void DisplayNetworkTransformProperties()
297331

298332
#if COM_UNITY_MODULES_PHYSICS
299333
// if rigidbody is present but network rigidbody is not present
300-
if (networkTransform.TryGetComponent<Rigidbody>(out _) && networkTransform.TryGetComponent<NetworkRigidbody>(out _) == false)
334+
if (hasGhost && networkTransform.TryGetComponent<Rigidbody>(out _) && networkTransform.TryGetComponent<NetworkRigidbody>(out _) == false)
301335
{
302-
EditorGUILayout.HelpBox("This GameObject contains a Rigidbody but no NetworkRigidbody.\n" +
336+
EditorGUILayout.HelpBox("This GameObject contains a Rigidbody but no NetworkRigidbody.\n " +
303337
"Add a NetworkRigidbody component to improve Rigidbody synchronization.", MessageType.Warning);
304338
}
305339
#endif // COM_UNITY_MODULES_PHYSICS
306340

307341
#if COM_UNITY_MODULES_PHYSICS2D
308-
if (networkTransform.TryGetComponent<Rigidbody2D>(out _) && networkTransform.TryGetComponent<NetworkRigidbody2D>(out _) == false)
342+
if (!hasGhost && networkTransform.TryGetComponent<Rigidbody2D>(out _) && networkTransform.TryGetComponent<NetworkRigidbody2D>(out _) == false)
309343
{
310344
EditorGUILayout.HelpBox("This GameObject contains a Rigidbody2D but no NetworkRigidbody2D.\n" +
311345
"Add a NetworkRigidbody2D component to improve Rigidbody2D synchronization.", MessageType.Warning);
312346
}
313347
#endif // COM_UNITY_MODULES_PHYSICS2D
348+
#if UNIFIED_NETCODE
349+
GUI.enabled = true;
350+
#endif
314351
}
315352

316353
/// <summary>

com.unity.netcode.gameobjects/Editor/Unity.Netcode.Editor.asmdef

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"Unity.Networking.Transport",
99
"Unity.Services.Core",
1010
"Unity.Services.Authentication",
11-
"Unity.NetCode"
11+
"Unity.NetCode",
12+
"Unity.NetCode.Editor"
1213
],
1314
"includePlatforms": [
1415
"Editor"

com.unity.netcode.gameobjects/Runtime/Components/Helpers/NetworkObjectBridge.cs

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#if UNIFIED_NETCODE
22
using Unity.NetCode;
3-
#if UNITY_EDITOR
4-
using UnityEditor;
5-
#endif
63
using UnityEngine;
74

85
namespace Unity.Netcode
@@ -13,31 +10,49 @@ namespace Unity.Netcode
1310
/// <see cref="NetworkObject.SerializedObject"/> the N4E-spawned hybrid prefab instances to the incoming <see cref="CreateObjectMessage"/>
1411
/// specific to the N4E-spawned hybrid prefab instance that has the matching <see cref="NetworkObjectId"/>.
1512
/// </summary>
13+
14+
[DefaultExecutionOrder(GhostAdapterExecutionOrder.ExecutionOrder + 1)]
15+
//BREAK --- Fix this on UNIFIED side 1st
1616
public partial class NetworkObjectBridge : GhostBehaviour
1717
{
18+
// DefaultExecutionOrder
19+
// TODO: Define a const for the value used on GhostAdapter and use that value
20+
// to set the execution order so if it changes on GhostAdapter it updates here.
1821
#if UNITY_EDITOR
19-
[HideInInspector]
20-
[SerializeField]
21-
private bool m_Sorted = false;
2222
private void OnValidate()
2323
{
24-
// TODO-UNIFIED: GhostAdapter must be above all GhostBehaviours in order to assure the GhostAdapter is initialized before any GhostBehaviour.
25-
// This auto-sorting is required because the GhostBehaviours rely on the GhostAdapter.Awake being invoked before any GhostBehaviour.Awake.
26-
if (!m_Sorted && !EditorApplication.isPlaying)
24+
hideFlags = HideFlags.HideInInspector;
25+
26+
var ghostAdapter = GetComponent<GhostAdapter>();
27+
if (ghostAdapter == null)
2728
{
28-
while (UnityEditorInternal.ComponentUtility.MoveComponentUp(this))
29-
{
30-
// Keep moving until it can't go higher
31-
}
32-
var ghostAdapter = gameObject.GetComponent<GhostAdapter>();
33-
// Now move the GhostAdapter to the top so it is above NetworkObjectBridge
34-
while (ghostAdapter != null && UnityEditorInternal.ComponentUtility.MoveComponentUp(ghostAdapter))
29+
return;
30+
}
31+
32+
// Start users with just interpolation (they can adjust this if they want prediction)
33+
// to make the initial transition less problematic for users.
34+
ghostAdapter.SupportedGhostModes = GhostModeMask.Interpolated;
35+
36+
#if COM_UNITY_MODULES_PHYSICS
37+
var rigidBody = GetComponent<Rigidbody>();
38+
var ghostRigidBody = GetComponent<GhostRigidbody>();
39+
if (rigidBody != null)
40+
{
41+
// This must be enabled when replicating the rigid body.
42+
43+
ghostAdapter.SingleWorldHostInterpolationSmoothing = SingleWorldHostInterpolationMode.Interpolate;
44+
// TODO: Currently, this is added only if you enable replication of the rigid body.
45+
// There is a bug where if you don't add this component it doesn't synchronize the transform.
46+
// Remove this once the issue is resolved.
47+
if (ghostRigidBody == null)
3548
{
36-
// Keep moving until it can't go higher
49+
gameObject.AddComponent<GhostRigidbody>();
3750
}
38-
39-
m_Sorted = true;
4051
}
52+
#endif
53+
#if COM_UNITY_MODULES_PHYSICS2D
54+
// TODO: Fill out a similar script as above but for the 2D version
55+
#endif
4156
}
4257
#endif
4358

@@ -67,6 +82,11 @@ internal void HybridParentUpdate(Vector3 scale)
6782
//Debug.Log($"---- New LT: {transform.localPosition} | {transform.localRotation}");
6883
Ghost.ApplyPostTransformMatrixScale(scale);
6984
}
85+
86+
internal void ApplyScale(Vector3 scale)
87+
{
88+
Ghost.ApplyPostTransformMatrixScale(scale);
89+
}
7090
}
7191
}
7292
#endif

com.unity.netcode.gameobjects/Runtime/Components/Helpers/UnifiedBootstrap.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,6 @@ public override bool Initialize(string defaultWorldName)
6464
}
6565

6666
networkManager.NetcodeWorld = (NetcodeWorld)LastCreatedWorld;
67-
#if UNIFIED_NGO_REGISTERS_PREFABS
68-
if (networkManager.NetworkConfig.Prefabs.HasPendingGhostPrefabs)
69-
{
70-
if (networkManager.LogLevel <= LogLevel.Developer)
71-
{
72-
NetworkLog.LogInfo($"[{nameof(UnifiedBootstrap)}] Registering hybrid prefabs...");
73-
}
74-
networkManager.NetworkConfig.Prefabs.RegisterGhostPrefabs(networkManager);
75-
}
76-
#endif
7767
}
7868
else
7969
{

0 commit comments

Comments
 (0)