You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.4 KiB
52 lines
1.4 KiB
using System.Text;
|
|
using UnityEngine;
|
|
|
|
public static class LocalPlayerData
|
|
{
|
|
public static ulong ID;
|
|
public static string PlayerName;
|
|
public static string Email;
|
|
public static string AvatarID;
|
|
public static string RoomID;
|
|
|
|
private static string GenerateRandomString(int length)
|
|
{
|
|
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
StringBuilder result = new StringBuilder(length);
|
|
|
|
for (int i = 0; i < length; i++)
|
|
{
|
|
result.Append(chars[Random.Range(0, chars.Length)]);
|
|
}
|
|
|
|
return result.ToString();
|
|
}
|
|
|
|
static LocalPlayerData()
|
|
{
|
|
ID = (ulong) Random.Range(0, int.MaxValue);
|
|
PlayerName = "GUEST_" + GenerateRandomString(6);
|
|
RoomID = "Room1";
|
|
AvatarID = "char_james";
|
|
}
|
|
|
|
public static void Set(UserLoginResult userLogin)
|
|
{
|
|
try
|
|
{
|
|
ID = ulong.Parse(userLogin.id);
|
|
PlayerName = userLogin.login;
|
|
Email = userLogin.email;
|
|
AvatarID = userLogin.avatarId;
|
|
RoomID = userLogin.roomId;
|
|
}
|
|
catch (System.FormatException)
|
|
{
|
|
Debug.Log("Conversion failed: Invalid format.");
|
|
}
|
|
catch (System.OverflowException)
|
|
{
|
|
Debug.Log("Conversion failed: Value is too large or too small.");
|
|
}
|
|
}
|
|
}
|
|
|