-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!: adding INetworkVisibility
network identity now creates a default visibility class instead of checking null each time. This will simplify some of the checks because Identity.Visibility will never return null BREAKING CHANGE: NetworkIdentity.Visibility can now throw if called before Object is spawned
- Loading branch information
1 parent
279e207
commit e47d4a3
Showing
9 changed files
with
127 additions
and
116 deletions.
There are no files selected for viewing
This file contains 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,49 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Mirage | ||
{ | ||
public interface INetworkVisibility | ||
{ | ||
bool OnCheckObserver(INetworkPlayer player); | ||
void OnRebuildObservers(HashSet<INetworkPlayer> newObservers, bool initialize); | ||
} | ||
|
||
/// <summary> | ||
/// Default visible when no NetworkVisibility is added to the gameobject | ||
/// </summary> | ||
internal class AlwaysVisible : INetworkVisibility | ||
{ | ||
private readonly ServerObjectManager _objectManager; | ||
private readonly NetworkServer _server; | ||
|
||
public AlwaysVisible(ServerObjectManager serverObjectManager) | ||
{ | ||
_objectManager = serverObjectManager; | ||
_server = serverObjectManager.Server; | ||
} | ||
|
||
public bool OnCheckObserver(INetworkPlayer player) => true; | ||
|
||
public void OnRebuildObservers(HashSet<INetworkPlayer> newObservers, bool initialize) | ||
{ | ||
// add all server connections | ||
foreach (var player in _server.Players) | ||
{ | ||
if (!player.SceneIsReady) | ||
continue; | ||
|
||
// todo replace this with a better visibility system (where default checks auth/scene ready) | ||
if (_objectManager.OnlySpawnOnAuthenticated && !player.IsAuthenticated) | ||
continue; | ||
|
||
newObservers.Add(player); | ||
} | ||
|
||
// add local host connection (if any) | ||
if (_server.LocalPlayer != null && _server.LocalPlayer.SceneIsReady) | ||
{ | ||
newObservers.Add(_server.LocalPlayer); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 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 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
Oops, something went wrong.