-
-
Notifications
You must be signed in to change notification settings - Fork 844
feat: InterestManagementBase #3379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| // interest management component for custom solutions like | ||
| // distance based, spatial hashing, raycast based, etc. | ||
| // low level base class allows for low level spatial hashing etc., which is 3-5x faster. | ||
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
|
|
||
| namespace Mirror | ||
| { | ||
| [DisallowMultipleComponent] | ||
| [HelpURL("https://mirror-networking.gitbook.io/docs/guides/interest-management")] | ||
| public abstract class InterestManagementBase : MonoBehaviour | ||
| { | ||
| // Awake configures InterestManagementBase in NetworkServer/Client | ||
| // Do NOT check for active server or client here. | ||
| // Awake must always set the static aoi references. | ||
| // make sure to call base.Awake when overwriting! | ||
| protected virtual void Awake() | ||
| { | ||
| if (NetworkServer.aoi == null) | ||
| { | ||
| NetworkServer.aoi = this; | ||
| } | ||
| else Debug.LogError($"Only one InterestManagement component allowed. {NetworkServer.aoi.GetType()} has been set up already."); | ||
|
|
||
| if (NetworkClient.aoi == null) | ||
| { | ||
| NetworkClient.aoi = this; | ||
| } | ||
| else Debug.LogError($"Only one InterestManagement component allowed. {NetworkClient.aoi.GetType()} has been set up already."); | ||
| } | ||
|
|
||
| [ServerCallback] | ||
| public virtual void Reset() {} | ||
|
|
||
| // Callback used by the visibility system to determine if an observer | ||
| // (player) can see the NetworkIdentity. If this function returns true, | ||
| // the network connection will be added as an observer. | ||
| // conn: Network connection of a player. | ||
| // returns True if the player can see this object. | ||
| public abstract bool OnCheckObserver(NetworkIdentity identity, NetworkConnectionToClient newObserver); | ||
|
|
||
|
|
||
| // Callback used by the visibility system for objects on a host. | ||
| // Objects on a host (with a local client) cannot be disabled or | ||
| // destroyed when they are not visible to the local client. So this | ||
| // function is called to allow custom code to hide these objects. A | ||
| // typical implementation will disable renderer components on the | ||
| // object. This is only called on local clients on a host. | ||
| // => need the function in here and virtual so people can overwrite! | ||
| // => not everyone wants to hide renderers! | ||
| [ServerCallback] | ||
| public virtual void SetHostVisibility(NetworkIdentity identity, bool visible) | ||
| { | ||
| foreach (Renderer rend in identity.GetComponentsInChildren<Renderer>()) | ||
| rend.enabled = visible; | ||
| } | ||
|
|
||
| /// <summary>Called on the server when a new networked object is spawned.</summary> | ||
| // (useful for 'only rebuild if changed' interest management algorithms) | ||
| [ServerCallback] | ||
| public virtual void OnSpawned(NetworkIdentity identity) {} | ||
|
|
||
| /// <summary>Called on the server when a networked object is destroyed.</summary> | ||
| // (useful for 'only rebuild if changed' interest management algorithms) | ||
| [ServerCallback] | ||
| public virtual void OnDestroyed(NetworkIdentity identity) {} | ||
|
|
||
| public abstract void Rebuild(NetworkIdentity identity, bool initialize); | ||
|
|
||
| /// <summary>Adds the specified connection to the observers of identity</summary> | ||
| protected void AddObserver(NetworkConnectionToClient connection, NetworkIdentity identity) | ||
| { | ||
| connection.AddToObserving(identity); | ||
| identity.observers.Add(connection.connectionId, connection); | ||
| } | ||
|
|
||
| /// <summary>Removes the specified connection from the observers of identity</summary> | ||
| protected void RemoveObserver(NetworkConnectionToClient connection, NetworkIdentity identity) | ||
| { | ||
| connection.RemoveFromObserving(identity, false); | ||
| identity.observers.Remove(connection.connectionId); | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.