2019-05-26 00:50:38 +00:00
|
|
|
using System.Linq;
|
|
|
|
using UnityEngine;
|
|
|
|
using SanAndreasUnity.Net;
|
|
|
|
|
|
|
|
namespace SanAndreasUnity.Stats
|
|
|
|
{
|
|
|
|
public class PlayerStats : MonoBehaviour
|
|
|
|
{
|
2021-07-23 22:28:39 +00:00
|
|
|
[SerializeField] float[] m_widths = new float[]{150, 110, 50, 70, 80, 150, 50, 80};
|
|
|
|
[SerializeField] string[] m_columnNames = new string[]{"Name", "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
|
|
|
|
2021-02-20 01:23:16 +00:00
|
|
|
float[] m_currentWidths = new float[0];
|
|
|
|
string[] m_currentColumnNames = new string[0];
|
|
|
|
|
|
|
|
public const string ColumnDataKeysKey = "player_stats_column_data_keys";
|
|
|
|
public const string ColumnNamesKey = "player_stats_column_names";
|
|
|
|
public const string ColumnWidthsKey = "player_stats_column_widths";
|
|
|
|
|
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;
|
|
|
|
|
2021-02-20 01:23:16 +00:00
|
|
|
string[] dataKeys = SyncedServerData.Data.GetStringArray(ColumnDataKeysKey) ?? new string[0];
|
|
|
|
|
|
|
|
m_currentColumnNames = m_columnNames.Concat(SyncedServerData.Data.GetStringArray(ColumnNamesKey) ?? new string[0]).ToArray();
|
|
|
|
m_currentWidths = m_widths.Concat(SyncedServerData.Data.GetFloatArray(ColumnWidthsKey) ?? new float[0]).ToArray();
|
|
|
|
|
|
|
|
if (m_currentColumnNames.Length != m_currentWidths.Length)
|
|
|
|
return;
|
|
|
|
|
2021-02-20 15:19:04 +00:00
|
|
|
if (dataKeys.Length + m_widths.Length != m_currentWidths.Length)
|
|
|
|
return;
|
|
|
|
|
2019-05-26 00:50:38 +00:00
|
|
|
// columns
|
|
|
|
GUILayout.BeginHorizontal();
|
2019-05-28 14:53:41 +00:00
|
|
|
m_currentIndex = 0;
|
2021-02-20 01:23:16 +00:00
|
|
|
for (int i=0; i < m_currentColumnNames.Length; i++)
|
|
|
|
GUILayout.Button(m_currentColumnNames[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;
|
2021-07-23 22:28:39 +00:00
|
|
|
GUILayout.Label(p.PlayerName, GUILayout.Width(GetWidth()));
|
2019-05-28 14:53:41 +00:00
|
|
|
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
|
|
|
|
2021-02-20 01:23:16 +00:00
|
|
|
foreach (string dataKey in dataKeys)
|
|
|
|
{
|
2021-07-23 22:29:36 +00:00
|
|
|
string data = p.ExtraData.GetString(dataKey) ?? string.Empty;
|
2021-02-20 01:23:16 +00:00
|
|
|
GUILayout.Label(data, GUILayout.Width(GetWidth()));
|
|
|
|
}
|
|
|
|
|
2019-05-26 00:50:38 +00:00
|
|
|
GUILayout.EndHorizontal();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-02-20 01:23:16 +00:00
|
|
|
float GetWidth() => m_currentWidths[m_currentIndex++];
|
2019-05-26 00:50:38 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|