mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
NetworkIdentity.passive
This commit is contained in:
parent
f9ea52257d
commit
b2b8adacc2
@ -32,6 +32,9 @@ public enum Visibility { Default, ForceHidden, ForceShown }
|
|||||||
[HelpURL("https://mirror-networking.gitbook.io/docs/components/network-identity")]
|
[HelpURL("https://mirror-networking.gitbook.io/docs/components/network-identity")]
|
||||||
public sealed class NetworkIdentity : MonoBehaviour
|
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>
|
/// <summary>Returns true if running as a client and this object was spawned by a server.</summary>
|
||||||
//
|
//
|
||||||
// IMPORTANT:
|
// IMPORTANT:
|
||||||
|
@ -1657,6 +1657,9 @@ static void BroadcastIdentity(
|
|||||||
NetworkWriterPooled ownerWriter,
|
NetworkWriterPooled ownerWriter,
|
||||||
NetworkWriterPooled observersWriter)
|
NetworkWriterPooled observersWriter)
|
||||||
{
|
{
|
||||||
|
// skip passive identities for performance
|
||||||
|
if (identity.passive) return;
|
||||||
|
|
||||||
// only serialize if it has any observers
|
// only serialize if it has any observers
|
||||||
// TODO only set dirty if has observers? would be easiest.
|
// TODO only set dirty if has observers? would be easiest.
|
||||||
if (identity.observers.Count > 0)
|
if (identity.observers.Count > 0)
|
||||||
|
@ -26,13 +26,16 @@ public override void OnStartServer()
|
|||||||
// color coding
|
// color coding
|
||||||
// can't do this in update, it's too expensive
|
// can't do this in update, it's too expensive
|
||||||
rend.material.color = sleeping ? sleepingColor : activeColor;
|
rend.material.color = sleeping ? sleepingColor : activeColor;
|
||||||
|
|
||||||
|
// set passive
|
||||||
|
netIdentity.passive = sleeping;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ServerCallback]
|
[ServerCallback]
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
// set dirty if not sleeping.
|
// set dirty every 'syncInterval'.
|
||||||
// only counts as dirty every 'syncInterval'.
|
// passive identities will ignore it.
|
||||||
if (!sleeping) ++value;
|
if (!sleeping) ++value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user