|
1 | 1 | using System.Collections; |
| 2 | +using System.Linq; |
| 3 | +using System.Text.RegularExpressions; |
2 | 4 | using NUnit.Framework; |
3 | 5 | using Unity.Netcode.Components; |
4 | 6 | using Unity.Netcode.TestHelpers.Runtime; |
@@ -71,8 +73,8 @@ protected override void OnNewClientCreated(NetworkManager networkManager) |
71 | 73 | /// is not deleted until a later time would cause an exception due to the |
72 | 74 | /// NetworkBehaviour not being removed from the NetworkObject.ChildNetworkBehaviours |
73 | 75 | /// list. |
74 | | - /// - That when a child GameObject is deleted/disabled or a NetworkBehaviour is disabled |
75 | | - /// a message is logged and the NetworkObject still can be spawned and synchronized. |
| 76 | + /// - When a NetworkBehaviour is disabled but the associated GameObject is enabled, |
| 77 | + /// the object spawns without any issues. |
76 | 78 | /// </summary> |
77 | 79 | [UnityTest] |
78 | 80 | public IEnumerator ValidatedDisableddNetworkBehaviourWarning([Values] bool disableGameObject) |
@@ -101,11 +103,18 @@ public IEnumerator ValidatedDisableddNetworkBehaviourWarning([Values] bool disab |
101 | 103 | // Now create an instance of the prefab |
102 | 104 | var instance = Object.Instantiate(m_PrefabToSpawn); |
103 | 105 | var instanceNetworkObject = instance.GetComponent<NetworkObject>(); |
104 | | - // Generate the expected warning message |
105 | | - var expectedWarning = instanceNetworkObject.GenerateDisabledNetworkBehaviourWarning(instanceNetworkObject.GetComponentInChildren<NetworkTransform>(true)); |
| 106 | + // When the GameObject is disabled, check for the warning. |
| 107 | + if (disableGameObject) |
| 108 | + { |
| 109 | + // Generate the expected warning message |
| 110 | + var expectedWarning = instanceNetworkObject.GenerateDisabledNetworkBehaviourWarning(instanceNetworkObject.GetComponentInChildren<NetworkTransform>(true)); |
| 111 | + var expectedSplit = expectedWarning.Split(']'); |
| 112 | + var expectedWarningBody = expectedSplit.Last(); |
| 113 | + LogAssert.Expect(LogType.Warning, new Regex($".*{expectedWarningBody}*.")); |
| 114 | + } |
| 115 | + |
106 | 116 | // Spawn the instance |
107 | 117 | SpawnObjectInstance(instanceNetworkObject, m_ServerNetworkManager); |
108 | | - LogAssert.Expect(LogType.Warning, $"{expectedWarning}"); |
109 | 118 | // Asure the connected client spawned the object first |
110 | 119 | yield return WaitForSpawnedOnAllOrTimeOut(instanceNetworkObject); |
111 | 120 | AssertOnTimeout($"Not all clients spawned {instanceNetworkObject.name}!"); |
|
0 commit comments