quantum-space-buddies/QSB/QSBNetworkLobby.cs

71 lines
1.4 KiB
C#
Raw Normal View History

2020-12-20 10:56:15 +00:00
using OWML.Utils;
2021-05-03 19:13:03 +00:00
using QuantumUNET;
2020-08-21 13:04:13 +00:00
using System;
2020-08-18 20:37:27 +00:00
using System.Linq;
using UnityEngine;
namespace QSB
{
2021-05-03 19:13:03 +00:00
public class QSBNetworkLobby : QNetworkBehaviour
2020-12-02 21:29:53 +00:00
{
public bool CanEditName { get; set; }
public string PlayerName { get; private set; }
2020-08-18 20:37:27 +00:00
2021-05-25 20:52:15 +00:00
// TODO : Could delete a lot of this - shouldnt be possible to not have a profile and still play
2020-12-02 21:29:53 +00:00
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"
};
2020-08-18 20:37:27 +00:00
2020-12-14 20:41:56 +00:00
public void Awake()
2020-12-02 21:29:53 +00:00
{
PlayerName = GetPlayerName();
CanEditName = true;
}
2020-08-18 20:37:27 +00:00
2020-12-02 21:29:53 +00:00
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();
}
2020-08-18 20:37:27 +00:00
2020-12-14 21:20:53 +00:00
public void OnGUI()
2020-12-02 21:29:53 +00:00
{
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);
}
}
}
2020-12-03 08:28:05 +00:00
}