diff --git a/Mirror/Runtime/ClientScene.cs b/Mirror/Runtime/ClientScene.cs index 502deaddf..7c616a35f 100644 --- a/Mirror/Runtime/ClientScene.cs +++ b/Mirror/Runtime/ClientScene.cs @@ -7,7 +7,8 @@ public static class ClientScene { static NetworkIdentity s_LocalPlayer; static NetworkConnection s_ReadyConnection; - static Dictionary s_SpawnableObjects; + // scene id to NetworkIdentity + static Dictionary s_SpawnableObjects; static bool s_IsReady; static bool s_IsSpawnFinished; @@ -27,7 +28,8 @@ internal static void SetNotReady() //NOTE: spawn handlers, prefabs and local objects now live in NetworkScene public static Dictionary objects { get { return s_NetworkScene.localObjects; } } public static Dictionary prefabs { get { return NetworkScene.guidToPrefab; } } - public static Dictionary spawnableObjects { get { return s_SpawnableObjects; } } + // scene id to NetworkIdentity + public static Dictionary spawnableObjects { get { return s_SpawnableObjects; } } internal static void Shutdown() { @@ -167,7 +169,7 @@ internal static void HandleClientDisconnect(NetworkConnection conn) internal static void PrepareToSpawnSceneObjects() { //NOTE: what is there are already objects in this dict?! should we merge with them? - s_SpawnableObjects = new Dictionary(); + s_SpawnableObjects = new Dictionary(); var uvs = Resources.FindObjectsOfTypeAll(); for (int i = 0; i < uvs.Length; i++) { @@ -175,7 +177,7 @@ internal static void PrepareToSpawnSceneObjects() // not spawned yet etc.? if (!uv.gameObject.activeSelf && uv.gameObject.hideFlags != HideFlags.NotEditable && uv.gameObject.hideFlags != HideFlags.HideAndDontSave && - !uv.sceneId.IsEmpty()) + uv.sceneId != 0) { s_SpawnableObjects[uv.sceneId] = uv; if (LogFilter.logDebug) { Debug.Log("ClientScene::PrepareSpawnObjects sceneId:" + uv.sceneId); } @@ -183,7 +185,7 @@ internal static void PrepareToSpawnSceneObjects() } } - internal static NetworkIdentity SpawnSceneObject(NetworkSceneId sceneId) + internal static NetworkIdentity SpawnSceneObject(uint sceneId) { if (s_SpawnableObjects.ContainsKey(sceneId)) { @@ -462,7 +464,7 @@ static void OnObjectDestroy(NetworkMessage netMsg) if (!NetworkScene.InvokeUnSpawnHandler(localObject.assetId, localObject.gameObject)) { // default handling - if (localObject.sceneId.IsEmpty()) + if (localObject.sceneId == 0) { Object.Destroy(localObject.gameObject); } diff --git a/Mirror/Runtime/Messages.cs b/Mirror/Runtime/Messages.cs index 2795f6165..07dd8dd1b 100644 --- a/Mirror/Runtime/Messages.cs +++ b/Mirror/Runtime/Messages.cs @@ -241,14 +241,14 @@ public override void Serialize(NetworkWriter writer) class SpawnSceneObjectMessage : MessageBase { public NetworkInstanceId netId; - public NetworkSceneId sceneId; + public uint sceneId; public Vector3 position; public byte[] payload; public override void Deserialize(NetworkReader reader) { netId = reader.ReadNetworkId(); - sceneId = reader.ReadSceneId(); + sceneId = reader.ReadPackedUInt32(); position = reader.ReadVector3(); payload = reader.ReadBytesAndSize(); } @@ -256,7 +256,7 @@ public override void Deserialize(NetworkReader reader) public override void Serialize(NetworkWriter writer) { writer.Write(netId); - writer.Write(sceneId); + writer.WritePackedUInt32(sceneId); writer.Write(position); writer.WriteBytesAndSize(payload); } diff --git a/Mirror/Runtime/Mirror.Runtime.csproj b/Mirror/Runtime/Mirror.Runtime.csproj index c461c13bc..bf6ad0017 100644 --- a/Mirror/Runtime/Mirror.Runtime.csproj +++ b/Mirror/Runtime/Mirror.Runtime.csproj @@ -73,7 +73,6 @@ - diff --git a/Mirror/Runtime/NetworkIdentity.cs b/Mirror/Runtime/NetworkIdentity.cs index 191b41afa..8dd359694 100644 --- a/Mirror/Runtime/NetworkIdentity.cs +++ b/Mirror/Runtime/NetworkIdentity.cs @@ -16,7 +16,7 @@ namespace Mirror public sealed class NetworkIdentity : MonoBehaviour { // configuration - [SerializeField] NetworkSceneId m_SceneId; + [SerializeField] uint m_SceneId; [SerializeField] NetworkHash128 m_AssetId; [SerializeField] bool m_ServerOnly; [SerializeField] bool m_LocalPlayerAuthority; @@ -46,7 +46,7 @@ public sealed class NetworkIdentity : MonoBehaviour public bool hasAuthority { get { return m_HasAuthority; } } public NetworkInstanceId netId { get { return m_NetId; } } - public NetworkSceneId sceneId { get { return m_SceneId; } } + public uint sceneId { get { return m_SceneId; } } public bool serverOnly { get { return m_ServerOnly; } set { m_ServerOnly = value; } } public bool localPlayerAuthority { get { return m_LocalPlayerAuthority; } set { m_LocalPlayerAuthority = value; } } public NetworkConnection clientAuthorityOwner { get { return m_ClientAuthorityOwner; }} @@ -160,7 +160,7 @@ internal void SetNetworkInstanceId(NetworkInstanceId newNetId) // only used when fixing duplicate scene IDs duing post-processing public void ForceSceneId(int newSceneId) { - m_SceneId = new NetworkSceneId((uint)newSceneId); + m_SceneId = (uint)newSceneId; } // only used in SetLocalObject diff --git a/Mirror/Runtime/NetworkReader.cs b/Mirror/Runtime/NetworkReader.cs index a17f32baa..7cad4b115 100644 --- a/Mirror/Runtime/NetworkReader.cs +++ b/Mirror/Runtime/NetworkReader.cs @@ -130,11 +130,6 @@ public NetworkInstanceId ReadNetworkId() return new NetworkInstanceId(ReadPackedUInt32()); } - public NetworkSceneId ReadSceneId() - { - return new NetworkSceneId(ReadPackedUInt32()); - } - public Vector2 ReadVector2() { return new Vector2(ReadSingle(), ReadSingle()); diff --git a/Mirror/Runtime/NetworkScene.cs b/Mirror/Runtime/NetworkScene.cs index 4633cca35..4e8230e42 100644 --- a/Mirror/Runtime/NetworkScene.cs +++ b/Mirror/Runtime/NetworkScene.cs @@ -241,7 +241,7 @@ internal void DestroyAllClientObjects() { if (!InvokeUnSpawnHandler(uv.assetId, uv.gameObject)) { - if (uv.sceneId.IsEmpty()) + if (uv.sceneId == 0) { Object.Destroy(uv.gameObject); } diff --git a/Mirror/Runtime/NetworkSceneId.cs b/Mirror/Runtime/NetworkSceneId.cs deleted file mode 100644 index d09c60462..000000000 --- a/Mirror/Runtime/NetworkSceneId.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using UnityEngine; - -namespace Mirror -{ - [Serializable] - public struct NetworkSceneId : IEquatable - { - public NetworkSceneId(uint value) - { - m_Value = value; - } - - [SerializeField] - uint m_Value; - - public bool IsEmpty() - { - return m_Value == 0; - } - - public override int GetHashCode() - { - return (int)m_Value; - } - - public override bool Equals(object obj) - { - return obj is NetworkSceneId && this == (NetworkSceneId)obj; - } - - public bool Equals(NetworkSceneId other) - { - return this.m_Value == other.m_Value; - } - - public static bool operator==(NetworkSceneId c1, NetworkSceneId c2) - { - return c1.m_Value == c2.m_Value; - } - - public static bool operator!=(NetworkSceneId c1, NetworkSceneId c2) - { - return c1.m_Value != c2.m_Value; - } - - public override string ToString() - { - return m_Value.ToString(); - } - - public uint Value { get { return m_Value; } } - } -} diff --git a/Mirror/Runtime/NetworkServer.cs b/Mirror/Runtime/NetworkServer.cs index 2e8a24c90..38852585f 100644 --- a/Mirror/Runtime/NetworkServer.cs +++ b/Mirror/Runtime/NetworkServer.cs @@ -972,7 +972,7 @@ internal static void SendSpawnMessage(NetworkIdentity uv, NetworkConnection conn if (LogFilter.logDebug) { Debug.Log("Server SendSpawnMessage: name=" + uv.name + " sceneId=" + uv.sceneId + " netid=" + uv.netId); } // for easier debugging // 'uv' is a prefab that should be spawned - if (uv.sceneId.IsEmpty()) + if (uv.sceneId == 0) { SpawnPrefabMessage msg = new SpawnPrefabMessage(); msg.netId = uv.netId; @@ -1257,10 +1257,7 @@ static bool ValidateSceneObject(NetworkIdentity netId) #endif // If not a scene object - if (netId.sceneId.IsEmpty()) - return false; - - return true; + return netId.sceneId != 0; } public static bool SpawnObjects() diff --git a/Mirror/Runtime/NetworkWriter.cs b/Mirror/Runtime/NetworkWriter.cs index cb9c4edcc..8c3c83d5c 100644 --- a/Mirror/Runtime/NetworkWriter.cs +++ b/Mirror/Runtime/NetworkWriter.cs @@ -195,11 +195,6 @@ public void Write(NetworkInstanceId value) WritePackedUInt32(value.Value); } - public void Write(NetworkSceneId value) - { - WritePackedUInt32(value.Value); - } - public void Write(Vector2 value) { Write(value.x); diff --git a/Mirror/Weaver/Weaver.cs b/Mirror/Weaver/Weaver.cs index 3d70f3101..04b2004ce 100644 --- a/Mirror/Weaver/Weaver.cs +++ b/Mirror/Weaver/Weaver.cs @@ -81,7 +81,6 @@ class Weaver public static MethodReference getUNetIdReference; public static TypeReference NetworkIdentityType; public static TypeReference NetworkInstanceIdType; - public static TypeReference NetworkSceneIdType; public static TypeReference IEnumeratorType; public static TypeReference ClientSceneType; @@ -109,10 +108,8 @@ class Weaver public static MethodReference NetworkWriterWritePacked64; public static MethodReference NetworkWriterWriteNetworkInstanceId; - public static MethodReference NetworkWriterWriteNetworkSceneId; public static MethodReference NetworkReaderReadNetworkInstanceId; - public static MethodReference NetworkReaderReadNetworkSceneId; public static MethodReference NetworkInstanceIsEmpty; public static MethodReference NetworkReadUInt16; @@ -1310,7 +1307,6 @@ static void SetupTargetTypes() MemoryStreamCtor = ResolveMethod(MemoryStreamType, ".ctor"); NetworkInstanceIdType = m_UNetAssemblyDefinition.MainModule.GetType("Mirror.NetworkInstanceId"); - NetworkSceneIdType = m_UNetAssemblyDefinition.MainModule.GetType("Mirror.NetworkSceneId"); NetworkServerGetActive = ResolveMethod(NetworkServerType, "get_active"); NetworkServerGetLocalClientActive = ResolveMethod(NetworkServerType, "get_localClientActive"); @@ -1329,10 +1325,8 @@ static void SetupTargetTypes() NetworkWriterWritePacked64 = ResolveMethod(NetworkWriterType, "WritePackedUInt64"); NetworkWriterWriteNetworkInstanceId = ResolveMethodWithArg(NetworkWriterType, "Write", NetworkInstanceIdType); - NetworkWriterWriteNetworkSceneId = ResolveMethodWithArg(NetworkWriterType, "Write", NetworkSceneIdType); NetworkReaderReadNetworkInstanceId = ResolveMethod(NetworkReaderType, "ReadNetworkId"); - NetworkReaderReadNetworkSceneId = ResolveMethod(NetworkReaderType, "ReadSceneId"); NetworkInstanceIsEmpty = ResolveMethod(NetworkInstanceIdType, "IsEmpty"); NetworkReadUInt16 = ResolveMethod(NetworkReaderType, "ReadUInt16"); @@ -1435,7 +1429,6 @@ static void SetupReadFunctions() { gameObjectType.FullName, ResolveMethod(NetworkReaderType, "ReadGameObject") }, { NetworkIdentityType.FullName, ResolveMethod(NetworkReaderType, "ReadNetworkIdentity") }, { NetworkInstanceIdType.FullName, NetworkReaderReadNetworkInstanceId }, - { NetworkSceneIdType.FullName, NetworkReaderReadNetworkSceneId }, { transformType.FullName, ResolveMethod(NetworkReaderType, "ReadTransform") }, { "System.Byte[]", ResolveMethod(NetworkReaderType, "ReadBytesAndSize") }, }; @@ -1473,7 +1466,6 @@ static void SetupWriteFunctions() { gameObjectType.FullName, ResolveMethodWithArg(NetworkWriterType, "Write", gameObjectType) }, { NetworkIdentityType.FullName, ResolveMethodWithArg(NetworkWriterType, "Write", NetworkIdentityType) }, { NetworkInstanceIdType.FullName, NetworkWriterWriteNetworkInstanceId }, - { NetworkSceneIdType.FullName, NetworkWriterWriteNetworkSceneId }, { transformType.FullName, ResolveMethodWithArg(NetworkWriterType, "Write", transformType) }, { "System.Byte[]", ResolveMethodWithArg(NetworkWriterType, "WriteBytesAndSize", "System.Byte[]") } };