From 3815ec6576d6c117d84cdcf77e3c9b3efd6755ae Mon Sep 17 00:00:00 2001 From: mischa Date: Thu, 6 Jun 2024 15:28:05 +0200 Subject: [PATCH] obsolete support instead of modifying original --- Assets/Mirror/Core/NetworkBehaviour.cs | 4 +- Assets/Mirror/Core/NetworkIdentity.cs | 2 +- Assets/Mirror/Core/NetworkMessage.cs | 5 +- Assets/Mirror/Core/NetworkProfiler2020.cs | 58 +++++++++++++++++++ .../Mirror/Core/NetworkProfiler2020.cs.meta | 3 + Assets/Mirror/Profiler/NetworkProfiler.cs | 2 +- 6 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 Assets/Mirror/Core/NetworkProfiler2020.cs create mode 100644 Assets/Mirror/Core/NetworkProfiler2020.cs.meta diff --git a/Assets/Mirror/Core/NetworkBehaviour.cs b/Assets/Mirror/Core/NetworkBehaviour.cs index 52ca522f3..329c6d45d 100644 --- a/Assets/Mirror/Core/NetworkBehaviour.cs +++ b/Assets/Mirror/Core/NetworkBehaviour.cs @@ -22,7 +22,7 @@ public enum SyncDirection { ServerToClient, ClientToServer } // [RequireComponent(typeof(NetworkIdentity))] disabled to allow child NetworkBehaviours [AddComponentMenu("")] [HelpURL("https://mirror-networking.gitbook.io/docs/guides/networkbehaviour")] - public abstract class NetworkBehaviour : MonoBehaviour + public abstract partial class NetworkBehaviour : MonoBehaviour { /// Sync direction for OnSerialize. ServerToClient by default. ClientToServer for client authority. [Tooltip("Server Authority calls OnSerialize on the server and syncs it to clients.\n\nClient Authority calls OnSerialize on the owning client, syncs it to server, which then broadcasts it to all other clients.\n\nUse server authority for cheat safety.")] @@ -1070,7 +1070,7 @@ protected T GetSyncVarNetworkBehaviour(NetworkBehaviourSyncVar syncNetBehavio { return null; } - + // ensure componentIndex is in range. // show explicit errors if something went wrong, instead of IndexOutOfRangeException. // removing components at runtime isn't allowed, yet this happened in a project so we need to check for it. diff --git a/Assets/Mirror/Core/NetworkIdentity.cs b/Assets/Mirror/Core/NetworkIdentity.cs index aed8251f6..41aa51260 100644 --- a/Assets/Mirror/Core/NetworkIdentity.cs +++ b/Assets/Mirror/Core/NetworkIdentity.cs @@ -38,7 +38,7 @@ public struct NetworkIdentitySerialization [DefaultExecutionOrder(-1)] [AddComponentMenu("Network/Network Identity")] [HelpURL("https://mirror-networking.gitbook.io/docs/components/network-identity")] - public sealed class NetworkIdentity : MonoBehaviour + public sealed partial class NetworkIdentity : MonoBehaviour { /// Returns true if running as a client and this object was spawned by a server. // diff --git a/Assets/Mirror/Core/NetworkMessage.cs b/Assets/Mirror/Core/NetworkMessage.cs index 7fc387ad4..fbea34633 100644 --- a/Assets/Mirror/Core/NetworkMessage.cs +++ b/Assets/Mirror/Core/NetworkMessage.cs @@ -1,4 +1,7 @@ +using System; + namespace Mirror { - public interface NetworkMessage {} + // OLD NETWORK PROFILER SUPPORT: inherit from old IMessageBase. Later don't inherit from anything. + public interface NetworkMessage : IMessageBase {} } diff --git a/Assets/Mirror/Core/NetworkProfiler2020.cs b/Assets/Mirror/Core/NetworkProfiler2020.cs new file mode 100644 index 000000000..2fc02f0df --- /dev/null +++ b/Assets/Mirror/Core/NetworkProfiler2020.cs @@ -0,0 +1,58 @@ +// [Obsolete] path for our old Network Profiler because the new one doesn't work with Unity 2020. +// we can't change NetworkProfiler, but we can restore the old API with [Obsolete] paths. +using System; +using System.Collections.Generic; +using Mirror.RemoteCalls; + +namespace Mirror +{ + static class NetworkProfiler2020 + { + public const string ObsoleteMessage = "Obsolete API is only kept for old Network Profiler and Unity 2020 support."; + } + + // OBSOLETE PATH FOR OLD NETWORK PROFILER IN UNITY 2020 + [Obsolete(NetworkProfiler2020.ObsoleteMessage)] + public interface IMessageBase{} + + [Obsolete(NetworkProfiler2020.ObsoleteMessage)] + public struct SyncEventMessage : NetworkMessage + { + public ushort functionHash; + public uint netId; + } + + [Obsolete(NetworkProfiler2020.ObsoleteMessage)] + public struct UpdateVarsMessage : NetworkMessage + { + public uint netId; + } + + [Obsolete(NetworkProfiler2020.ObsoleteMessage)] + public abstract partial class NetworkBehaviour + { + public static RemoteCallDelegate GetRpcHandler(int functionHash) => + RemoteProcedureCalls.GetDelegate((ushort)functionHash); + } + + [Obsolete(NetworkProfiler2020.ObsoleteMessage)] + public sealed partial class NetworkIdentity + { + public static Dictionary spawned + { + get + { + // server / host mode: use the one from server. + // host mode has access to all spawned. + if (NetworkServer.active) + return NetworkServer.spawned; + + // client + if (NetworkClient.active) + return NetworkClient.spawned; + + return null; + } + } + } +} diff --git a/Assets/Mirror/Core/NetworkProfiler2020.cs.meta b/Assets/Mirror/Core/NetworkProfiler2020.cs.meta new file mode 100644 index 000000000..7f224e5d1 --- /dev/null +++ b/Assets/Mirror/Core/NetworkProfiler2020.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a5684027f2ad43b9863abe03e630bc71 +timeCreated: 1717679756 \ No newline at end of file diff --git a/Assets/Mirror/Profiler/NetworkProfiler.cs b/Assets/Mirror/Profiler/NetworkProfiler.cs index dd79a2e5d..55d63a91b 100644 --- a/Assets/Mirror/Profiler/NetworkProfiler.cs +++ b/Assets/Mirror/Profiler/NetworkProfiler.cs @@ -210,7 +210,7 @@ private GameObject GetSceneObject(ulong sceneId) } } - private GameObject GetPrefab(Guid assetId) + private GameObject GetPrefab(uint assetId) { var networkManager = NetworkManager.singleton;