44 lines
1.4 KiB
C#
44 lines
1.4 KiB
C#
using UnityEngine;
|
|
|
|
namespace Vanguard.App
|
|
{
|
|
/// <summary>
|
|
/// Настройки клиента. Пока хранятся в PlayerPrefs: для dev-сборки этого
|
|
/// достаточно, позже серверный URL и токены переедут в лаунчер/защищённое
|
|
/// хранилище.
|
|
/// </summary>
|
|
public sealed class AppConfig
|
|
{
|
|
public const string DefaultServerUrl = "http://192.168.31.158:18080";
|
|
private const string ServerUrlKey = "vanguard.serverUrl";
|
|
|
|
public string ServerBaseUrl { get; private set; } = DefaultServerUrl;
|
|
public float RequestTimeoutSeconds => 20f;
|
|
public string ClientBuild => Application.version;
|
|
|
|
public void Load()
|
|
{
|
|
ServerBaseUrl = Normalize(PlayerPrefs.GetString(ServerUrlKey, DefaultServerUrl));
|
|
}
|
|
|
|
public void SetServerBaseUrl(string value)
|
|
{
|
|
ServerBaseUrl = Normalize(value);
|
|
PlayerPrefs.SetString(ServerUrlKey, ServerBaseUrl);
|
|
PlayerPrefs.Save();
|
|
}
|
|
|
|
public static string Normalize(string value)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(value))
|
|
return DefaultServerUrl;
|
|
|
|
value = value.Trim();
|
|
if (!value.StartsWith("http://") && !value.StartsWith("https://"))
|
|
value = "http://" + value;
|
|
|
|
return value.TrimEnd('/');
|
|
}
|
|
}
|
|
}
|