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.3.1] - 2023-03-27 ### Added - Added detection and graceful handling of corrupt packets for additional safety. (#2419) ### Changed - The UTP component UI has been updated to be more user-friendly for new users by adding a simple toggle to switch between local-only (127.0.0.1) and remote (0.0.0.0) binding modes, using the toggle "Allow Remote Connections" (#2408) - Updated `UnityTransport` dependency on `com.unity.transport` to 1.3.3. (#2450) - `NetworkShow()` of `NetworkObject`s are delayed until the end of the frame to ensure consistency of delta-driven variables like `NetworkList`. - Dirty `NetworkObject` are reset at end-of-frame and not at serialization time. - `NetworkHide()` of an object that was just `NetworkShow()`n produces a warning, as remote clients will _not_ get a spawn/despawn pair. - Renamed the NetworkTransform.SetState parameter `shouldGhostsInterpolate` to `teleportDisabled` for better clarity of what that parameter does. (#2228) - Network prefabs are now stored in a ScriptableObject that can be shared between NetworkManagers, and have been exposed for public access. By default, a Default Prefabs List is created that contains all NetworkObject prefabs in the project, and new NetworkManagers will default to using that unless that option is turned off in the Netcode for GameObjects settings. Existing NetworkManagers will maintain their existing lists, which can be migrated to the new format via a button in their inspector. (#2322) ### Fixed - Fixed issue where changes to a layer's weight would not synchronize unless a state transition was occurring.(#2399) - Fixed issue where `NetworkManager.LocalClientId` was returning the `NetworkTransport.ServerClientId` as opposed to the `NetworkManager.m_LocalClientId`. (#2398) - Fixed issue where a dynamically spawned `NetworkObject` parented under an in-scene placed `NetworkObject` would have its `InScenePlaced` value changed to `true`. This would result in a soft synchronization error for late joining clients. (#2396) - Fixed a UTP test that was failing when you install Unity Transport package 2.0.0 or newer. (#2347) - Fixed issue where `NetcodeSettingsProvider` would throw an exception in Unity 2020.3.x versions. (#2345) - Fixed server side issue where, depending upon component ordering, some NetworkBehaviour components might not have their OnNetworkDespawn method invoked if the client side disconnected. (#2323) - Fixed a case where data corruption could occur when using UnityTransport when reaching a certain level of send throughput. (#2332) - Fixed an issue in `UnityTransport` where an exception would be thrown if starting a Relay host/server on WebGL. This exception should only be thrown if using direct connections (where WebGL can't act as a host/server). (#2321) - Fixed `NetworkAnimator` issue where it was not checking for `AnimatorStateTtansition.destinationStateMachine` and any possible sub-states defined within it. (#2309) - Fixed `NetworkAnimator` issue where the host client was receiving the ClientRpc animation updates when the host was the owner.(#2309) - Fixed `NetworkAnimator` issue with using pooled objects and when specific properties are cleaned during despawn and destroy.(#2309) - Fixed issue where `NetworkAnimator` was checking for animation changes when the associated `NetworkObject` was not spawned.(#2309) - Corrected an issue with the documentation for BufferSerializer (#2401)
222 lines
8.6 KiB
C#
222 lines
8.6 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace Unity.Netcode
|
|
{
|
|
/// <summary>
|
|
/// The method of NetworkPrefab override used to identify the source prefab
|
|
/// </summary>
|
|
public enum NetworkPrefabOverride
|
|
{
|
|
/// <summary>
|
|
/// No oeverride is present
|
|
/// </summary>
|
|
None,
|
|
/// <summary>
|
|
/// Override the prefab when the given SourcePrefabToOverride is requested
|
|
/// </summary>
|
|
Prefab,
|
|
/// <summary>
|
|
/// Override the prefab when the given SourceHashToOverride is requested
|
|
/// Used in situations where the server assets do not exist in client builds
|
|
/// </summary>
|
|
Hash
|
|
}
|
|
|
|
/// <summary>
|
|
/// Class that represents a NetworkPrefab
|
|
/// </summary>
|
|
[Serializable]
|
|
public class NetworkPrefab
|
|
{
|
|
/// <summary>
|
|
/// The override settings for this NetworkPrefab
|
|
/// </summary>
|
|
public NetworkPrefabOverride Override;
|
|
|
|
/// <summary>
|
|
/// Asset reference of the network prefab
|
|
/// </summary>
|
|
public GameObject Prefab;
|
|
|
|
/// <summary>
|
|
/// Used when prefab is selected for the source prefab to override value (i.e. direct reference, the prefab is within the same project)
|
|
/// We keep a separate value as the user might want to have something different than the default Prefab for the SourcePrefabToOverride
|
|
/// </summary>
|
|
public GameObject SourcePrefabToOverride;
|
|
|
|
/// <summary>
|
|
/// Used when hash is selected for the source prefab to override value (i.e. a direct reference is not possible such as in a multi-project pattern)
|
|
/// </summary>
|
|
public uint SourceHashToOverride;
|
|
|
|
/// <summary>
|
|
/// The prefab to replace (override) the source prefab with
|
|
/// </summary>
|
|
public GameObject OverridingTargetPrefab;
|
|
|
|
public bool Equals(NetworkPrefab other)
|
|
{
|
|
return Override == other.Override &&
|
|
Prefab == other.Prefab &&
|
|
SourcePrefabToOverride == other.SourcePrefabToOverride &&
|
|
SourceHashToOverride == other.SourceHashToOverride &&
|
|
OverridingTargetPrefab == other.OverridingTargetPrefab;
|
|
}
|
|
|
|
public uint SourcePrefabGlobalObjectIdHash
|
|
{
|
|
get
|
|
{
|
|
switch (Override)
|
|
{
|
|
case NetworkPrefabOverride.None:
|
|
if (Prefab != null && Prefab.TryGetComponent(out NetworkObject no))
|
|
{
|
|
return no.GlobalObjectIdHash;
|
|
}
|
|
|
|
throw new InvalidOperationException("Prefab field isn't set or isn't a Network Object");
|
|
case NetworkPrefabOverride.Prefab:
|
|
if (SourcePrefabToOverride != null && SourcePrefabToOverride.TryGetComponent(out no))
|
|
{
|
|
return no.GlobalObjectIdHash;
|
|
}
|
|
|
|
throw new InvalidOperationException("Source Prefab field isn't set or isn't a Network Object");
|
|
case NetworkPrefabOverride.Hash:
|
|
return SourceHashToOverride;
|
|
default:
|
|
throw new ArgumentOutOfRangeException();
|
|
}
|
|
}
|
|
}
|
|
|
|
public uint TargetPrefabGlobalObjectIdHash
|
|
{
|
|
get
|
|
{
|
|
switch (Override)
|
|
{
|
|
case NetworkPrefabOverride.None:
|
|
return 0;
|
|
case NetworkPrefabOverride.Prefab:
|
|
case NetworkPrefabOverride.Hash:
|
|
if (OverridingTargetPrefab != null && OverridingTargetPrefab.TryGetComponent(out NetworkObject no))
|
|
{
|
|
return no.GlobalObjectIdHash;
|
|
}
|
|
|
|
throw new InvalidOperationException("Target Prefab field isn't set or isn't a Network Object");
|
|
default:
|
|
throw new ArgumentOutOfRangeException();
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool Validate(int index = -1)
|
|
{
|
|
NetworkObject networkObject;
|
|
if (Override == NetworkPrefabOverride.None)
|
|
{
|
|
if (Prefab == null)
|
|
{
|
|
NetworkLog.LogWarning($"{nameof(NetworkPrefab)} cannot be null ({nameof(NetworkPrefab)} at index: {index})");
|
|
return false;
|
|
}
|
|
|
|
networkObject = Prefab.GetComponent<NetworkObject>();
|
|
if (networkObject == null)
|
|
{
|
|
if (NetworkLog.CurrentLogLevel <= LogLevel.Error)
|
|
{
|
|
NetworkLog.LogWarning($"{NetworkManager.PrefabDebugHelper(this)} is missing " +
|
|
$"a {nameof(NetworkObject)} component (entry will be ignored).");
|
|
}
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// Validate source prefab override values first
|
|
switch (Override)
|
|
{
|
|
case NetworkPrefabOverride.Hash:
|
|
{
|
|
if (SourceHashToOverride == 0)
|
|
{
|
|
if (NetworkLog.CurrentLogLevel <= LogLevel.Error)
|
|
{
|
|
NetworkLog.LogWarning($"{nameof(NetworkPrefab)} {nameof(SourceHashToOverride)} is zero " +
|
|
"(entry will be ignored).");
|
|
}
|
|
return false;
|
|
}
|
|
|
|
break;
|
|
}
|
|
case NetworkPrefabOverride.Prefab:
|
|
{
|
|
if (SourcePrefabToOverride == null)
|
|
{
|
|
// This is a leftover side-effect from NetworkManager's OnValidate. It's a usability
|
|
// adjustment to automatically set the "Prefab" field as the source prefab when a user
|
|
// swaps from the default Inspector to the override one.
|
|
if (Prefab != null)
|
|
{
|
|
SourcePrefabToOverride = Prefab;
|
|
}
|
|
else if (NetworkLog.CurrentLogLevel <= LogLevel.Error)
|
|
{
|
|
NetworkLog.LogWarning($"{nameof(NetworkPrefab)} {nameof(SourcePrefabToOverride)} is null (entry will be ignored).");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (!SourcePrefabToOverride.TryGetComponent(out networkObject))
|
|
{
|
|
if (NetworkLog.CurrentLogLevel <= LogLevel.Error)
|
|
{
|
|
NetworkLog.LogWarning($"{nameof(NetworkPrefab)} ({SourcePrefabToOverride.name}) " +
|
|
$"is missing a {nameof(NetworkObject)} component (entry will be ignored).");
|
|
}
|
|
return false;
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Validate target prefab override values next
|
|
if (OverridingTargetPrefab == null)
|
|
{
|
|
if (NetworkLog.CurrentLogLevel <= LogLevel.Error)
|
|
{
|
|
NetworkLog.LogWarning($"{nameof(NetworkPrefab)} {nameof(OverridingTargetPrefab)} is null!");
|
|
}
|
|
switch (Override)
|
|
{
|
|
case NetworkPrefabOverride.Hash:
|
|
{
|
|
Debug.LogWarning($"{nameof(NetworkPrefab)} override entry {SourceHashToOverride} will be removed and ignored.");
|
|
break;
|
|
}
|
|
case NetworkPrefabOverride.Prefab:
|
|
{
|
|
Debug.LogWarning($"{nameof(NetworkPrefab)} override entry ({SourcePrefabToOverride.name}) will be removed and ignored.");
|
|
break;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"{{SourceHash: {SourceHashToOverride}, TargetHash: {TargetPrefabGlobalObjectIdHash}}}";
|
|
}
|
|
}
|
|
}
|