com.unity.netcode.gameobjects@1.2.0
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). Additional documentation and release notes are available at [Multiplayer Documentation](https://docs-multiplayer.unity3d.com). ## [1.2.0] - 2022-11-21 ### Added - Added protected method `NetworkBehaviour.OnSynchronize` which is invoked during the initial `NetworkObject` synchronization process. This provides users the ability to include custom serialization information that will be applied to the `NetworkBehaviour` prior to the `NetworkObject` being spawned. (#2298) - Added support for different versions of the SDK to talk to each other in circumstances where changes permit it. Starting with this version and into future versions, patch versions should be compatible as long as the minor version is the same. (#2290) - Added `NetworkObject` auto-add helper and Multiplayer Tools install reminder settings to Project Settings. (#2285) - Added `public string DisconnectReason` getter to `NetworkManager` and `string Reason` to `ConnectionApprovalResponse`. Allows connection approval to communicate back a reason. Also added `public void DisconnectClient(ulong clientId, string reason)` allowing setting a disconnection reason, when explicitly disconnecting a client. (#2280) ### Changed - Changed 3rd-party `XXHash` (32 & 64) implementation with an in-house reimplementation (#2310) - When `NetworkConfig.EnsureNetworkVariableLengthSafety` is disabled `NetworkVariable` fields do not write the additional `ushort` size value (_which helps to reduce the total synchronization message size_), but when enabled it still writes the additional `ushort` value. (#2298) - Optimized bandwidth usage by encoding most integer fields using variable-length encoding. (#2276) ### Fixed - Fixed issue where `NetworkTransform` components nested under a parent with a `NetworkObject` component (i.e. network prefab) would not have their associated `GameObject`'s transform synchronized. (#2298) - Fixed issue where `NetworkObject`s that failed to instantiate could cause the entire synchronization pipeline to be disrupted/halted for a connecting client. (#2298) - Fixed issue where in-scene placed `NetworkObject`s nested under a `GameObject` would be added to the orphaned children list causing continual console warning log messages. (#2298) - Custom messages are now properly received by the local client when they're sent while running in host mode. (#2296) - Fixed issue where the host would receive more than one event completed notification when loading or unloading a scene only when no clients were connected. (#2292) - Fixed an issue in `UnityTransport` where an error would be logged if the 'Use Encryption' flag was enabled with a Relay configuration that used a secure protocol. (#2289) - Fixed issue where in-scene placed `NetworkObjects` were not honoring the `AutoObjectParentSync` property. (#2281) - Fixed the issue where `NetworkManager.OnClientConnectedCallback` was being invoked before in-scene placed `NetworkObject`s had been spawned when starting `NetworkManager` as a host. (#2277) - Creating a `FastBufferReader` with `Allocator.None` will not result in extra memory being allocated for the buffer (since it's owned externally in that scenario). (#2265) ### Removed - Removed the `NetworkObject` auto-add and Multiplayer Tools install reminder settings from the Menu interface. (#2285)
This commit is contained in:
@@ -102,15 +102,19 @@ namespace Unity.Netcode.Editor.CodeGen
|
||||
private PostProcessorAssemblyResolver m_AssemblyResolver;
|
||||
|
||||
private MethodReference m_MessagingSystem_ReceiveMessage_MethodRef;
|
||||
private MethodReference m_MessagingSystem_CreateMessageAndGetVersion_MethodRef;
|
||||
private TypeReference m_MessagingSystem_MessageWithHandler_TypeRef;
|
||||
private MethodReference m_MessagingSystem_MessageHandler_Constructor_TypeRef;
|
||||
private MethodReference m_MessagingSystem_VersionGetter_Constructor_TypeRef;
|
||||
private FieldReference m_ILPPMessageProvider___network_message_types_FieldRef;
|
||||
private FieldReference m_MessagingSystem_MessageWithHandler_MessageType_FieldRef;
|
||||
private FieldReference m_MessagingSystem_MessageWithHandler_Handler_FieldRef;
|
||||
private FieldReference m_MessagingSystem_MessageWithHandler_GetVersion_FieldRef;
|
||||
private MethodReference m_Type_GetTypeFromHandle_MethodRef;
|
||||
private MethodReference m_List_Add_MethodRef;
|
||||
|
||||
private const string k_ReceiveMessageName = nameof(MessagingSystem.ReceiveMessage);
|
||||
private const string k_CreateMessageAndGetVersionName = nameof(MessagingSystem.CreateMessageAndGetVersion);
|
||||
|
||||
private bool ImportReferences(ModuleDefinition moduleDefinition)
|
||||
{
|
||||
@@ -126,6 +130,7 @@ namespace Unity.Netcode.Editor.CodeGen
|
||||
TypeDefinition listTypeDef = moduleDefinition.ImportReference(typeof(List<>)).Resolve();
|
||||
|
||||
TypeDefinition messageHandlerTypeDef = null;
|
||||
TypeDefinition versionGetterTypeDef = null;
|
||||
TypeDefinition messageWithHandlerTypeDef = null;
|
||||
TypeDefinition ilppMessageProviderTypeDef = null;
|
||||
TypeDefinition messagingSystemTypeDef = null;
|
||||
@@ -137,6 +142,12 @@ namespace Unity.Netcode.Editor.CodeGen
|
||||
continue;
|
||||
}
|
||||
|
||||
if (versionGetterTypeDef == null && netcodeTypeDef.Name == nameof(MessagingSystem.VersionGetter))
|
||||
{
|
||||
versionGetterTypeDef = netcodeTypeDef;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (messageWithHandlerTypeDef == null && netcodeTypeDef.Name == nameof(MessagingSystem.MessageWithHandler))
|
||||
{
|
||||
messageWithHandlerTypeDef = netcodeTypeDef;
|
||||
@@ -157,6 +168,7 @@ namespace Unity.Netcode.Editor.CodeGen
|
||||
}
|
||||
|
||||
m_MessagingSystem_MessageHandler_Constructor_TypeRef = moduleDefinition.ImportReference(messageHandlerTypeDef.GetConstructors().First());
|
||||
m_MessagingSystem_VersionGetter_Constructor_TypeRef = moduleDefinition.ImportReference(versionGetterTypeDef.GetConstructors().First());
|
||||
|
||||
m_MessagingSystem_MessageWithHandler_TypeRef = moduleDefinition.ImportReference(messageWithHandlerTypeDef);
|
||||
foreach (var fieldDef in messageWithHandlerTypeDef.Fields)
|
||||
@@ -169,6 +181,9 @@ namespace Unity.Netcode.Editor.CodeGen
|
||||
case nameof(MessagingSystem.MessageWithHandler.Handler):
|
||||
m_MessagingSystem_MessageWithHandler_Handler_FieldRef = moduleDefinition.ImportReference(fieldDef);
|
||||
break;
|
||||
case nameof(MessagingSystem.MessageWithHandler.GetVersion):
|
||||
m_MessagingSystem_MessageWithHandler_GetVersion_FieldRef = moduleDefinition.ImportReference(fieldDef);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,6 +226,9 @@ namespace Unity.Netcode.Editor.CodeGen
|
||||
case k_ReceiveMessageName:
|
||||
m_MessagingSystem_ReceiveMessage_MethodRef = moduleDefinition.ImportReference(methodDef);
|
||||
break;
|
||||
case k_CreateMessageAndGetVersionName:
|
||||
m_MessagingSystem_CreateMessageAndGetVersion_MethodRef = moduleDefinition.ImportReference(methodDef);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,7 +254,7 @@ namespace Unity.Netcode.Editor.CodeGen
|
||||
return staticCtorMethodDef;
|
||||
}
|
||||
|
||||
private void CreateInstructionsToRegisterType(ILProcessor processor, List<Instruction> instructions, TypeReference type, MethodReference receiveMethod)
|
||||
private void CreateInstructionsToRegisterType(ILProcessor processor, List<Instruction> instructions, TypeReference type, MethodReference receiveMethod, MethodReference versionMethod)
|
||||
{
|
||||
// MessagingSystem.__network_message_types.Add(new MessagingSystem.MessageWithHandler{MessageType=typeof(type), Handler=type.Receive});
|
||||
processor.Body.Variables.Add(new VariableDefinition(m_MessagingSystem_MessageWithHandler_TypeRef));
|
||||
@@ -252,7 +270,7 @@ namespace Unity.Netcode.Editor.CodeGen
|
||||
instructions.Add(processor.Create(OpCodes.Call, m_Type_GetTypeFromHandle_MethodRef));
|
||||
instructions.Add(processor.Create(OpCodes.Stfld, m_MessagingSystem_MessageWithHandler_MessageType_FieldRef));
|
||||
|
||||
// tmp.Handler = type.Receive
|
||||
// tmp.Handler = MessageHandler.ReceveMessage<type>
|
||||
instructions.Add(processor.Create(OpCodes.Ldloca, messageWithHandlerLocIdx));
|
||||
instructions.Add(processor.Create(OpCodes.Ldnull));
|
||||
|
||||
@@ -260,6 +278,15 @@ namespace Unity.Netcode.Editor.CodeGen
|
||||
instructions.Add(processor.Create(OpCodes.Newobj, m_MessagingSystem_MessageHandler_Constructor_TypeRef));
|
||||
instructions.Add(processor.Create(OpCodes.Stfld, m_MessagingSystem_MessageWithHandler_Handler_FieldRef));
|
||||
|
||||
|
||||
// tmp.GetVersion = MessageHandler.CreateMessageAndGetVersion<type>
|
||||
instructions.Add(processor.Create(OpCodes.Ldloca, messageWithHandlerLocIdx));
|
||||
instructions.Add(processor.Create(OpCodes.Ldnull));
|
||||
|
||||
instructions.Add(processor.Create(OpCodes.Ldftn, versionMethod));
|
||||
instructions.Add(processor.Create(OpCodes.Newobj, m_MessagingSystem_VersionGetter_Constructor_TypeRef));
|
||||
instructions.Add(processor.Create(OpCodes.Stfld, m_MessagingSystem_MessageWithHandler_GetVersion_FieldRef));
|
||||
|
||||
// ILPPMessageProvider.__network_message_types.Add(tmp);
|
||||
instructions.Add(processor.Create(OpCodes.Ldloc, messageWithHandlerLocIdx));
|
||||
instructions.Add(processor.Create(OpCodes.Callvirt, m_List_Add_MethodRef));
|
||||
@@ -285,7 +312,9 @@ namespace Unity.Netcode.Editor.CodeGen
|
||||
{
|
||||
var receiveMethod = new GenericInstanceMethod(m_MessagingSystem_ReceiveMessage_MethodRef);
|
||||
receiveMethod.GenericArguments.Add(type);
|
||||
CreateInstructionsToRegisterType(processor, instructions, type, receiveMethod);
|
||||
var versionMethod = new GenericInstanceMethod(m_MessagingSystem_CreateMessageAndGetVersion_MethodRef);
|
||||
versionMethod.GenericArguments.Add(type);
|
||||
CreateInstructionsToRegisterType(processor, instructions, type, receiveMethod, versionMethod);
|
||||
}
|
||||
|
||||
instructions.ForEach(instruction => processor.Body.Instructions.Insert(processor.Body.Instructions.Count - 1, instruction));
|
||||
|
||||
@@ -139,6 +139,19 @@ namespace Unity.Netcode.Editor.CodeGen
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool IsSpecialCaseType(TypeReference type)
|
||||
{
|
||||
foreach (var supportedType in SpecialCaseTypes)
|
||||
{
|
||||
if (type.FullName == supportedType.FullName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void CreateNetworkVariableTypeInitializers(AssemblyDefinition assembly)
|
||||
{
|
||||
foreach (var typeDefinition in assembly.MainModule.Types)
|
||||
@@ -153,6 +166,11 @@ namespace Unity.Netcode.Editor.CodeGen
|
||||
|
||||
foreach (var type in m_WrappedNetworkVariableTypes)
|
||||
{
|
||||
if (IsSpecialCaseType(type))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// If a serializable type isn't found, FallbackSerializer will be used automatically, which will
|
||||
// call into UserNetworkVariableSerialization, giving the user a chance to define their own serializaiton
|
||||
// for types that aren't in our official supported types list.
|
||||
@@ -257,6 +275,20 @@ namespace Unity.Netcode.Editor.CodeGen
|
||||
private MethodReference m_NetworkVariableSerializationTypes_InitializeEqualityChecker_UnmanagedValueEquals_MethodRef;
|
||||
private MethodReference m_NetworkVariableSerializationTypes_InitializeEqualityChecker_ManagedClassEquals_MethodRef;
|
||||
|
||||
private MethodReference m_BytePacker_WriteValueBitPacked_Short_MethodRef;
|
||||
private MethodReference m_BytePacker_WriteValueBitPacked_UShort_MethodRef;
|
||||
private MethodReference m_BytePacker_WriteValueBitPacked_Int_MethodRef;
|
||||
private MethodReference m_BytePacker_WriteValueBitPacked_UInt_MethodRef;
|
||||
private MethodReference m_BytePacker_WriteValueBitPacked_Long_MethodRef;
|
||||
private MethodReference m_BytePacker_WriteValueBitPacked_ULong_MethodRef;
|
||||
|
||||
private MethodReference m_ByteUnpacker_ReadValueBitPacked_Short_MethodRef;
|
||||
private MethodReference m_ByteUnpacker_ReadValueBitPacked_UShort_MethodRef;
|
||||
private MethodReference m_ByteUnpacker_ReadValueBitPacked_Int_MethodRef;
|
||||
private MethodReference m_ByteUnpacker_ReadValueBitPacked_UInt_MethodRef;
|
||||
private MethodReference m_ByteUnpacker_ReadValueBitPacked_Long_MethodRef;
|
||||
private MethodReference m_ByteUnpacker_ReadValueBitPacked_ULong_MethodRef;
|
||||
|
||||
private TypeReference m_FastBufferWriter_TypeRef;
|
||||
private readonly Dictionary<string, MethodReference> m_FastBufferWriter_WriteValue_MethodRefs = new Dictionary<string, MethodReference>();
|
||||
private readonly List<MethodReference> m_FastBufferWriter_ExtensionMethodRefs = new List<MethodReference>();
|
||||
@@ -276,12 +308,13 @@ namespace Unity.Netcode.Editor.CodeGen
|
||||
typeof(decimal),
|
||||
typeof(double),
|
||||
typeof(float),
|
||||
typeof(int),
|
||||
// the following types have special handling
|
||||
/*typeof(int),
|
||||
typeof(uint),
|
||||
typeof(long),
|
||||
typeof(ulong),
|
||||
typeof(short),
|
||||
typeof(ushort),
|
||||
typeof(ushort),*/
|
||||
typeof(Vector2),
|
||||
typeof(Vector3),
|
||||
typeof(Vector2Int),
|
||||
@@ -293,6 +326,16 @@ namespace Unity.Netcode.Editor.CodeGen
|
||||
typeof(Ray),
|
||||
typeof(Ray2D)
|
||||
};
|
||||
internal static readonly Type[] SpecialCaseTypes = new[]
|
||||
{
|
||||
// the following types have special handling
|
||||
typeof(int),
|
||||
typeof(uint),
|
||||
typeof(long),
|
||||
typeof(ulong),
|
||||
typeof(short),
|
||||
typeof(ushort),
|
||||
};
|
||||
|
||||
private const string k_Debug_LogError = nameof(Debug.LogError);
|
||||
private const string k_NetworkManager_LocalClientId = nameof(NetworkManager.LocalClientId);
|
||||
@@ -343,6 +386,8 @@ namespace Unity.Netcode.Editor.CodeGen
|
||||
TypeDefinition fastBufferWriterTypeDef = null;
|
||||
TypeDefinition fastBufferReaderTypeDef = null;
|
||||
TypeDefinition networkVariableSerializationTypesTypeDef = null;
|
||||
TypeDefinition bytePackerTypeDef = null;
|
||||
TypeDefinition byteUnpackerTypeDef = null;
|
||||
foreach (var netcodeTypeDef in m_NetcodeModule.GetAllTypes())
|
||||
{
|
||||
if (networkManagerTypeDef == null && netcodeTypeDef.Name == nameof(NetworkManager))
|
||||
@@ -398,6 +443,18 @@ namespace Unity.Netcode.Editor.CodeGen
|
||||
networkVariableSerializationTypesTypeDef = netcodeTypeDef;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (bytePackerTypeDef == null && netcodeTypeDef.Name == nameof(BytePacker))
|
||||
{
|
||||
bytePackerTypeDef = netcodeTypeDef;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (byteUnpackerTypeDef == null && netcodeTypeDef.Name == nameof(ByteUnpacker))
|
||||
{
|
||||
byteUnpackerTypeDef = netcodeTypeDef;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var methodDef in debugTypeDef.Methods)
|
||||
@@ -652,6 +709,82 @@ namespace Unity.Netcode.Editor.CodeGen
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var method in bytePackerTypeDef.Methods)
|
||||
{
|
||||
if (!method.IsStatic)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (method.Name)
|
||||
{
|
||||
case nameof(BytePacker.WriteValueBitPacked):
|
||||
if (method.Parameters[1].ParameterType.FullName == typeof(short).FullName)
|
||||
{
|
||||
m_BytePacker_WriteValueBitPacked_Short_MethodRef = m_MainModule.ImportReference(method);
|
||||
}
|
||||
else if (method.Parameters[1].ParameterType.FullName == typeof(ushort).FullName)
|
||||
{
|
||||
m_BytePacker_WriteValueBitPacked_UShort_MethodRef = m_MainModule.ImportReference(method);
|
||||
}
|
||||
else if (method.Parameters[1].ParameterType.FullName == typeof(int).FullName)
|
||||
{
|
||||
m_BytePacker_WriteValueBitPacked_Int_MethodRef = m_MainModule.ImportReference(method);
|
||||
}
|
||||
else if (method.Parameters[1].ParameterType.FullName == typeof(uint).FullName)
|
||||
{
|
||||
m_BytePacker_WriteValueBitPacked_UInt_MethodRef = m_MainModule.ImportReference(method);
|
||||
}
|
||||
else if (method.Parameters[1].ParameterType.FullName == typeof(long).FullName)
|
||||
{
|
||||
m_BytePacker_WriteValueBitPacked_Long_MethodRef = m_MainModule.ImportReference(method);
|
||||
}
|
||||
else if (method.Parameters[1].ParameterType.FullName == typeof(ulong).FullName)
|
||||
{
|
||||
m_BytePacker_WriteValueBitPacked_ULong_MethodRef = m_MainModule.ImportReference(method);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var method in byteUnpackerTypeDef.Methods)
|
||||
{
|
||||
if (!method.IsStatic)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (method.Name)
|
||||
{
|
||||
case nameof(ByteUnpacker.ReadValueBitPacked):
|
||||
if (method.Parameters[1].ParameterType.FullName == typeof(short).MakeByRefType().FullName)
|
||||
{
|
||||
m_ByteUnpacker_ReadValueBitPacked_Short_MethodRef = m_MainModule.ImportReference(method);
|
||||
}
|
||||
else if (method.Parameters[1].ParameterType.FullName == typeof(ushort).MakeByRefType().FullName)
|
||||
{
|
||||
m_ByteUnpacker_ReadValueBitPacked_UShort_MethodRef = m_MainModule.ImportReference(method);
|
||||
}
|
||||
else if (method.Parameters[1].ParameterType.FullName == typeof(int).MakeByRefType().FullName)
|
||||
{
|
||||
m_ByteUnpacker_ReadValueBitPacked_Int_MethodRef = m_MainModule.ImportReference(method);
|
||||
}
|
||||
else if (method.Parameters[1].ParameterType.FullName == typeof(uint).MakeByRefType().FullName)
|
||||
{
|
||||
m_ByteUnpacker_ReadValueBitPacked_UInt_MethodRef = m_MainModule.ImportReference(method);
|
||||
}
|
||||
else if (method.Parameters[1].ParameterType.FullName == typeof(long).MakeByRefType().FullName)
|
||||
{
|
||||
m_ByteUnpacker_ReadValueBitPacked_Long_MethodRef = m_MainModule.ImportReference(method);
|
||||
}
|
||||
else if (method.Parameters[1].ParameterType.FullName == typeof(ulong).MakeByRefType().FullName)
|
||||
{
|
||||
m_ByteUnpacker_ReadValueBitPacked_ULong_MethodRef = m_MainModule.ImportReference(method);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1008,6 +1141,36 @@ namespace Unity.Netcode.Editor.CodeGen
|
||||
|
||||
private bool GetWriteMethodForParameter(TypeReference paramType, out MethodReference methodRef)
|
||||
{
|
||||
if (paramType.FullName == typeof(short).FullName)
|
||||
{
|
||||
methodRef = m_BytePacker_WriteValueBitPacked_Short_MethodRef;
|
||||
return true;
|
||||
}
|
||||
if (paramType.FullName == typeof(ushort).FullName)
|
||||
{
|
||||
methodRef = m_BytePacker_WriteValueBitPacked_UShort_MethodRef;
|
||||
return true;
|
||||
}
|
||||
if (paramType.FullName == typeof(int).FullName)
|
||||
{
|
||||
methodRef = m_BytePacker_WriteValueBitPacked_Int_MethodRef;
|
||||
return true;
|
||||
}
|
||||
if (paramType.FullName == typeof(uint).FullName)
|
||||
{
|
||||
methodRef = m_BytePacker_WriteValueBitPacked_UInt_MethodRef;
|
||||
return true;
|
||||
}
|
||||
if (paramType.FullName == typeof(long).FullName)
|
||||
{
|
||||
methodRef = m_BytePacker_WriteValueBitPacked_Long_MethodRef;
|
||||
return true;
|
||||
}
|
||||
if (paramType.FullName == typeof(ulong).FullName)
|
||||
{
|
||||
methodRef = m_BytePacker_WriteValueBitPacked_ULong_MethodRef;
|
||||
return true;
|
||||
}
|
||||
var assemblyQualifiedName = paramType.FullName + ", " + paramType.Resolve().Module.Assembly.FullName;
|
||||
var foundMethodRef = m_FastBufferWriter_WriteValue_MethodRefs.TryGetValue(assemblyQualifiedName, out methodRef);
|
||||
|
||||
@@ -1154,6 +1317,36 @@ namespace Unity.Netcode.Editor.CodeGen
|
||||
|
||||
private bool GetReadMethodForParameter(TypeReference paramType, out MethodReference methodRef)
|
||||
{
|
||||
if (paramType.FullName == typeof(short).FullName)
|
||||
{
|
||||
methodRef = m_ByteUnpacker_ReadValueBitPacked_Short_MethodRef;
|
||||
return true;
|
||||
}
|
||||
if (paramType.FullName == typeof(ushort).FullName)
|
||||
{
|
||||
methodRef = m_ByteUnpacker_ReadValueBitPacked_UShort_MethodRef;
|
||||
return true;
|
||||
}
|
||||
if (paramType.FullName == typeof(int).FullName)
|
||||
{
|
||||
methodRef = m_ByteUnpacker_ReadValueBitPacked_Int_MethodRef;
|
||||
return true;
|
||||
}
|
||||
if (paramType.FullName == typeof(uint).FullName)
|
||||
{
|
||||
methodRef = m_ByteUnpacker_ReadValueBitPacked_UInt_MethodRef;
|
||||
return true;
|
||||
}
|
||||
if (paramType.FullName == typeof(long).FullName)
|
||||
{
|
||||
methodRef = m_ByteUnpacker_ReadValueBitPacked_Long_MethodRef;
|
||||
return true;
|
||||
}
|
||||
if (paramType.FullName == typeof(ulong).FullName)
|
||||
{
|
||||
methodRef = m_ByteUnpacker_ReadValueBitPacked_ULong_MethodRef;
|
||||
return true;
|
||||
}
|
||||
var assemblyQualifiedName = paramType.FullName + ", " + paramType.Resolve().Module.Assembly.FullName;
|
||||
|
||||
var foundMethodRef = m_FastBufferReader_ReadValue_MethodRefs.TryGetValue(assemblyQualifiedName, out methodRef);
|
||||
|
||||
8
Editor/Configuration.meta
Normal file
8
Editor/Configuration.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52153943c346dd04e8712ab540ab9c22
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
39
Editor/Configuration/NetcodeForGameObjectsSettings.cs
Normal file
39
Editor/Configuration/NetcodeForGameObjectsSettings.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using UnityEditor;
|
||||
|
||||
|
||||
namespace Unity.Netcode.Editor.Configuration
|
||||
{
|
||||
internal class NetcodeForGameObjectsSettings
|
||||
{
|
||||
internal const string AutoAddNetworkObjectIfNoneExists = "AutoAdd-NetworkObject-When-None-Exist";
|
||||
internal const string InstallMultiplayerToolsTipDismissedPlayerPrefKey = "Netcode_Tip_InstallMPTools_Dismissed";
|
||||
|
||||
internal static int GetNetcodeInstallMultiplayerToolTips()
|
||||
{
|
||||
if (EditorPrefs.HasKey(InstallMultiplayerToolsTipDismissedPlayerPrefKey))
|
||||
{
|
||||
return EditorPrefs.GetInt(InstallMultiplayerToolsTipDismissedPlayerPrefKey);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
internal static void SetNetcodeInstallMultiplayerToolTips(int toolTipPrefSetting)
|
||||
{
|
||||
EditorPrefs.SetInt(InstallMultiplayerToolsTipDismissedPlayerPrefKey, toolTipPrefSetting);
|
||||
}
|
||||
|
||||
internal static bool GetAutoAddNetworkObjectSetting()
|
||||
{
|
||||
if (EditorPrefs.HasKey(AutoAddNetworkObjectIfNoneExists))
|
||||
{
|
||||
return EditorPrefs.GetBool(AutoAddNetworkObjectIfNoneExists);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
internal static void SetAutoAddNetworkObjectSetting(bool autoAddSetting)
|
||||
{
|
||||
EditorPrefs.SetBool(AutoAddNetworkObjectIfNoneExists, autoAddSetting);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/Configuration/NetcodeForGameObjectsSettings.cs.meta
Normal file
11
Editor/Configuration/NetcodeForGameObjectsSettings.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2f9c9b10bc41a0e46ab71324dd0ac6e1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
94
Editor/Configuration/NetcodeSettingsProvider.cs
Normal file
94
Editor/Configuration/NetcodeSettingsProvider.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.Netcode.Editor.Configuration
|
||||
{
|
||||
internal static class NetcodeSettingsProvider
|
||||
{
|
||||
[SettingsProvider]
|
||||
public static SettingsProvider CreateNetcodeSettingsProvider()
|
||||
{
|
||||
// First parameter is the path in the Settings window.
|
||||
// Second parameter is the scope of this setting: it only appears in the Settings window for the Project scope.
|
||||
var provider = new SettingsProvider("Project/NetcodeForGameObjects", SettingsScope.Project)
|
||||
{
|
||||
label = "Netcode for GameObjects",
|
||||
keywords = new[] { "netcode", "editor" },
|
||||
guiHandler = OnGuiHandler,
|
||||
};
|
||||
|
||||
return provider;
|
||||
}
|
||||
|
||||
internal static NetcodeSettingsLabel NetworkObjectsSectionLabel = new NetcodeSettingsLabel("NetworkObject Helper Settings", 20);
|
||||
internal static NetcodeSettingsToggle AutoAddNetworkObjectToggle = new NetcodeSettingsToggle("Auto-Add NetworkObjects", "When enabled, NetworkObjects are automatically added to GameObjects when NetworkBehaviours are added first.", 20);
|
||||
internal static NetcodeSettingsLabel MultiplayerToolsLabel = new NetcodeSettingsLabel("Multiplayer Tools", 20);
|
||||
internal static NetcodeSettingsToggle MultiplayerToolTipStatusToggle = new NetcodeSettingsToggle("Multiplayer Tools Install Reminder", "When enabled, the NetworkManager will display " +
|
||||
"the notification to install the multiplayer tools package.", 20);
|
||||
|
||||
private static void OnGuiHandler(string obj)
|
||||
{
|
||||
var autoAddNetworkObjectSetting = NetcodeForGameObjectsSettings.GetAutoAddNetworkObjectSetting();
|
||||
var multiplayerToolsTipStatus = NetcodeForGameObjectsSettings.GetNetcodeInstallMultiplayerToolTips() == 0;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
NetworkObjectsSectionLabel.DrawLabel();
|
||||
autoAddNetworkObjectSetting = AutoAddNetworkObjectToggle.DrawToggle(autoAddNetworkObjectSetting);
|
||||
MultiplayerToolsLabel.DrawLabel();
|
||||
multiplayerToolsTipStatus = MultiplayerToolTipStatusToggle.DrawToggle(multiplayerToolsTipStatus);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
NetcodeForGameObjectsSettings.SetAutoAddNetworkObjectSetting(autoAddNetworkObjectSetting);
|
||||
NetcodeForGameObjectsSettings.SetNetcodeInstallMultiplayerToolTips(multiplayerToolsTipStatus ? 0 : 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class NetcodeSettingsLabel : NetcodeGUISettings
|
||||
{
|
||||
private string m_LabelContent;
|
||||
|
||||
public void DrawLabel()
|
||||
{
|
||||
EditorGUIUtility.labelWidth = m_LabelSize;
|
||||
GUILayout.Label(m_LabelContent, EditorStyles.boldLabel, m_LayoutWidth);
|
||||
}
|
||||
|
||||
public NetcodeSettingsLabel(string labelText, float layoutOffset = 0.0f)
|
||||
{
|
||||
m_LabelContent = labelText;
|
||||
AdjustLableSize(labelText, layoutOffset);
|
||||
}
|
||||
}
|
||||
|
||||
internal class NetcodeSettingsToggle : NetcodeGUISettings
|
||||
{
|
||||
private GUIContent m_ToggleContent;
|
||||
|
||||
public bool DrawToggle(bool currentSetting)
|
||||
{
|
||||
EditorGUIUtility.labelWidth = m_LabelSize;
|
||||
return EditorGUILayout.Toggle(m_ToggleContent, currentSetting, m_LayoutWidth);
|
||||
}
|
||||
|
||||
public NetcodeSettingsToggle(string labelText, string toolTip, float layoutOffset)
|
||||
{
|
||||
AdjustLableSize(labelText, layoutOffset);
|
||||
m_ToggleContent = new GUIContent(labelText, toolTip);
|
||||
}
|
||||
}
|
||||
|
||||
internal class NetcodeGUISettings
|
||||
{
|
||||
private const float k_MaxLabelWidth = 450f;
|
||||
protected float m_LabelSize { get; private set; }
|
||||
|
||||
protected GUILayoutOption m_LayoutWidth { get; private set; }
|
||||
|
||||
protected void AdjustLableSize(string labelText, float offset = 0.0f)
|
||||
{
|
||||
m_LabelSize = Mathf.Min(k_MaxLabelWidth, EditorStyles.label.CalcSize(new GUIContent(labelText)).x);
|
||||
m_LayoutWidth = GUILayout.Width(m_LabelSize + offset);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
11
Editor/Configuration/NetcodeSettingsProvider.cs.meta
Normal file
11
Editor/Configuration/NetcodeSettingsProvider.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6b373a89fcbd41444a97ebd1798b326f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -3,9 +3,13 @@ using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Unity.Netcode.Editor.Configuration;
|
||||
|
||||
namespace Unity.Netcode.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="CustomEditor"/> for <see cref="NetworkBehaviour"/>
|
||||
/// </summary>
|
||||
[CustomEditor(typeof(NetworkBehaviour), true)]
|
||||
[CanEditMultipleObjects]
|
||||
public class NetworkBehaviourEditor : UnityEditor.Editor
|
||||
@@ -33,8 +37,8 @@ namespace Unity.Netcode.Editor
|
||||
var ft = fields[i].FieldType;
|
||||
if (ft.IsGenericType && ft.GetGenericTypeDefinition() == typeof(NetworkVariable<>) && !fields[i].IsDefined(typeof(HideInInspector), true))
|
||||
{
|
||||
m_NetworkVariableNames.Add(fields[i].Name);
|
||||
m_NetworkVariableFields.Add(fields[i].Name, fields[i]);
|
||||
m_NetworkVariableNames.Add(ObjectNames.NicifyVariableName(fields[i].Name));
|
||||
m_NetworkVariableFields.Add(ObjectNames.NicifyVariableName(fields[i].Name), fields[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -230,8 +234,6 @@ namespace Unity.Netcode.Editor
|
||||
CheckForNetworkObject((target as NetworkBehaviour).gameObject);
|
||||
}
|
||||
|
||||
internal const string AutoAddNetworkObjectIfNoneExists = "AutoAdd-NetworkObject-When-None-Exist";
|
||||
|
||||
/// <summary>
|
||||
/// Recursively finds the root parent of a <see cref="Transform"/>
|
||||
/// </summary>
|
||||
@@ -308,7 +310,7 @@ namespace Unity.Netcode.Editor
|
||||
// and the user has already turned "Auto-Add NetworkObject" on when first notified about the requirement
|
||||
// then just send a reminder to the user why the NetworkObject they just deleted seemingly "re-appeared"
|
||||
// again.
|
||||
if (networkObjectRemoved && EditorPrefs.HasKey(AutoAddNetworkObjectIfNoneExists) && EditorPrefs.GetBool(AutoAddNetworkObjectIfNoneExists))
|
||||
if (networkObjectRemoved && NetcodeForGameObjectsSettings.GetAutoAddNetworkObjectSetting())
|
||||
{
|
||||
Debug.LogWarning($"{gameObject.name} still has {nameof(NetworkBehaviour)}s and Auto-Add NetworkObjects is enabled. A NetworkObject is being added back to {gameObject.name}.");
|
||||
Debug.Log($"To reset Auto-Add NetworkObjects: Select the Netcode->General->Reset Auto-Add NetworkObject menu item.");
|
||||
@@ -317,7 +319,7 @@ namespace Unity.Netcode.Editor
|
||||
// Notify and provide the option to add it one time, always add a NetworkObject, or do nothing and let the user manually add it
|
||||
if (EditorUtility.DisplayDialog($"{nameof(NetworkBehaviour)}s require a {nameof(NetworkObject)}",
|
||||
$"{gameObject.name} does not have a {nameof(NetworkObject)} component. Would you like to add one now?", "Yes", "No (manually add it)",
|
||||
DialogOptOutDecisionType.ForThisMachine, AutoAddNetworkObjectIfNoneExists))
|
||||
DialogOptOutDecisionType.ForThisMachine, NetcodeForGameObjectsSettings.AutoAddNetworkObjectIfNoneExists))
|
||||
{
|
||||
gameObject.AddComponent<NetworkObject>();
|
||||
var activeScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();
|
||||
@@ -327,20 +329,5 @@ namespace Unity.Netcode.Editor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This allows users to reset the Auto-Add NetworkObject preference
|
||||
/// so the next time they add a NetworkBehaviour to a GameObject without
|
||||
/// a NetworkObject it will display the dialog box again and not
|
||||
/// automatically add a NetworkObject.
|
||||
/// </summary>
|
||||
[MenuItem("Netcode/General/Reset Auto-Add NetworkObject", false, 1)]
|
||||
private static void ResetMultiplayerToolsTipStatus()
|
||||
{
|
||||
if (EditorPrefs.HasKey(AutoAddNetworkObjectIfNoneExists))
|
||||
{
|
||||
EditorPrefs.SetBool(AutoAddNetworkObjectIfNoneExists, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEditorInternal;
|
||||
using Unity.Netcode.Editor.Configuration;
|
||||
|
||||
namespace Unity.Netcode.Editor
|
||||
{
|
||||
@@ -14,7 +15,6 @@ namespace Unity.Netcode.Editor
|
||||
[CanEditMultipleObjects]
|
||||
public class NetworkManagerEditor : UnityEditor.Editor
|
||||
{
|
||||
internal const string InstallMultiplayerToolsTipDismissedPlayerPrefKey = "Netcode_Tip_InstallMPTools_Dismissed";
|
||||
private static GUIStyle s_CenteredWordWrappedLabelStyle;
|
||||
private static GUIStyle s_HelpBoxStyle;
|
||||
|
||||
@@ -359,7 +359,7 @@ namespace Unity.Netcode.Editor
|
||||
const string targetUrl = "https://docs-multiplayer.unity3d.com/netcode/current/tools/install-tools";
|
||||
const string infoIconName = "console.infoicon";
|
||||
|
||||
if (PlayerPrefs.GetInt(InstallMultiplayerToolsTipDismissedPlayerPrefKey, 0) != 0)
|
||||
if (NetcodeForGameObjectsSettings.GetNetcodeInstallMultiplayerToolTips() != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -405,7 +405,7 @@ namespace Unity.Netcode.Editor
|
||||
GUILayout.FlexibleSpace();
|
||||
if (GUILayout.Button(dismissButtonText, dismissButtonStyle, GUILayout.ExpandWidth(false)))
|
||||
{
|
||||
PlayerPrefs.SetInt(InstallMultiplayerToolsTipDismissedPlayerPrefKey, 1);
|
||||
NetcodeForGameObjectsSettings.SetNetcodeInstallMultiplayerToolTips(1);
|
||||
}
|
||||
EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
@@ -65,7 +65,11 @@ namespace Unity.Netcode.Editor
|
||||
var scenesList = EditorBuildSettings.scenes.ToList();
|
||||
var activeScene = SceneManager.GetActiveScene();
|
||||
var isSceneInBuildSettings = scenesList.Count((c) => c.path == activeScene.path) == 1;
|
||||
#if UNITY_2023_1_OR_NEWER
|
||||
var networkManager = Object.FindFirstObjectByType<NetworkManager>();
|
||||
#else
|
||||
var networkManager = Object.FindObjectOfType<NetworkManager>();
|
||||
#endif
|
||||
if (!isSceneInBuildSettings && networkManager != null)
|
||||
{
|
||||
if (networkManager.NetworkConfig != null && networkManager.NetworkConfig.EnableSceneManagement)
|
||||
|
||||
Reference in New Issue
Block a user