chip-game/Assets/Scripts/ContactsLabel.cs
2026-01-12 09:36:17 +03:00

70 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using TMPro;
using UnityEngine;
public class ContactsLabel : MonoBehaviour
{
public string startText = "администрация: ";
TextMeshProUGUI label;
private void Start()
{
label = GetComponent<TextMeshProUGUI>();
SettingsManager.OnSettingsChanged.AddListener(pullSettings);
InvokeRepeating("pullSettings", 0, 10);
}
void pullSettings()
{
string contact;
if (PlayerPrefs.HasKey("Number"))
{
contact = PlayerPrefs.GetString("Number");
}
else contact = "<Не указано>";
//if (SettingsManager.instance.GetSettingValue("Показывать контакты администрации") == "Вкл")
if (SettingsManager.GetBool("ShowNumber", true))
label.text = startText + contact;
else
label.text = "";
}
/* static string ReadContactOrDefault()
{
string filePath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
"gameData",
"contacts.txt");
try
{
if (!File.Exists(filePath))
return "<не указано>";
// читаем весь текст как UTF-8
string text = File.ReadAllText(filePath, Encoding.UTF8);
// если пусто или только пробелы/переводы строк — считаем пустым
if (string.IsNullOrWhiteSpace(text))
return "<не указано>";
return text.Trim(); // уберём крайние переводы строк/пробелы
}
catch
{
// на любой ошибке ввода-вывода — безопасное значение
return "<не указано>";
}
}*/
}