123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- using System.Collections.Generic;
- using UnityEngine;
- namespace Mirror
- {
- [DisallowMultipleComponent]
- [HelpURL("https://mirror-networking.gitbook.io/docs/guides/interest-management")]
- public abstract class InterestManagement : InterestManagementBase
- {
-
- readonly HashSet<NetworkConnectionToClient> newObservers =
- new HashSet<NetworkConnectionToClient>();
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public abstract void OnRebuildObservers(NetworkIdentity identity, HashSet<NetworkConnectionToClient> newObservers);
-
-
-
-
-
-
- [ServerCallback]
- protected void RebuildAll()
- {
- foreach (NetworkIdentity identity in NetworkServer.spawned.Values)
- {
- NetworkServer.RebuildObservers(identity, false);
- }
- }
- public override void Rebuild(NetworkIdentity identity, bool initialize)
- {
-
- newObservers.Clear();
-
- if (identity.visible != Visibility.ForceHidden)
- {
- OnRebuildObservers(identity, newObservers);
- }
-
-
-
-
-
-
-
- if (identity.connectionToClient != null)
- {
- newObservers.Add(identity.connectionToClient);
- }
- bool changed = false;
-
- foreach (NetworkConnectionToClient conn in newObservers)
- {
-
-
- if (conn != null && conn.isReady)
- {
- if (initialize || !identity.observers.ContainsKey(conn.connectionId))
- {
-
- conn.AddToObserving(identity);
-
- changed = true;
- }
- }
- }
-
- foreach (NetworkConnectionToClient conn in identity.observers.Values)
- {
- if (!newObservers.Contains(conn))
- {
-
- conn.RemoveFromObserving(identity, false);
-
- changed = true;
- }
- }
-
- if (changed)
- {
- identity.observers.Clear();
- foreach (NetworkConnectionToClient conn in newObservers)
- {
- if (conn != null && conn.isReady)
- identity.observers.Add(conn.connectionId, conn);
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if (initialize)
- {
- if (!newObservers.Contains(NetworkServer.localConnection))
- {
- SetHostVisibility(identity, false);
- }
- }
- }
- }
- }
|