@@ -420,7 +420,7 @@ public bool ActiveSceneSynchronizationEnabled
420420 /// The Scene.Handle aspect allows us to distinguish duplicated in-scene placed NetworkObjects created by the loading
421421 /// of the same additive scene multiple times.
422422 /// </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 ( ) ;
424424
425425 /// <summary>
426426 /// 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
436436 /// The client links the server scene handle to the client local scene handle upon a scene being loaded
437437 /// <see cref="GetAndAddNewlyLoadedSceneByName"/>
438438 /// </summary>
439- internal Dictionary < int , Scene > ScenesLoaded = new Dictionary < int , Scene > ( ) ;
439+ internal Dictionary < SceneHandle , Scene > ScenesLoaded = new ( ) ;
440440
441441 /// <summary>
442442 /// 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()
456456 /// Since Scene.handle is unique per client, we create a look-up table between the client and server to associate server unique scene
457457 /// instances with client unique scene instances
458458 /// </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 ( ) ;
461461
462462 internal bool IsRestoringSession ;
463463 /// <summary>
464464 /// Add the client to server (and vice versa) scene handle lookup.
465465 /// Add the client-side handle to scene entry in the HandleToScene table.
466466 /// If it fails (i.e. already added) it returns false.
467467 /// </summary>
468- internal bool UpdateServerClientSceneHandle ( int serverHandle , int clientHandle , Scene localScene )
468+ internal bool UpdateServerClientSceneHandle ( SceneHandle serverHandle , SceneHandle clientHandle , Scene localScene )
469469 {
470470 if ( ! ServerSceneHandleToClientSceneHandle . ContainsKey ( serverHandle ) )
471471 {
@@ -498,7 +498,7 @@ internal bool UpdateServerClientSceneHandle(int serverHandle, int clientHandle,
498498 /// Removes the client to server (and vice versa) scene handles.
499499 /// If it fails (i.e. already removed) it returns false.
500500 /// </summary>
501- internal bool RemoveServerClientSceneHandle ( int serverHandle , int clientHandle )
501+ internal bool RemoveServerClientSceneHandle ( SceneHandle serverHandle , SceneHandle clientHandle )
502502 {
503503 if ( ServerSceneHandleToClientSceneHandle . ContainsKey ( serverHandle ) )
504504 {
@@ -989,7 +989,7 @@ internal Scene GetAndAddNewlyLoadedSceneByName(string sceneName)
989989 /// value. Scene handles are used to distinguish between in-scene placed NetworkObjects under this situation.
990990 /// </summary>
991991 /// <param name="serverSceneHandle"></param>
992- internal void SetTheSceneBeingSynchronized ( int serverSceneHandle )
992+ internal void SetTheSceneBeingSynchronized ( SceneHandle serverSceneHandle )
993993 {
994994 var clientSceneHandle = serverSceneHandle ;
995995 if ( ServerSceneHandleToClientSceneHandle . ContainsKey ( serverSceneHandle ) )
@@ -1037,20 +1037,19 @@ internal void SetTheSceneBeingSynchronized(int serverSceneHandle)
10371037 /// <summary>
10381038 /// During soft synchronization of in-scene placed NetworkObjects, this is now used by NetworkSpawnManager.CreateLocalNetworkObject
10391039 /// </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 )
10431041 {
10441042 if ( ScenePlacedObjects . ContainsKey ( globalObjectIdHash ) )
10451043 {
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 ) )
10481047 {
1049- sceneHandle = ServerSceneHandleToClientSceneHandle [ networkSceneHandle . Value ] ;
1048+ sceneHandle = clientHandle ;
10501049 }
1051- if ( ScenePlacedObjects [ globalObjectIdHash ] . ContainsKey ( sceneHandle ) )
1050+ if ( ScenePlacedObjects [ globalObjectIdHash ] . TryGetValue ( sceneHandle , out var scenePlaceObject ) )
10521051 {
1053- return ScenePlacedObjects [ globalObjectIdHash ] [ sceneHandle ] ;
1052+ return scenePlaceObject ;
10541053 }
10551054 }
10561055 return null ;
@@ -1252,7 +1251,7 @@ private bool OnSceneEventProgressCompleted(SceneEventProgress sceneEventProgress
12521251 public SceneEventProgressStatus UnloadScene ( Scene scene )
12531252 {
12541253 var sceneName = scene . name ;
1255- var sceneHandle = scene . handle ;
1254+ SceneHandle sceneHandle = scene . handle ;
12561255
12571256 if ( ! scene . isLoaded )
12581257 {
@@ -2751,7 +2750,7 @@ internal void PopulateScenePlacedObjects(Scene sceneToFilterBy, bool clearSceneP
27512750 {
27522751 if ( ! ScenePlacedObjects . ContainsKey ( globalObjectIdHash ) )
27532752 {
2754- ScenePlacedObjects . Add ( globalObjectIdHash , new Dictionary < int , NetworkObject > ( ) ) ;
2753+ ScenePlacedObjects . Add ( globalObjectIdHash , new Dictionary < SceneHandle , NetworkObject > ( ) ) ;
27552754 }
27562755
27572756 if ( ! ScenePlacedObjects [ globalObjectIdHash ] . ContainsKey ( sceneHandle ) )
@@ -2797,7 +2796,10 @@ internal void MoveObjectsFromDontDestroyOnLoadToScene(Scene scene)
27972796 }
27982797 else
27992798 {
2800- networkObject . NetworkSceneHandle = ClientSceneHandleToServerSceneHandle [ scene . handle ] ;
2799+ if ( ClientSceneHandleToServerSceneHandle . TryGetValue ( scene . handle , out var handle ) )
2800+ {
2801+ networkObject . NetworkSceneHandle = handle ;
2802+ }
28012803 }
28022804 networkObject . SceneOriginHandle = scene . handle ;
28032805 }
@@ -2812,7 +2814,7 @@ internal void MoveObjectsFromDontDestroyOnLoadToScene(Scene scene)
28122814 /// Holds a list of scene handles (server-side relative) and NetworkObjects migrated into it
28132815 /// during the current frame.
28142816 /// </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 ( ) ;
28162818
28172819 internal bool IsSceneEventInProgress ( )
28182820 {
@@ -2917,18 +2919,16 @@ internal void MigrateNetworkObjectsIntoScenes()
29172919 {
29182920 foreach ( var sceneEntry in ObjectsMigratedIntoNewScene )
29192921 {
2920- if ( ServerSceneHandleToClientSceneHandle . ContainsKey ( sceneEntry . Key ) )
2922+ if ( ServerSceneHandleToClientSceneHandle . TryGetValue ( sceneEntry . Key , out var clientSceneHandle ) )
29212923 {
2922- var clientSceneHandle = ServerSceneHandleToClientSceneHandle [ sceneEntry . Key ] ;
29232924 foreach ( var ownerEntry in sceneEntry . Value )
29242925 {
29252926 if ( ownerEntry . Key == NetworkManager . LocalClientId )
29262927 {
29272928 continue ;
29282929 }
2929- if ( ScenesLoaded . ContainsKey ( clientSceneHandle ) )
2930+ if ( ScenesLoaded . TryGetValue ( clientSceneHandle , out var scene ) )
29302931 {
2931- var scene = ScenesLoaded [ clientSceneHandle ] ;
29322932 foreach ( var networkObject in ownerEntry . Value )
29332933 {
29342934 SceneManager . MoveGameObjectToScene ( networkObject . gameObject , scene ) ;
@@ -2947,7 +2947,7 @@ internal void MigrateNetworkObjectsIntoScenes()
29472947 }
29482948
29492949
2950- private List < int > m_ScenesToRemoveFromObjectMigration = new List < int > ( ) ;
2950+ private List < SceneHandle > m_ScenesToRemoveFromObjectMigration = new ( ) ;
29512951
29522952 /// <summary>
29532953 /// Should be invoked during PostLateUpdate just prior to the NetworkMessageManager processes its outbound message queue.
@@ -3025,7 +3025,7 @@ internal void CheckForAndSendNetworkObjectSceneChanged()
30253025 internal struct DeferredObjectsMovedEvent
30263026 {
30273027 internal ulong OwnerId ;
3028- internal Dictionary < int , List < ulong > > ObjectsMigratedTable ;
3028+ internal Dictionary < SceneHandle , List < ulong > > ObjectsMigratedTable ;
30293029 }
30303030 internal List < DeferredObjectsMovedEvent > DeferredObjectsMovedEvents = new List < DeferredObjectsMovedEvent > ( ) ;
30313031
@@ -3167,9 +3167,15 @@ public List<SceneMap> GetSceneMapping(MapTypes mapType)
31673167 var sceneMap = new SceneMap ( )
31683168 {
31693169 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
31703175 ServerHandle = entry . Key ,
31713176 MappedLocalHandle = entry . Value ,
31723177 LocalHandle = scene . handle ,
3178+ #endif
31733179 Scene = scene ,
31743180 ScenePresent = sceneIsPresent ,
31753181 SceneName = sceneIsPresent ? scene . name : "NotPresent" ,
@@ -3186,9 +3192,15 @@ public List<SceneMap> GetSceneMapping(MapTypes mapType)
31863192 var sceneMap = new SceneMap ( )
31873193 {
31883194 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 ,
31913202 LocalHandle = scene . handle ,
3203+ #endif
31923204 Scene = scene ,
31933205 ScenePresent = sceneIsPresent ,
31943206 SceneName = sceneIsPresent ? scene . name : "NotPresent" ,
0 commit comments