Skip to content

Commit 115b538

Browse files
IsTimedOut redundancy removed
1 parent f3c963e commit 115b538

File tree

1 file changed

+10
-37
lines changed

1 file changed

+10
-37
lines changed

Packages/com.unity.multiplayer.samples.coop/Utilities/Testing/TestUtilities.cs

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections;
3+
using System.Collections.Generic;
34
using UnityEngine;
45
using NUnit.Framework;
56
using Unity.Netcode;
@@ -11,21 +12,6 @@ public abstract class TestUtilities
1112
{
1213
const float k_MaxSceneLoadDuration = 10f;
1314

14-
/// <summary>
15-
/// Helper wrapper method for asserting the completion of a scene load to be used inside Playmode tests. A scene
16-
/// is either loaded successfully, or the loading process has timed out and will throw an exception.
17-
/// </summary>
18-
/// <param name="sceneName"> Name of scene </param>
19-
/// <returns> IEnumerator to track scene load process </returns>
20-
public static IEnumerator AssertIsSceneLoaded(string sceneName)
21-
{
22-
var waitUntilSceneLoaded = new WaitForSceneLoad(sceneName);
23-
24-
yield return waitUntilSceneLoaded;
25-
26-
Assert.That(!waitUntilSceneLoaded.TimedOut);
27-
}
28-
2915
/// <summary>
3016
/// Helper wrapper method for asserting the completion of a network scene load to be used inside Playmode tests.
3117
/// A scene is either loaded successfully, or the loading process has timed out and will throw an exception.
@@ -37,27 +23,21 @@ public static IEnumerator AssertIsNetworkSceneLoaded(string sceneName, NetworkSc
3723
{
3824
Assert.That(networkSceneManager != null, "NetworkSceneManager instance is null!");
3925

40-
var waitForNetworkSceneLoad = new WaitForNetworkSceneLoad(sceneName, networkSceneManager);
41-
42-
yield return waitForNetworkSceneLoad;
43-
44-
Assert.That(!waitForNetworkSceneLoad.TimedOut);
26+
yield return new WaitForNetworkSceneLoad(sceneName, networkSceneManager);
4527
}
4628

4729
/// <summary>
4830
/// Custom IEnumerator class to validate the loading of a Scene by name. If a scene load lasts longer than
4931
/// k_MaxSceneLoadDuration it is considered a timeout.
5032
/// </summary>
51-
class WaitForSceneLoad : CustomYieldInstruction
33+
public class WaitForSceneLoad : CustomYieldInstruction
5234
{
5335
string m_SceneName;
5436

5537
float m_LoadSceneStart;
5638

5739
float m_MaxLoadDuration;
5840

59-
public bool TimedOut { get; private set; }
60-
6141
public override bool keepWaiting
6242
{
6343
get
@@ -68,12 +48,10 @@ public override bool keepWaiting
6848

6949
if (Time.time - m_LoadSceneStart >= m_MaxLoadDuration)
7050
{
71-
TimedOut = true;
72-
7351
throw new Exception($"Timeout for scene load for scene name {m_SceneName}");
7452
}
7553

76-
return !isSceneLoaded && !TimedOut;
54+
return !isSceneLoaded;
7755
}
7856
}
7957

@@ -101,22 +79,18 @@ class WaitForNetworkSceneLoad : CustomYieldInstruction
10179

10280
NetworkSceneManager m_NetworkSceneManager;
10381

104-
public bool TimedOut { get; private set; }
105-
10682
public override bool keepWaiting
10783
{
10884
get
10985
{
11086
if (Time.time - m_LoadSceneStart >= m_MaxLoadDuration)
11187
{
112-
TimedOut = true;
113-
114-
m_NetworkSceneManager.OnSceneEvent -= ConfirmSceneLoad;
88+
m_NetworkSceneManager.OnLoadEventCompleted -= ConfirmSceneLoad;
11589

11690
throw new Exception($"Timeout for network scene load for scene name {m_SceneName}");
11791
}
11892

119-
return !m_IsNetworkSceneLoaded && !TimedOut;
93+
return !m_IsNetworkSceneLoaded;
12094
}
12195
}
12296

@@ -128,17 +102,16 @@ public WaitForNetworkSceneLoad(string sceneName, NetworkSceneManager networkScen
128102

129103
m_NetworkSceneManager = networkSceneManager;
130104

131-
m_NetworkSceneManager.OnSceneEvent += ConfirmSceneLoad;
105+
m_NetworkSceneManager.OnLoadEventCompleted += ConfirmSceneLoad;
132106
}
133107

134-
void ConfirmSceneLoad(SceneEvent sceneEvent)
108+
void ConfirmSceneLoad(string sceneName, LoadSceneMode loadSceneMode, List<ulong> clientsCompleted, List<ulong> clientsTimedOut)
135109
{
136-
if (sceneEvent.SceneName == m_SceneName &&
137-
sceneEvent.SceneEventType == SceneEventType.LoadEventCompleted)
110+
if (sceneName == m_SceneName)
138111
{
139112
m_IsNetworkSceneLoaded = true;
140113

141-
m_NetworkSceneManager.OnSceneEvent -= ConfirmSceneLoad;
114+
m_NetworkSceneManager.OnLoadEventCompleted -= ConfirmSceneLoad;
142115
}
143116
}
144117
}

0 commit comments

Comments
 (0)