SanAndreasUnity/Assets/Scripts/Stats/PlayerStats.cs

55 lines
2.2 KiB
C#
Raw Normal View History

2019-05-26 00:50:38 +00:00
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Mirror;
using SanAndreasUnity.Net;
namespace SanAndreasUnity.Stats
{
public class PlayerStats : MonoBehaviour
{
2019-07-06 21:06:15 +00:00
[SerializeField] float[] m_widths = new float[]{110, 50, 70, 80, 150, 50, 80};
[SerializeField] string[] m_columnNames = new string[]{"Address", "Net id", "Ped net id", "Ped model", "Ped state", "Health", "Weapon"};
2019-05-28 14:53:41 +00:00
int m_currentIndex = 0;
2019-05-26 00:50:38 +00:00
void Start()
{
Utilities.Stats.RegisterStat(new Utilities.Stats.Entry(){category = "PLAYERS", onGUI = OnStatGUI});
}
void OnStatGUI()
{
bool isServer = NetStatus.IsServer;
// columns
GUILayout.BeginHorizontal();
2019-05-28 14:53:41 +00:00
m_currentIndex = 0;
2019-05-26 00:50:38 +00:00
for (int i=0; i < m_columnNames.Length; i++)
2019-05-28 14:53:41 +00:00
GUILayout.Button(m_columnNames[i], GUILayout.Width(GetWidth()));
2019-05-26 00:50:38 +00:00
GUILayout.EndHorizontal();
foreach (var p in Player.AllPlayersEnumerable)
{
GUILayout.BeginHorizontal();
2019-05-28 14:53:41 +00:00
m_currentIndex = 0;
GUILayout.Label(isServer ? p.connectionToClient.address : "", GUILayout.Width(GetWidth()));
GUILayout.Label(p.netId.ToString(), GUILayout.Width(GetWidth()));
GUILayout.Label(p.OwnedPed != null ? p.OwnedPed.netId.ToString() : "", GUILayout.Width(GetWidth()));
GUILayout.Label(p.OwnedPed != null && p.OwnedPed.PedDef != null ? p.OwnedPed.PedDef.ModelName : "", GUILayout.Width(GetWidth()));
GUILayout.Label(p.OwnedPed != null && p.OwnedPed.CurrentState != null ? p.OwnedPed.CurrentState.GetType().Name : "", GUILayout.Width(GetWidth()));
GUILayout.Label(p.OwnedPed != null ? p.OwnedPed.Health.ToString() : "", GUILayout.Width(GetWidth()));
2019-07-06 21:06:15 +00:00
GUILayout.Label(p.OwnedPed != null && p.OwnedPed.CurrentWeapon != null && p.OwnedPed.CurrentWeapon.Definition != null ? p.OwnedPed.CurrentWeapon.Definition.ModelName : "", GUILayout.Width(GetWidth()));
2019-05-26 00:50:38 +00:00
GUILayout.EndHorizontal();
}
}
2019-05-28 14:53:41 +00:00
float GetWidth() => m_widths[m_currentIndex++];
2019-05-26 00:50:38 +00:00
}
}