Skip to content

Commit

Permalink
feat: Adding onLocalPlayerChanged to ClientScene for when localPlayer…
Browse files Browse the repository at this point in the history
… is changed (#1920)

* adding onLocalPlayerChanged event

* Update Assets/Mirror/Runtime/ClientScene.cs

Co-authored-by: MrGadget <chris@clevertech.net>

Co-authored-by: MrGadget <chris@clevertech.net>
  • Loading branch information
James-Frowen and MrGadget committed May 30, 2020
1 parent 3a35b0e commit b4acf7d
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion Assets/Mirror/Runtime/ClientScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,28 @@ public static class ClientScene
static readonly ILogger logger = LogFactory.GetLogger(typeof(ClientScene));

static bool isSpawnFinished;
static NetworkIdentity _localPlayer;

/// <summary>
/// NetworkIdentity of the localPlayer
/// </summary>
public static NetworkIdentity localPlayer { get; private set; }
public static NetworkIdentity localPlayer
{
get => _localPlayer;
private set
{
NetworkIdentity oldPlayer = _localPlayer;
NetworkIdentity newPlayer = value;
if (oldPlayer != newPlayer)
{
_localPlayer = value;
onLocalPlayerChanged?.Invoke(oldPlayer, newPlayer);
}
}
}

public delegate void LocalplayerChanged(NetworkIdentity oldPlayer, NetworkIdentity newPlayer);
public static event LocalplayerChanged onLocalPlayerChanged;

/// <summary>
/// Returns true when a client's connection has been set to ready.
Expand Down

0 comments on commit b4acf7d

Please sign in to comment.