mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
use uint, no need for a special NetworkSceneId (#62)
This commit is contained in:
parent
5449c94f21
commit
2d208bcae0
@ -7,7 +7,8 @@ public static class ClientScene
|
||||
{
|
||||
static NetworkIdentity s_LocalPlayer;
|
||||
static NetworkConnection s_ReadyConnection;
|
||||
static Dictionary<NetworkSceneId, NetworkIdentity> s_SpawnableObjects;
|
||||
// scene id to NetworkIdentity
|
||||
static Dictionary<uint, NetworkIdentity> 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<NetworkInstanceId, NetworkIdentity> objects { get { return s_NetworkScene.localObjects; } }
|
||||
public static Dictionary<NetworkHash128, GameObject> prefabs { get { return NetworkScene.guidToPrefab; } }
|
||||
public static Dictionary<NetworkSceneId, NetworkIdentity> spawnableObjects { get { return s_SpawnableObjects; } }
|
||||
// scene id to NetworkIdentity
|
||||
public static Dictionary<uint, NetworkIdentity> 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<NetworkSceneId, NetworkIdentity>();
|
||||
s_SpawnableObjects = new Dictionary<uint, NetworkIdentity>();
|
||||
var uvs = Resources.FindObjectsOfTypeAll<NetworkIdentity>();
|
||||
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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -73,7 +73,6 @@
|
||||
<Compile Include="NetworkInstanceId.cs" />
|
||||
<Compile Include="NetworkProximityChecker.cs" />
|
||||
<Compile Include="NetworkScene.cs" />
|
||||
<Compile Include="NetworkSceneId.cs" />
|
||||
<Compile Include="NetworkStartPosition.cs" />
|
||||
<Compile Include="NetworkTranformChild.cs" />
|
||||
<Compile Include="NetworkTransform.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
|
||||
|
@ -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());
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -1,54 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror
|
||||
{
|
||||
[Serializable]
|
||||
public struct NetworkSceneId : IEquatable<NetworkSceneId>
|
||||
{
|
||||
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; } }
|
||||
}
|
||||
}
|
@ -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()
|
||||
|
@ -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);
|
||||
|
@ -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[]") }
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user