Skip to content

Commit 58f4a4d

Browse files
committed
feat: Added scene switch started event with internal Unity progress exposed
1 parent 9f819cf commit 58f4a4d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

MLAPI/SceneManagement/NetworkSceneManager.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,17 @@ public static class NetworkSceneManager
2323
/// </summary>
2424
public delegate void SceneSwitchedDelegate();
2525
/// <summary>
26+
/// Delegate for when a scene switch has been initiated
27+
/// </summary>
28+
public delegate void SceneSwitchStartedDelegate(AsyncOperation operation);
29+
/// <summary>
2630
/// Event that is invoked when the scene is switched
2731
/// </summary>
2832
public static event SceneSwitchedDelegate OnSceneSwitched;
33+
/// <summary>
34+
/// Event that is invoked when a local scene switch has started
35+
/// </summary>
36+
public static event SceneSwitchStartedDelegate OnSceneSwitchStarted;
2937

3038
internal static readonly HashSet<string> registeredSceneNames = new HashSet<string>();
3139
internal static readonly Dictionary<string, uint> sceneNameToIndex = new Dictionary<string, uint>();
@@ -105,12 +113,18 @@ public static SceneSwitchProgress SwitchScene(string sceneName)
105113

106114
// Switch scene
107115
AsyncOperation sceneLoad = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Single);
116+
108117
nextSceneName = sceneName;
109118

110119
sceneLoad.completed += (AsyncOperation asyncOp2) => { OnSceneLoaded(switchSceneProgress.guid, null); };
111120

112121
switchSceneProgress.SetSceneLoadOperation(sceneLoad);
113122

123+
if (OnSceneSwitchStarted != null)
124+
{
125+
OnSceneSwitchStarted(sceneLoad);
126+
}
127+
114128
return switchSceneProgress;
115129
}
116130

@@ -137,12 +151,18 @@ internal static void OnSceneSwitch(uint sceneIndex, Guid switchSceneGuid, Stream
137151
string sceneName = sceneIndexToString[sceneIndex];
138152

139153
AsyncOperation sceneLoad = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Single);
154+
140155
nextSceneName = sceneName;
141156

142157
sceneLoad.completed += (AsyncOperation asyncOp2) =>
143158
{
144159
OnSceneLoaded(switchSceneGuid, objectStream);
145160
};
161+
162+
if (OnSceneSwitchStarted != null)
163+
{
164+
OnSceneSwitchStarted(sceneLoad);
165+
}
146166
}
147167

148168
internal static void OnFirstSceneSwitchSync(uint sceneIndex, Guid switchSceneGuid)

0 commit comments

Comments
 (0)