Skip to content

Commit c282dfe

Browse files
committed
Add placeholder SceneHandle object
1 parent a83293a commit c282dfe

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#if !SCENE_MANAGEMENT_SCENE_HANDLE_AVAILABLE
2+
using System;
3+
using System.Runtime.CompilerServices;
4+
5+
namespace Unity.Netcode
6+
{
7+
internal struct SceneHandle : IEquatable<SceneHandle>
8+
{
9+
private int m_Handle;
10+
public static SceneHandle None => default;
11+
12+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
13+
public bool Equals(SceneHandle other)
14+
{
15+
return m_Handle == other.m_Handle;
16+
}
17+
18+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
19+
public override bool Equals(object obj)
20+
{
21+
return obj is SceneHandle other && Equals(other);
22+
}
23+
24+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
25+
public override int GetHashCode()
26+
{
27+
return m_Handle;
28+
}
29+
30+
/// <summary>
31+
/// Test for equality.
32+
/// </summary>
33+
/// <param name="left"></param>
34+
/// <param name="right"></param>
35+
/// <returns>True if the two SceneHandles are the same</returns>
36+
public static bool operator ==(SceneHandle left, SceneHandle right) => left.Equals(right);
37+
38+
/// <summary>
39+
/// Test for inequality.
40+
/// </summary>
41+
/// <param name="left"></param>
42+
/// <param name="right"></param>
43+
/// <returns>True if the two SceneHandles are different</returns>
44+
public static bool operator !=(SceneHandle left, SceneHandle right) => !left.Equals(right);
45+
46+
/// <summary>
47+
/// Implicit conversion from <see langword="int"/> to <see cref="SceneHandle"/>.
48+
/// </summary>
49+
/// <param name="handle"></param>
50+
public static implicit operator SceneHandle(int handle) => new() { m_Handle = handle };
51+
52+
/// <summary>
53+
/// Implicit conversion from <see cref="SceneHandle"/> to <see langword="int"/>.
54+
/// </summary>
55+
/// <param name="handle">The SceneHandle</param>
56+
public static implicit operator int(SceneHandle handle) => handle.m_Handle;
57+
}
58+
}
59+
#endif

com.unity.netcode.gameobjects/Runtime/SceneManagement/SceneHandle.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)