NetworkIdentity.passive

This commit is contained in:
mischa 2023-08-04 11:58:13 +08:00
parent f9ea52257d
commit b2b8adacc2
3 changed files with 11 additions and 2 deletions

View File

@ -32,6 +32,9 @@ public enum Visibility { Default, ForceHidden, ForceShown }
[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

@ -1657,6 +1657,9 @@ static void BroadcastIdentity(
NetworkWriterPooled ownerWriter,
NetworkWriterPooled observersWriter)
{
// skip passive identities for performance
if (identity.passive) return;
// only serialize if it has any observers
// TODO only set dirty if has observers? would be easiest.
if (identity.observers.Count > 0)

View File

@ -26,13 +26,16 @@ public override void OnStartServer()
// color coding
// can't do this in update, it's too expensive
rend.material.color = sleeping ? sleepingColor : activeColor;
// set passive
netIdentity.passive = sleeping;
}
[ServerCallback]
void Update()
{
// set dirty if not sleeping.
// only counts as dirty every 'syncInterval'.
// set dirty every 'syncInterval'.
// passive identities will ignore it.
if (!sleeping) ++value;
}
}