NetworkIdentity.passive

This commit is contained in:
mischa 2023-08-04 12:33:34 +08:00
parent 9d0e90f484
commit 49228d59e9
3 changed files with 7 additions and 0 deletions

View File

@ -40,6 +40,9 @@ public struct NetworkIdentitySerialization
[HelpURL("https://mirror-networking.gitbook.io/docs/components/network-identity")]
public sealed class NetworkIdentity : MonoBehaviour
{
[Tooltip("Performance optimization for passive objects like Npcs, ItemDrops, Trees, Structures etc. skip broadcasting.\nPassive objects only spawn and despawn, their state isn't synced.\nThis can make a huge performance difference for large worlds with lots of passive objects.")]
public bool passive = false;
/// <summary>Returns true if running as a client and this object was spawned by a server.</summary>
//
// IMPORTANT:

View File

@ -1667,6 +1667,8 @@ static void BroadcastToConnection(NetworkConnectionToClient connection)
// NetworkServer.Destroy)
if (identity != null)
{
if (identity.passive) continue;
// get serialization for this entity viewed by this connection
// (if anything was serialized this time)
NetworkWriter serialization = SerializeForConnection(identity, connection);

View File

@ -26,6 +26,8 @@ public override void OnStartServer()
// color coding
// can't do this in update, it's too expensive
rend.material.color = sleeping ? sleepingColor : activeColor;
netIdentity.passive = sleeping;
}
[ServerCallback]