quantum-space-buddies/QSB/QSBNetworkLobby.cs
Mister_Nebula c7005765a0 fixes
2021-01-18 12:33:07 +00:00

69 lines
1.3 KiB
C#

using OWML.Utils;
using System;
using System.Linq;
using UnityEngine;
using UnityEngine.Networking;
namespace QSB
{
public class QSBNetworkLobby : NetworkBehaviour
{
public bool CanEditName { get; set; }
public string PlayerName { get; private set; }
private readonly string[] _defaultNames = {
"Arkose",
"Chert",
"Esker",
"Hal",
"Hornfels",
"Feldspar",
"Gabbro",
"Galena",
"Gneiss",
"Gossan",
"Marl",
"Mica",
"Moraine",
"Porphy",
"Riebeck",
"Rutile",
"Slate",
"Spinel",
"Tektite",
"Tephra",
"Tuff",
"Jinha"
};
public void Awake()
{
PlayerName = GetPlayerName();
CanEditName = true;
}
private string GetPlayerName()
{
var profileManager = StandaloneProfileManager.SharedInstance;
profileManager.Initialize();
var profile = profileManager.GetValue<StandaloneProfileManager.ProfileData>("_currentProfile");
var profileName = profile?.profileName;
return !string.IsNullOrEmpty(profileName)
? profileName
: _defaultNames.OrderBy(x => Guid.NewGuid()).First();
}
public void OnGUI()
{
GUI.Label(new Rect(10, 10, 200f, 20f), "Name:");
if (CanEditName)
{
PlayerName = GUI.TextField(new Rect(60, 10, 145, 20f), PlayerName);
}
else
{
GUI.Label(new Rect(60, 10, 145, 20f), PlayerName);
}
}
}
}