Skip to content

Commit

Permalink
refactor: move LocalPlayer to ClientObjectManager (#619)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: removed NetworkClient.LocalPlayer,  use ClientObjectManager.LocalPlayer instead
  • Loading branch information
uweeby committed Feb 22, 2021
1 parent e0dd626 commit df1e379
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
7 changes: 6 additions & 1 deletion Assets/Mirage/Runtime/ClientObjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public class ClientObjectManager : MonoBehaviour, IClientObjectManager, IObjectL
[SerializeField] SpawnEvent _unSpawned = new SpawnEvent();
public SpawnEvent UnSpawned => _unSpawned;

/// <summary>
/// NetworkIdentity of the localPlayer
/// </summary>
public NetworkIdentity LocalPlayer => Client.Connection?.Identity;

[Header("Prefabs")]
/// <summary>
/// List of prefabs that will be registered with the spawning system.
Expand Down Expand Up @@ -578,7 +583,7 @@ internal void OnRpcMessage(RpcMessage msg)

void CheckForLocalPlayer(NetworkIdentity identity)
{
if (identity && identity == Client.LocalPlayer)
if (identity && identity == LocalPlayer)
{
// Set isLocalPlayer to true on this NetworkIdentity and trigger OnStartLocalPlayer in all scripts on the same GO
identity.ConnectionToServer = Client.Connection;
Expand Down
5 changes: 5 additions & 0 deletions Assets/Mirage/Runtime/IClientObjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public interface IClientObjectManager
/// </summary>
SpawnEvent UnSpawned { get; }

/// <summary>
/// NetworkIdentity of the localPlayer
/// </summary>
NetworkIdentity LocalPlayer { get; }

NetworkIdentity GetPrefab(Guid assetId);

void RegisterPrefab(NetworkIdentity identity);
Expand Down
5 changes: 0 additions & 5 deletions Assets/Mirage/Runtime/INetworkClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ public interface INetworkClient
/// </summary>
INetworkConnection Connection { get; }

/// <summary>
/// NetworkIdentity of the localPlayer
/// </summary>
NetworkIdentity LocalPlayer { get; }

/// <summary>
/// active is true while a client is connecting/connected
/// (= while the network is active)
Expand Down
5 changes: 0 additions & 5 deletions Assets/Mirage/Runtime/NetworkClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ public class NetworkClient : MonoBehaviour, INetworkClient
/// </summary>
public INetworkConnection Connection { get; internal set; }

/// <summary>
/// NetworkIdentity of the localPlayer
/// </summary>
public NetworkIdentity LocalPlayer => Connection?.Identity;

internal ConnectState connectState = ConnectState.Disconnected;

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirage/Runtime/NetworkIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public sealed class NetworkIdentity : MonoBehaviour
/// This returns true if this object is the one that represents the player on the local machine.
/// <para>This is set when the server has spawned an object for this particular client.</para>
/// </summary>
public bool IsLocalPlayer => Client != null && Client.LocalPlayer == this;
public bool IsLocalPlayer => ClientObjectManager != null && ClientObjectManager.LocalPlayer == this;

/// <summary>
/// This returns true if this object is the authoritative player object on the client.
Expand Down
4 changes: 2 additions & 2 deletions Assets/Mirage/Samples~/Tanks/Scripts/TankGameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ int GetAlivePlayerCount()
void FindLocalTank()
{
//Check to see if the player is loaded in yet
if (NetworkManager.Client.LocalPlayer == null)
if (NetworkManager.ClientObjectManager.LocalPlayer == null)
return;

LocalPlayer = NetworkManager.Client.LocalPlayer.GetComponent<Tank>();
LocalPlayer = NetworkManager.ClientObjectManager.LocalPlayer.GetComponent<Tank>();
}

void UpdateStats()
Expand Down

0 comments on commit df1e379

Please sign in to comment.