@@ -420,7 +420,7 @@ public bool ActiveSceneSynchronizationEnabled
420
420
/// The Scene.Handle aspect allows us to distinguish duplicated in-scene placed NetworkObjects created by the loading
421
421
/// of the same additive scene multiple times.
422
422
/// </summary>
423
- internal readonly Dictionary < uint , Dictionary < int , NetworkObject > > ScenePlacedObjects = new Dictionary < uint , Dictionary < int , NetworkObject > > ( ) ;
423
+ internal readonly Dictionary < uint , Dictionary < SceneHandle , NetworkObject > > ScenePlacedObjects = new ( ) ;
424
424
425
425
/// <summary>
426
426
/// This is used for the deserialization of in-scene placed NetworkObjects in order to distinguish duplicated in-scene
@@ -436,7 +436,7 @@ public bool ActiveSceneSynchronizationEnabled
436
436
/// The client links the server scene handle to the client local scene handle upon a scene being loaded
437
437
/// <see cref="GetAndAddNewlyLoadedSceneByName"/>
438
438
/// </summary>
439
- internal Dictionary < int , Scene > ScenesLoaded = new Dictionary < int , Scene > ( ) ;
439
+ internal Dictionary < SceneHandle , Scene > ScenesLoaded = new ( ) ;
440
440
441
441
/// <summary>
442
442
/// Returns the currently loaded scenes that are synchronized with the session owner or server depending upon the selected
@@ -456,16 +456,16 @@ public List<Scene> GetSynchronizedScenes()
456
456
/// Since Scene.handle is unique per client, we create a look-up table between the client and server to associate server unique scene
457
457
/// instances with client unique scene instances
458
458
/// </summary>
459
- internal Dictionary < int , int > ServerSceneHandleToClientSceneHandle = new Dictionary < int , int > ( ) ;
460
- internal Dictionary < int , int > ClientSceneHandleToServerSceneHandle = new Dictionary < int , int > ( ) ;
459
+ internal Dictionary < SceneHandle , SceneHandle > ServerSceneHandleToClientSceneHandle = new ( ) ;
460
+ internal Dictionary < SceneHandle , SceneHandle > ClientSceneHandleToServerSceneHandle = new ( ) ;
461
461
462
462
internal bool IsRestoringSession ;
463
463
/// <summary>
464
464
/// Add the client to server (and vice versa) scene handle lookup.
465
465
/// Add the client-side handle to scene entry in the HandleToScene table.
466
466
/// If it fails (i.e. already added) it returns false.
467
467
/// </summary>
468
- internal bool UpdateServerClientSceneHandle ( int serverHandle , int clientHandle , Scene localScene )
468
+ internal bool UpdateServerClientSceneHandle ( SceneHandle serverHandle , SceneHandle clientHandle , Scene localScene )
469
469
{
470
470
if ( ! ServerSceneHandleToClientSceneHandle . ContainsKey ( serverHandle ) )
471
471
{
@@ -498,7 +498,7 @@ internal bool UpdateServerClientSceneHandle(int serverHandle, int clientHandle,
498
498
/// Removes the client to server (and vice versa) scene handles.
499
499
/// If it fails (i.e. already removed) it returns false.
500
500
/// </summary>
501
- internal bool RemoveServerClientSceneHandle ( int serverHandle , int clientHandle )
501
+ internal bool RemoveServerClientSceneHandle ( SceneHandle serverHandle , SceneHandle clientHandle )
502
502
{
503
503
if ( ServerSceneHandleToClientSceneHandle . ContainsKey ( serverHandle ) )
504
504
{
@@ -989,7 +989,7 @@ internal Scene GetAndAddNewlyLoadedSceneByName(string sceneName)
989
989
/// value. Scene handles are used to distinguish between in-scene placed NetworkObjects under this situation.
990
990
/// </summary>
991
991
/// <param name="serverSceneHandle"></param>
992
- internal void SetTheSceneBeingSynchronized ( int serverSceneHandle )
992
+ internal void SetTheSceneBeingSynchronized ( SceneHandle serverSceneHandle )
993
993
{
994
994
var clientSceneHandle = serverSceneHandle ;
995
995
if ( ServerSceneHandleToClientSceneHandle . ContainsKey ( serverSceneHandle ) )
@@ -1037,20 +1037,19 @@ internal void SetTheSceneBeingSynchronized(int serverSceneHandle)
1037
1037
/// <summary>
1038
1038
/// During soft synchronization of in-scene placed NetworkObjects, this is now used by NetworkSpawnManager.CreateLocalNetworkObject
1039
1039
/// </summary>
1040
- /// <param name="globalObjectIdHash"></param>
1041
- /// <returns></returns>
1042
- internal NetworkObject GetSceneRelativeInSceneNetworkObject ( uint globalObjectIdHash , int ? networkSceneHandle )
1040
+ internal NetworkObject GetSceneRelativeInSceneNetworkObject ( uint globalObjectIdHash , SceneHandle ? networkSceneHandle )
1043
1041
{
1044
1042
if ( ScenePlacedObjects . ContainsKey ( globalObjectIdHash ) )
1045
1043
{
1046
- var sceneHandle = SceneBeingSynchronized . handle ;
1047
- if ( networkSceneHandle . HasValue && networkSceneHandle . Value != 0 && ServerSceneHandleToClientSceneHandle . ContainsKey ( networkSceneHandle . Value ) )
1044
+ SceneHandle sceneHandle = SceneBeingSynchronized . handle ;
1045
+ if ( networkSceneHandle . HasValue && networkSceneHandle . Value != SceneHandle . None &&
1046
+ ServerSceneHandleToClientSceneHandle . TryGetValue ( networkSceneHandle . Value , out var clientHandle ) )
1048
1047
{
1049
- sceneHandle = ServerSceneHandleToClientSceneHandle [ networkSceneHandle . Value ] ;
1048
+ sceneHandle = clientHandle ;
1050
1049
}
1051
- if ( ScenePlacedObjects [ globalObjectIdHash ] . ContainsKey ( sceneHandle ) )
1050
+ if ( ScenePlacedObjects [ globalObjectIdHash ] . TryGetValue ( sceneHandle , out var scenePlaceObject ) )
1052
1051
{
1053
- return ScenePlacedObjects [ globalObjectIdHash ] [ sceneHandle ] ;
1052
+ return scenePlaceObject ;
1054
1053
}
1055
1054
}
1056
1055
return null ;
@@ -1252,7 +1251,7 @@ private bool OnSceneEventProgressCompleted(SceneEventProgress sceneEventProgress
1252
1251
public SceneEventProgressStatus UnloadScene ( Scene scene )
1253
1252
{
1254
1253
var sceneName = scene . name ;
1255
- var sceneHandle = scene . handle ;
1254
+ SceneHandle sceneHandle = scene . handle ;
1256
1255
1257
1256
if ( ! scene . isLoaded )
1258
1257
{
@@ -2751,7 +2750,7 @@ internal void PopulateScenePlacedObjects(Scene sceneToFilterBy, bool clearSceneP
2751
2750
{
2752
2751
if ( ! ScenePlacedObjects . ContainsKey ( globalObjectIdHash ) )
2753
2752
{
2754
- ScenePlacedObjects . Add ( globalObjectIdHash , new Dictionary < int , NetworkObject > ( ) ) ;
2753
+ ScenePlacedObjects . Add ( globalObjectIdHash , new Dictionary < SceneHandle , NetworkObject > ( ) ) ;
2755
2754
}
2756
2755
2757
2756
if ( ! ScenePlacedObjects [ globalObjectIdHash ] . ContainsKey ( sceneHandle ) )
@@ -2797,7 +2796,10 @@ internal void MoveObjectsFromDontDestroyOnLoadToScene(Scene scene)
2797
2796
}
2798
2797
else
2799
2798
{
2800
- networkObject . NetworkSceneHandle = ClientSceneHandleToServerSceneHandle [ scene . handle ] ;
2799
+ if ( ClientSceneHandleToServerSceneHandle . TryGetValue ( scene . handle , out var handle ) )
2800
+ {
2801
+ networkObject . NetworkSceneHandle = handle ;
2802
+ }
2801
2803
}
2802
2804
networkObject . SceneOriginHandle = scene . handle ;
2803
2805
}
@@ -2812,7 +2814,7 @@ internal void MoveObjectsFromDontDestroyOnLoadToScene(Scene scene)
2812
2814
/// Holds a list of scene handles (server-side relative) and NetworkObjects migrated into it
2813
2815
/// during the current frame.
2814
2816
/// </summary>
2815
- internal Dictionary < int , Dictionary < ulong , List < NetworkObject > > > ObjectsMigratedIntoNewScene = new Dictionary < int , Dictionary < ulong , List < NetworkObject > > > ( ) ;
2817
+ internal Dictionary < SceneHandle , Dictionary < ulong , List < NetworkObject > > > ObjectsMigratedIntoNewScene = new ( ) ;
2816
2818
2817
2819
internal bool IsSceneEventInProgress ( )
2818
2820
{
@@ -2917,18 +2919,16 @@ internal void MigrateNetworkObjectsIntoScenes()
2917
2919
{
2918
2920
foreach ( var sceneEntry in ObjectsMigratedIntoNewScene )
2919
2921
{
2920
- if ( ServerSceneHandleToClientSceneHandle . ContainsKey ( sceneEntry . Key ) )
2922
+ if ( ServerSceneHandleToClientSceneHandle . TryGetValue ( sceneEntry . Key , out var clientSceneHandle ) )
2921
2923
{
2922
- var clientSceneHandle = ServerSceneHandleToClientSceneHandle [ sceneEntry . Key ] ;
2923
2924
foreach ( var ownerEntry in sceneEntry . Value )
2924
2925
{
2925
2926
if ( ownerEntry . Key == NetworkManager . LocalClientId )
2926
2927
{
2927
2928
continue ;
2928
2929
}
2929
- if ( ScenesLoaded . ContainsKey ( clientSceneHandle ) )
2930
+ if ( ScenesLoaded . TryGetValue ( clientSceneHandle , out var scene ) )
2930
2931
{
2931
- var scene = ScenesLoaded [ clientSceneHandle ] ;
2932
2932
foreach ( var networkObject in ownerEntry . Value )
2933
2933
{
2934
2934
SceneManager . MoveGameObjectToScene ( networkObject . gameObject , scene ) ;
@@ -2947,7 +2947,7 @@ internal void MigrateNetworkObjectsIntoScenes()
2947
2947
}
2948
2948
2949
2949
2950
- private List < int > m_ScenesToRemoveFromObjectMigration = new List < int > ( ) ;
2950
+ private List < SceneHandle > m_ScenesToRemoveFromObjectMigration = new ( ) ;
2951
2951
2952
2952
/// <summary>
2953
2953
/// Should be invoked during PostLateUpdate just prior to the NetworkMessageManager processes its outbound message queue.
@@ -3025,7 +3025,7 @@ internal void CheckForAndSendNetworkObjectSceneChanged()
3025
3025
internal struct DeferredObjectsMovedEvent
3026
3026
{
3027
3027
internal ulong OwnerId ;
3028
- internal Dictionary < int , List < ulong > > ObjectsMigratedTable ;
3028
+ internal Dictionary < SceneHandle , List < ulong > > ObjectsMigratedTable ;
3029
3029
}
3030
3030
internal List < DeferredObjectsMovedEvent > DeferredObjectsMovedEvents = new List < DeferredObjectsMovedEvent > ( ) ;
3031
3031
@@ -3167,9 +3167,15 @@ public List<SceneMap> GetSceneMapping(MapTypes mapType)
3167
3167
var sceneMap = new SceneMap ( )
3168
3168
{
3169
3169
MapType = mapType ,
3170
+ #if SCENE_MANAGEMENT_SCENE_HANDLE_NO_INT_CONVERSION
3171
+ ServerHandle = entry . Key . GetRawData ( ) ,
3172
+ MappedLocalHandle = entry . Value . GetRawData ( ) ,
3173
+ LocalHandle = scene . handle . GetRawData ( ) ,
3174
+ #else
3170
3175
ServerHandle = entry . Key ,
3171
3176
MappedLocalHandle = entry . Value ,
3172
3177
LocalHandle = scene . handle ,
3178
+ #endif
3173
3179
Scene = scene ,
3174
3180
ScenePresent = sceneIsPresent ,
3175
3181
SceneName = sceneIsPresent ? scene . name : "NotPresent" ,
@@ -3186,9 +3192,15 @@ public List<SceneMap> GetSceneMapping(MapTypes mapType)
3186
3192
var sceneMap = new SceneMap ( )
3187
3193
{
3188
3194
MapType = mapType ,
3189
- ServerHandle = entry . Value ,
3190
- MappedLocalHandle = entry . Key ,
3195
+ #if SCENE_MANAGEMENT_SCENE_HANDLE_NO_INT_CONVERSION
3196
+ ServerHandle = entry . Key ,
3197
+ MappedLocalHandle = entry . Value ,
3198
+ LocalHandle = scene . handle ,
3199
+ #else
3200
+ ServerHandle = entry . Key ,
3201
+ MappedLocalHandle = entry . Value ,
3191
3202
LocalHandle = scene . handle ,
3203
+ #endif
3192
3204
Scene = scene ,
3193
3205
ScenePresent = sceneIsPresent ,
3194
3206
SceneName = sceneIsPresent ? scene . name : "NotPresent" ,
0 commit comments