com.unity.netcode.gameobjects@1.0.0-pre.5
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.0.0-pre.5] - 2022-01-26 ### Added - Added `PreviousValue` in `NetworkListEvent`, when `Value` has changed (#1528) ### Changed - NetworkManager's GameObject is no longer allowed to be nested under one or more GameObject(s).(#1484) - NetworkManager DontDestroy property was removed and now NetworkManager always is migrated into the DontDestroyOnLoad scene. (#1484) ### Fixed - Fixed network tick value sometimes being duplicated or skipped. (#1614) - Fixed The ClientNetworkTransform sample script to allow for owner changes at runtime. (#1606)
This commit is contained in:
@@ -197,11 +197,6 @@ namespace Unity.Netcode
|
||||
|
||||
public NetworkTime ServerTime => NetworkTickSystem?.ServerTime ?? default;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets if the NetworkManager should be marked as DontDestroyOnLoad
|
||||
/// </summary>
|
||||
[HideInInspector] public bool DontDestroy = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets if the application should be set to run in background
|
||||
/// </summary>
|
||||
@@ -490,6 +485,13 @@ namespace Unity.Netcode
|
||||
|
||||
private void Initialize(bool server)
|
||||
{
|
||||
// Don't allow the user to start a network session if the NetworkManager is
|
||||
// still parented under another GameObject
|
||||
if (NetworkManagerCheckForParent(true))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (NetworkLog.CurrentLogLevel <= LogLevel.Developer)
|
||||
{
|
||||
NetworkLog.LogInfo(nameof(Initialize));
|
||||
@@ -941,11 +943,6 @@ namespace Unity.Netcode
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (DontDestroy)
|
||||
{
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
|
||||
if (RunInBackground)
|
||||
{
|
||||
Application.runInBackground = true;
|
||||
@@ -955,6 +952,11 @@ namespace Unity.Netcode
|
||||
{
|
||||
SetSingleton();
|
||||
}
|
||||
|
||||
if (!NetworkManagerCheckForParent())
|
||||
{
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
@@ -962,6 +964,48 @@ namespace Unity.Netcode
|
||||
UnityEngine.SceneManagement.SceneManager.sceneUnloaded += OnSceneUnloaded;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle runtime detection for parenting the NetworkManager's GameObject under another GameObject
|
||||
/// </summary>
|
||||
private void OnTransformParentChanged()
|
||||
{
|
||||
NetworkManagerCheckForParent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines if the NetworkManager's GameObject is parented under another GameObject and
|
||||
/// notifies the user that this is not allowed for the NetworkManager.
|
||||
/// </summary>
|
||||
internal bool NetworkManagerCheckForParent(bool ignoreNetworkManagerCache = false)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
var isParented = NetworkManagerHelper.NotifyUserOfNestedNetworkManager(this, ignoreNetworkManagerCache);
|
||||
#else
|
||||
var isParented = transform.root != transform;
|
||||
if (isParented)
|
||||
{
|
||||
throw new Exception(GenerateNestedNetworkManagerMessage(transform));
|
||||
}
|
||||
#endif
|
||||
return isParented;
|
||||
}
|
||||
|
||||
static internal string GenerateNestedNetworkManagerMessage(Transform transform)
|
||||
{
|
||||
return $"{transform.name} is nested under {transform.root.name}. NetworkManager cannot be nested.\n";
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
static internal INetworkManagerHelper NetworkManagerHelper;
|
||||
/// <summary>
|
||||
/// Interface for NetworkManagerHelper
|
||||
/// </summary>
|
||||
internal interface INetworkManagerHelper
|
||||
{
|
||||
bool NotifyUserOfNestedNetworkManager(NetworkManager networkManager, bool ignoreNetworkManagerCache = false, bool editorTest = false);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Ensures that the NetworkManager is cleaned up before OnDestroy is run on NetworkObjects and NetworkBehaviours when unloading a scene with a NetworkManager
|
||||
private void OnSceneUnloaded(Scene scene)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user