1
1
using System ;
2
2
using System . Collections ;
3
+ using System . Collections . Generic ;
3
4
using UnityEngine ;
4
5
using NUnit . Framework ;
5
6
using Unity . Netcode ;
@@ -11,21 +12,6 @@ public abstract class TestUtilities
11
12
{
12
13
const float k_MaxSceneLoadDuration = 10f ;
13
14
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
-
29
15
/// <summary>
30
16
/// Helper wrapper method for asserting the completion of a network scene load to be used inside Playmode tests.
31
17
/// 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
37
23
{
38
24
Assert . That ( networkSceneManager != null , "NetworkSceneManager instance is null!" ) ;
39
25
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 ) ;
45
27
}
46
28
47
29
/// <summary>
48
30
/// Custom IEnumerator class to validate the loading of a Scene by name. If a scene load lasts longer than
49
31
/// k_MaxSceneLoadDuration it is considered a timeout.
50
32
/// </summary>
51
- class WaitForSceneLoad : CustomYieldInstruction
33
+ public class WaitForSceneLoad : CustomYieldInstruction
52
34
{
53
35
string m_SceneName ;
54
36
55
37
float m_LoadSceneStart ;
56
38
57
39
float m_MaxLoadDuration ;
58
40
59
- public bool TimedOut { get ; private set ; }
60
-
61
41
public override bool keepWaiting
62
42
{
63
43
get
@@ -68,12 +48,10 @@ public override bool keepWaiting
68
48
69
49
if ( Time . time - m_LoadSceneStart >= m_MaxLoadDuration )
70
50
{
71
- TimedOut = true ;
72
-
73
51
throw new Exception ( $ "Timeout for scene load for scene name { m_SceneName } ") ;
74
52
}
75
53
76
- return ! isSceneLoaded && ! TimedOut ;
54
+ return ! isSceneLoaded ;
77
55
}
78
56
}
79
57
@@ -101,22 +79,18 @@ class WaitForNetworkSceneLoad : CustomYieldInstruction
101
79
102
80
NetworkSceneManager m_NetworkSceneManager ;
103
81
104
- public bool TimedOut { get ; private set ; }
105
-
106
82
public override bool keepWaiting
107
83
{
108
84
get
109
85
{
110
86
if ( Time . time - m_LoadSceneStart >= m_MaxLoadDuration )
111
87
{
112
- TimedOut = true ;
113
-
114
- m_NetworkSceneManager . OnSceneEvent -= ConfirmSceneLoad ;
88
+ m_NetworkSceneManager . OnLoadEventCompleted -= ConfirmSceneLoad ;
115
89
116
90
throw new Exception ( $ "Timeout for network scene load for scene name { m_SceneName } ") ;
117
91
}
118
92
119
- return ! m_IsNetworkSceneLoaded && ! TimedOut ;
93
+ return ! m_IsNetworkSceneLoaded ;
120
94
}
121
95
}
122
96
@@ -128,17 +102,16 @@ public WaitForNetworkSceneLoad(string sceneName, NetworkSceneManager networkScen
128
102
129
103
m_NetworkSceneManager = networkSceneManager ;
130
104
131
- m_NetworkSceneManager . OnSceneEvent += ConfirmSceneLoad ;
105
+ m_NetworkSceneManager . OnLoadEventCompleted += ConfirmSceneLoad ;
132
106
}
133
107
134
- void ConfirmSceneLoad ( SceneEvent sceneEvent )
108
+ void ConfirmSceneLoad ( string sceneName , LoadSceneMode loadSceneMode , List < ulong > clientsCompleted , List < ulong > clientsTimedOut )
135
109
{
136
- if ( sceneEvent . SceneName == m_SceneName &&
137
- sceneEvent . SceneEventType == SceneEventType . LoadEventCompleted )
110
+ if ( sceneName == m_SceneName )
138
111
{
139
112
m_IsNetworkSceneLoaded = true ;
140
113
141
- m_NetworkSceneManager . OnSceneEvent -= ConfirmSceneLoad ;
114
+ m_NetworkSceneManager . OnLoadEventCompleted -= ConfirmSceneLoad ;
142
115
}
143
116
}
144
117
}
0 commit comments