diff --git a/Assets/Mirror/Core/Messages.cs b/Assets/Mirror/Core/Messages.cs index 62888c07e6..15cadde894 100644 --- a/Assets/Mirror/Core/Messages.cs +++ b/Assets/Mirror/Core/Messages.cs @@ -52,13 +52,14 @@ public struct RpcMessage : NetworkMessage public ArraySegment payload; } + [Flags] public enum AuthorityFlags : byte { None, isOwner, isLocalPlayer } + public struct SpawnMessage : NetworkMessage { // netId of new or existing object public uint netId; - public bool isLocalPlayer; - // Sets hasAuthority on the spawned object - public bool isOwner; + // isOwner and isLocalPlayer are merged into one byte via bitwise op + public AuthorityFlags authorityFlags; public ulong sceneId; // If sceneId != 0 then it is used instead of assetId public uint assetId; @@ -71,13 +72,53 @@ public struct SpawnMessage : NetworkMessage // serialized component data // ArraySegment to avoid unnecessary allocations public ArraySegment payload; + + // Backwards compatibility after implementing authorityFlags + public bool isOwner + { + get => authorityFlags.HasFlag(AuthorityFlags.isOwner); + set => authorityFlags = + value + ? authorityFlags | AuthorityFlags.isOwner + : authorityFlags & ~AuthorityFlags.isOwner; + } + + // Backwards compatibility after implementing authorityFlags + public bool isLocalPlayer + { + get => authorityFlags.HasFlag(AuthorityFlags.isLocalPlayer); + set => authorityFlags = + value + ? authorityFlags | AuthorityFlags.isLocalPlayer + : authorityFlags & ~AuthorityFlags.isLocalPlayer; + } } public struct ChangeOwnerMessage : NetworkMessage { public uint netId; - public bool isOwner; - public bool isLocalPlayer; + // isOwner and isLocalPlayer are merged into one byte via bitwise op + public AuthorityFlags authorityFlags; + + // Backwards compatibility after implementing authorityFlags + public bool isOwner + { + get => authorityFlags.HasFlag(AuthorityFlags.isOwner); + set => authorityFlags = + value + ? authorityFlags | AuthorityFlags.isOwner + : authorityFlags & ~AuthorityFlags.isOwner; + } + + // Backwards compatibility after implementing authorityFlags + public bool isLocalPlayer + { + get => authorityFlags.HasFlag(AuthorityFlags.isLocalPlayer); + set => authorityFlags = + value + ? authorityFlags | AuthorityFlags.isLocalPlayer + : authorityFlags & ~AuthorityFlags.isLocalPlayer; + } } public struct ObjectSpawnStartedMessage : NetworkMessage {}