-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Pierce Thompson <[email protected]>
- Loading branch information
1 parent
a3415f7
commit 28fdbac
Showing
4 changed files
with
70 additions
and
3 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 |
---|---|---|
@@ -1,13 +1,16 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
Project("{99d6f2a9-1021-4ea5-acb3-48cbd6fb8d09}") = "Multiplayer", "Multiplayer/Multiplayer.csproj", "{f712c7fb-eeae-4036-a938-356e022b0455}" | ||
Project("{99D6F2A9-1021-4EA5-ACB3-48CBD6FB8D09}") = "Multiplayer", "Multiplayer/Multiplayer.csproj", "{F712C7FB-EEAE-4036-A938-356E022B0455}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Release|Any CPU = Release|Any CPU | ||
Debug|Any CPU = Debug|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{f712c7fb-eeae-4036-a938-356e022b0455}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{f712c7fb-eeae-4036-a938-356e022b0455}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{F712C7FB-EEAE-4036-A938-356E022B0455}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{F712C7FB-EEAE-4036-A938-356E022B0455}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{F712C7FB-EEAE-4036-A938-356E022B0455}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{F712C7FB-EEAE-4036-A938-356E022B0455}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System.Collections.Generic; | ||
using Multiplayer.Components.Networking.Player; | ||
using UnityEngine; | ||
|
||
namespace Multiplayer.Components.Networking; | ||
|
||
public class PlayerListGUI : MonoBehaviour | ||
{ | ||
private bool showPlayerList; | ||
|
||
public void RegisterListeners() | ||
{ | ||
ScreenspaceMouse.Instance.ValueChanged += OnToggle; | ||
} | ||
|
||
private void OnToggle(bool status) | ||
{ | ||
showPlayerList = status; | ||
} | ||
|
||
private void OnGUI() | ||
{ | ||
if (!showPlayerList) | ||
return; | ||
|
||
GUILayout.Window(157031520, new Rect(Screen.width / 2.0f - 125, 25, 250, 0), DrawPlayerList, "Online Players"); | ||
} | ||
|
||
private static void DrawPlayerList(int windowId) | ||
{ | ||
foreach (string player in GetPlayerList()) | ||
GUILayout.Label(player); | ||
} | ||
|
||
// todo: cache this? | ||
private static IEnumerable<string> GetPlayerList() | ||
{ | ||
if (!NetworkLifecycle.Instance.IsClientRunning) | ||
return new[] { "Not in game" }; | ||
|
||
IReadOnlyCollection<NetworkedPlayer> players = NetworkLifecycle.Instance.Client.PlayerManager.Players; | ||
string[] playerList = new string[players.Count + 1]; | ||
int i = 0; | ||
foreach (NetworkedPlayer player in players) | ||
{ | ||
playerList[i] = $"{player.Username} ({player.GetPing().ToString()}ms)"; | ||
i++; | ||
} | ||
|
||
// The Player of the Client is not in the PlayerManager, so we need to add it separately | ||
playerList[playerList.Length - 1] = $"{Multiplayer.Settings.Username} ({NetworkLifecycle.Instance.Client.Ping.ToString()}ms)"; | ||
return playerList; | ||
} | ||
} |