Skip to content

Commit 94cb5ac

Browse files
committed
fix: GetSceneMapping final int->ulong conversion
1 parent 4b99f27 commit 94cb5ac

File tree

3 files changed

+88
-38
lines changed

3 files changed

+88
-38
lines changed

.yamato/_triggers.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ pr_code_changes_checks:
8787
# Coverage on other standalone machines is present in Nightly job so it's enough to not run all of them for PRs
8888
# desktop_standalone_test and cmb_service_standalone_test are both reusing desktop_standalone_build dependency so we run those in the same configuration on PRs to reduce waiting time.
8989
# Note that our daily tests will anyway run both test configurations in "minimal supported" and "trunk" configurations
90-
- .yamato/desktop-standalone-tests.yml#desktop_standalone_test_testproject_ubuntu_il2cpp_trunk
91-
- .yamato/cmb-service-standalone-tests.yml#cmb_service_standalone_test_testproject_ubuntu_il2cpp_trunk
90+
# TODO: Move these tests back to trunk
91+
- .yamato/desktop-standalone-tests.yml#desktop_standalone_test_testproject_ubuntu_il2cpp_6000.4
92+
- .yamato/cmb-service-standalone-tests.yml#cmb_service_standalone_test_testproject_ubuntu_il2cpp_6000.4
9293
triggers:
9394
expression: |-
9495
(pull_request.comment eq "ngo" OR

com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneHandle.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,14 @@ internal NetworkSceneHandle(int handle, bool asMock)
9292
/// <summary>
9393
/// Implicit conversion from <see cref="SceneHandle"/> to <see cref="NetworkSceneHandle"/>.
9494
/// </summary>
95-
/// <param name="handle"></param>
95+
/// <param name="handle">The SceneHandle to covert</param>
9696
public static implicit operator NetworkSceneHandle(SceneHandle handle) => new(handle);
97+
98+
/// <summary>
99+
/// Implicit conversion from <see cref="NetworkSceneHandle"/> to <see cref="SceneHandle"/>.
100+
/// </summary>
101+
/// <param name="handle">The NetworkSceneHandle to convert</param>
102+
public static implicit operator SceneHandle(NetworkSceneHandle handle) => handle.m_Handle;
97103
#else
98104
/// <summary>
99105
/// Implicit conversion from <see langword="int"/> to <see cref="NetworkSceneHandle"/>.

com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs

Lines changed: 78 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3115,19 +3115,67 @@ public struct SceneMap : INetworkSerializable
31153115
/// The name of the scene
31163116
/// </summary>
31173117
public string SceneName;
3118+
3119+
#if SCENE_MANAGEMENT_SCENE_HANDLE_NO_INT_CONVERSION
3120+
/// <summary>
3121+
/// The scene's server handle (a.k.a network scene handle)
3122+
/// </summary>
3123+
/// <remarks>
3124+
/// This is deprecated in favor of ServerSceneHandle
3125+
/// </remarks>
3126+
[Obsolete("Int representation of a SceneHandle is deprecated, please use SceneHandle instead. (UnityUpgradable) -> ServerSceneHandle")]
3127+
#else
31183128
/// <summary>
31193129
/// The scene's server handle (a.k.a network scene handle)
31203130
/// </summary>
3131+
#endif
31213132
public int ServerHandle;
3133+
3134+
#if SCENE_MANAGEMENT_SCENE_HANDLE_NO_INT_CONVERSION
3135+
/// <summary>
3136+
/// The mapped handled. This could be the ServerHandle or LocalHandle depending upon context (client or server).
3137+
/// </summary>
3138+
/// <remarks>
3139+
/// This is deprecated in favor of MappedLocalSceneHandle
3140+
/// </remarks>
3141+
[Obsolete("Int representation of a SceneHandle is deprecated, please use SceneHandle instead. (UnityUpgradable) -> MappedLocalSceneHandle")]
3142+
#else
31223143
/// <summary>
31233144
/// The mapped handled. This could be the ServerHandle or LocalHandle depending upon context (client or server).
31243145
/// </summary>
3146+
#endif
31253147
public int MappedLocalHandle;
3148+
3149+
#if SCENE_MANAGEMENT_SCENE_HANDLE_NO_INT_CONVERSION
3150+
/// <summary>
3151+
/// The local handle of the scene.
3152+
/// </summary>
3153+
/// <remarks>
3154+
/// This is deprecated in favor of LocalSceneHandle
3155+
/// </remarks>
3156+
[Obsolete("Int representation of a SceneHandle is deprecated, please use SceneHandle instead. (UnityUpgradable) -> LocalSceneHandle")]
3157+
#else
31263158
/// <summary>
31273159
/// The local handle of the scene.
31283160
/// </summary>
3161+
#endif
31293162
public int LocalHandle;
31303163

3164+
#if SCENE_MANAGEMENT_SCENE_HANDLE_AVAILABLE
3165+
/// <summary>
3166+
/// The scene's server handle (a.k.a network scene handle)
3167+
/// </summary>
3168+
public SceneHandle ServerSceneHandle;
3169+
/// <summary>
3170+
/// The mapped handled. This could be the ServerSceneHandle or LocalSceneHandle depending upon context (client or server).
3171+
/// </summary>
3172+
public SceneHandle MappedLocalSceneHandle;
3173+
/// <summary>
3174+
/// The local handle of the scene.
3175+
/// </summary>
3176+
public SceneHandle LocalSceneHandle;
3177+
#endif
3178+
31313179
/// <inheritdoc cref="INetworkSerializable.NetworkSerialize{T}(BufferSerializer{T})"/>
31323180
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
31333181
{
@@ -3156,43 +3204,38 @@ public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReade
31563204
public List<SceneMap> GetSceneMapping(MapTypes mapType)
31573205
{
31583206
var mapping = new List<SceneMap>();
3159-
if (mapType == MapTypes.ServerToClient)
3160-
{
3161-
foreach (var entry in ServerSceneHandleToClientSceneHandle)
3162-
{
3163-
var scene = ScenesLoaded[entry.Value];
3164-
var sceneIsPresent = scene.IsValid() && scene.isLoaded;
3165-
var sceneMap = new SceneMap()
3166-
{
3167-
MapType = mapType,
3168-
ServerHandle = entry.Key.GetRawData(),
3169-
MappedLocalHandle = entry.Value.GetRawData(),
3170-
LocalHandle = new NetworkSceneHandle(scene.handle).GetRawData(),
3171-
Scene = scene,
3172-
ScenePresent = sceneIsPresent,
3173-
SceneName = sceneIsPresent ? scene.name : "NotPresent",
3174-
};
3175-
mapping.Add(sceneMap);
3176-
}
3177-
}
3178-
else
3207+
var map = mapType == MapTypes.ServerToClient ? ServerSceneHandleToClientSceneHandle : ClientSceneHandleToServerSceneHandle;
3208+
3209+
foreach (var entry in map)
31793210
{
3180-
foreach (var entry in ClientSceneHandleToServerSceneHandle)
3211+
var scene = ScenesLoaded[entry.Key];
3212+
var sceneIsPresent = scene.IsValid() && scene.isLoaded;
3213+
var sceneMap = new SceneMap()
31813214
{
3182-
var scene = ScenesLoaded[entry.Key];
3183-
var sceneIsPresent = scene.IsValid() && scene.isLoaded;
3184-
var sceneMap = new SceneMap()
3185-
{
3186-
MapType = mapType,
3187-
ServerHandle = entry.Key.GetRawData(),
3188-
MappedLocalHandle = entry.Value.GetRawData(),
3189-
LocalHandle = new NetworkSceneHandle(scene.handle).GetRawData(),
3190-
Scene = scene,
3191-
ScenePresent = sceneIsPresent,
3192-
SceneName = sceneIsPresent ? scene.name : "NotPresent",
3193-
};
3194-
mapping.Add(sceneMap);
3195-
}
3215+
MapType = mapType,
3216+
3217+
#pragma warning disable CS0618 // Type or member is obsolete
3218+
#if SCENE_MANAGEMENT_SCENE_HANDLE_MUST_USE_ULONG
3219+
ServerHandle = (int)entry.Key.GetRawData(),
3220+
MappedLocalHandle = (int)entry.Value.GetRawData(),
3221+
LocalHandle = (int)new NetworkSceneHandle(scene.handle).GetRawData(),
3222+
#else
3223+
ServerHandle = entry.Key.GetRawData(),
3224+
MappedLocalHandle = entry.Value.GetRawData(),
3225+
LocalHandle = new NetworkSceneHandle(scene.handle).GetRawData(),
3226+
#endif
3227+
#pragma warning restore CS0618 // Type or member is obsolete
3228+
3229+
#if SCENE_MANAGEMENT_SCENE_HANDLE_AVAILABLE
3230+
ServerSceneHandle = entry.Key,
3231+
MappedLocalSceneHandle = entry.Value,
3232+
LocalSceneHandle = scene.handle,
3233+
#endif
3234+
Scene = scene,
3235+
ScenePresent = sceneIsPresent,
3236+
SceneName = sceneIsPresent ? scene.name : "NotPresent",
3237+
};
3238+
mapping.Add(sceneMap);
31963239
}
31973240

31983241
return mapping;

0 commit comments

Comments
 (0)