mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2025-02-16 21:08:28 +00:00
Working on player stats
This commit is contained in:
parent
b987948bf9
commit
5ca4ce46df
3 changed files with 55 additions and 2 deletions
|
@ -0,0 +1,50 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
using SanAndreasUnity.Net;
|
||||
|
||||
namespace SanAndreasUnity.Stats
|
||||
{
|
||||
public class PlayerStats : MonoBehaviour
|
||||
{
|
||||
float[] m_widths = new float[]{0.25f, 0.1f, 0.1f, 0.25f, 0.15f, 0.1f};
|
||||
string[] m_columnNames = new string[]{"Address", "Net id", "Ped net id", "Ped model", "Health", "Ping"};
|
||||
|
||||
|
||||
void Start()
|
||||
{
|
||||
Utilities.Stats.RegisterStat(new Utilities.Stats.Entry(){category = "PLAYERS", onGUI = OnStatGUI});
|
||||
}
|
||||
|
||||
void OnStatGUI()
|
||||
{
|
||||
|
||||
bool isServer = NetStatus.IsServer;
|
||||
|
||||
// columns
|
||||
GUILayout.BeginHorizontal();
|
||||
for (int i=0; i < m_columnNames.Length; i++)
|
||||
GUILayout.Button(m_columnNames[i], GUILayout.Width(GetWidth(i)));
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
foreach (var p in Player.AllPlayersEnumerable)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
GUILayout.Label(isServer ? p.connectionToClient.address : "", GUILayout.Width(GetWidth(0)));
|
||||
GUILayout.Label(p.netId.ToString(), GUILayout.Width(GetWidth(1)));
|
||||
GUILayout.Label(p.OwnedPed != null ? p.OwnedPed.netId.ToString() : "", GUILayout.Width(GetWidth(2)));
|
||||
GUILayout.Label(p.OwnedPed != null && p.OwnedPed.PedDef != null ? p.OwnedPed.PedDef.ModelName : "", GUILayout.Width(GetWidth(3)));
|
||||
GUILayout.Label(p.OwnedPed != null ? p.OwnedPed.Health.ToString() : "", GUILayout.Width(GetWidth(4)));
|
||||
GUILayout.Label("", GUILayout.Width(GetWidth(5)));
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
float GetWidth(int index) => m_widths[index] * Utilities.Stats.DisplayRect.width;
|
||||
|
||||
}
|
||||
}
|
|
@ -31,11 +31,12 @@ namespace SanAndreasUnity.UI
|
|||
|
||||
protected override void OnWindowGUI ()
|
||||
{
|
||||
var categories = Stats.Categories.ToArray();
|
||||
Utilities.Stats.DisplayRect = this.windowRect;
|
||||
var categories = Utilities.Stats.Categories.ToArray();
|
||||
m_tabIndex = GUIUtils.TabsControl(m_tabIndex, categories);
|
||||
if (m_tabIndex >= 0)
|
||||
{
|
||||
var stats = Stats.Entries.ElementAt(m_tabIndex).Value;
|
||||
var stats = Utilities.Stats.Entries.ElementAt(m_tabIndex).Value;
|
||||
foreach (var stat in stats)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(stat.text))
|
||||
|
|
|
@ -16,6 +16,8 @@ namespace SanAndreasUnity.Utilities
|
|||
public static IEnumerable<KeyValuePair<string, List<Entry>>> Entries => s_entries;
|
||||
public static IEnumerable<string> Categories => s_entries.Select(pair => pair.Key);
|
||||
|
||||
public static UnityEngine.Rect DisplayRect { get; set; }
|
||||
|
||||
|
||||
public static void RegisterStat(Entry entry)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue