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:
Unity Technologies
2022-01-26 00:00:00 +00:00
parent 36d07fad5e
commit 4818405514
17 changed files with 403 additions and 39 deletions

View File

@@ -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)
{

View File

@@ -272,18 +272,22 @@ namespace Unity.Netcode
{
reader.ReadValueSafe(out int index);
reader.ReadValueSafe(out T value);
if (index < m_List.Length)
if (index >= m_List.Length)
{
m_List[index] = value;
throw new Exception("Shouldn't be here, index is higher than list length");
}
var previousValue = m_List[index];
m_List[index] = value;
if (OnListChanged != null)
{
OnListChanged(new NetworkListEvent<T>
{
Type = eventType,
Index = index,
Value = value
Value = value,
PreviousValue = previousValue
});
}
@@ -293,7 +297,8 @@ namespace Unity.Netcode
{
Type = eventType,
Index = index,
Value = value
Value = value,
PreviousValue = previousValue
});
}
}
@@ -368,7 +373,7 @@ namespace Unity.Netcode
public bool Contains(T item)
{
int index = NativeArrayExtensions.IndexOf(m_List, item);
return index == -1;
return index != -1;
}
/// <inheritdoc />
@@ -528,6 +533,11 @@ namespace Unity.Netcode
/// </summary>
public T Value;
/// <summary>
/// The previous value when "Value" has changed, if available.
/// </summary>
public T PreviousValue;
/// <summary>
/// the index changed, added or removed if available
/// </summary>

View File

@@ -565,20 +565,8 @@ namespace Unity.Netcode
GenerateScenesInBuild();
// If NetworkManager has this set to true, then we can get the DDOL (DontDestroyOnLoad) from its GaemObject
if (networkManager.DontDestroy)
{
DontDestroyOnLoadScene = networkManager.gameObject.scene;
}
else
{
// Otherwise, we have to create a GameObject and move it into the DDOL in order to
// register the DDOL scene handle with NetworkSceneManager
var myDDOLObject = new GameObject("DDOL-NWSM");
UnityEngine.Object.DontDestroyOnLoad(myDDOLObject);
DontDestroyOnLoadScene = myDDOLObject.scene;
UnityEngine.Object.Destroy(myDDOLObject);
}
// Since NetworkManager is now always migrated to the DDOL we will use this to get the DDOL scene
DontDestroyOnLoadScene = networkManager.gameObject.scene;
ServerSceneHandleToClientSceneHandle.Add(DontDestroyOnLoadScene.handle, DontDestroyOnLoadScene.handle);
ScenesLoaded.Add(DontDestroyOnLoadScene.handle, DontDestroyOnLoadScene);

View File

@@ -114,6 +114,11 @@ namespace Unity.Netcode
{
double d = m_TimeSec / m_TickInterval;
m_CachedTick = (int)d;
// This check is needed due to double division imprecision of large numbers
if ((d - m_CachedTick) >= 0.999999999999)
{
m_CachedTick++;
}
m_CachedTickOffset = ((d - Math.Truncate(d)) * m_TickInterval);
// This handles negative time, decreases tick by 1 and makes offset positive.