SanAndreasUnity/Assets/Scripts/Stats/PlayerStats.cs
2020-05-31 19:09:41 +02:00

50 lines
1.8 KiB
C#

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[]{80, 15, 15, 20, 60, 15};
string[] m_columnNames = new string[]{"Address", "Net id", "Ped net id", "Ped model", "Ped state", "Health"};
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.CurrentState != null ? p.OwnedPed.CurrentState.GetType().Name : "", GUILayout.Width(GetWidth(4)));
GUILayout.Label(p.OwnedPed != null ? p.OwnedPed.Health.ToString() : "", GUILayout.Width(GetWidth(5)));
GUILayout.EndHorizontal();
}
}
float GetWidth(int index) => m_widths[index];
}
}