Skip to content

Commit

Permalink
feat: adding event to NetworkPlayer when Identity is changed
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Frowen committed Mar 31, 2022
1 parent de874ab commit 9e22ff4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions Assets/Mirage/Runtime/INetworkPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public interface IVisibilityTracker
/// </summary>
public interface IObjectOwner
{
event Action<NetworkIdentity> OnIdentityChanged;
NetworkIdentity Identity { get; set; }
bool HasCharacter { get; }
void RemoveOwnedObject(NetworkIdentity networkIdentity);
Expand Down
23 changes: 22 additions & 1 deletion Assets/Mirage/Runtime/NetworkPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public sealed class NetworkPlayer : INetworkPlayer, IMessageSender
/// </summary>
bool isDisconnected = false;

/// <summary>
/// Backing field for <see cref="Identity"/>
/// </summary>
private NetworkIdentity _identity;

/// <summary>
/// Marks if this player has been accepted by a <see cref="NetworkAuthenticator"/>
/// </summary>
Expand Down Expand Up @@ -93,10 +98,26 @@ public void MarkAsDisconnected()
isDisconnected = true;
}

/// <summary>
/// Event called when <see cref="Identity"/> property is changed
/// </summary>
public event Action<NetworkIdentity> OnIdentityChanged;

/// <summary>
/// The NetworkIdentity for this connection.
/// </summary>
public NetworkIdentity Identity { get; set; }
public NetworkIdentity Identity
{
get => _identity;
set
{
if (_identity == value)
return;

_identity = value;
OnIdentityChanged?.Invoke(_identity);
}
}

/// <summary>
/// A list of the NetworkIdentity objects owned by this connection. This list is read-only.
Expand Down

0 comments on commit 9e22ff4

Please sign in to comment.