Skip to content

Commit

Permalink
feat: adding more public methods for NetworkPlayer VisList
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed Aug 17, 2022
1 parent 2e1263e commit ccc7ef5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Assets/Mirage/Runtime/INetworkPlayer.cs
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Mirage.SocketLayer;

namespace Mirage
Expand Down Expand Up @@ -39,9 +40,37 @@ public interface IMessageReceiver
/// </summary>
public interface IVisibilityTracker
{
/// <summary>
/// Called when sending spawn message to client
/// </summary>
/// <param name="identity"></param>
void AddToVisList(NetworkIdentity identity);

/// <summary>
/// Called when sending destroy message to client
/// </summary>
/// <param name="identity"></param>
void RemoveFromVisList(NetworkIdentity identity);

/// <summary>
/// Removes all <see cref="NetworkIdentity"/> that this player can see
/// <para>This is called when loading a new scene</para>
/// </summary>
void RemoveAllVisibleObjects();

/// <summary>
/// Checks if player can see <see cref="NetworkIdentity"/>
/// </summary>
/// <param name="identity"></param>
/// <returns></returns>
bool ContainsInVisList(NetworkIdentity identity);

/// <summary>
/// HashSet of all <see cref="NetworkIdentity"/> that this player can see
/// <para>Only valid on server</para>
/// <para>Reverse collection for <see cref="NetworkIdentity.observers"/></para>
/// </summary>
IReadOnlyCollection<NetworkIdentity> VisList { get; }
}

/// <summary>
Expand Down
17 changes: 17 additions & 0 deletions Assets/Mirage/Runtime/NetworkPlayer.cs
Expand Up @@ -76,6 +76,13 @@ public sealed class NetworkPlayer : INetworkPlayer, IMessageSender

public IConnection Connection => _connection;

/// <summary>
/// List of all networkIdentity that this player can see
/// <para>Only valid on server</para>
/// </summary>
public IReadOnlyCollection<NetworkIdentity> VisList => _visList;


/// <summary>
/// Disconnects the player.
/// <para>A disconnected player can not send messages</para>
Expand Down Expand Up @@ -215,6 +222,16 @@ public void RemoveFromVisList(NetworkIdentity identity)
_visList.Remove(identity);
}

/// <summary>
/// Checks if player can see NetworkIdentity
/// </summary>
/// <param name="identity"></param>
/// <returns></returns>
public bool ContainsInVisList(NetworkIdentity identity)
{
return _visList.Contains(identity);
}

/// <summary>
/// Removes all objects that this player can see
/// <para>This is called when loading a new scene</para>
Expand Down

0 comments on commit ccc7ef5

Please sign in to comment.