48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
|
|
public class gameSettings : MonoBehaviour
|
|
{
|
|
public Toggle multiNoteNoticeToggle;
|
|
public Text multiNoteNoticeText; // Using Legacy Text object
|
|
|
|
private const string PrefKey_EnableSyncNotePrefab = "EnableSyncNotePrefab";
|
|
|
|
void Start()
|
|
{
|
|
if (multiNoteNoticeToggle != null)
|
|
{
|
|
// Initialize toggle state from PlayerPrefs, default to 1 (true)
|
|
bool isEnabled = PlayerPrefs.GetInt(PrefKey_EnableSyncNotePrefab, 1) == 1;
|
|
multiNoteNoticeToggle.isOn = isEnabled;
|
|
|
|
// Initialize text based on current toggle value
|
|
UpdateText(isEnabled);
|
|
|
|
// Add listener to save value and update text when changed
|
|
multiNoteNoticeToggle.onValueChanged.AddListener((isOn) =>
|
|
{
|
|
PlayerPrefs.SetInt(PrefKey_EnableSyncNotePrefab, isOn ? 1 : 0);
|
|
PlayerPrefs.Save();
|
|
UpdateText(isOn);
|
|
});
|
|
}
|
|
}
|
|
|
|
private void UpdateText(bool isOn)
|
|
{
|
|
if (multiNoteNoticeText != null)
|
|
{
|
|
multiNoteNoticeText.text = isOn ? "已启用多押指示器" : "已禁用多押指示器";
|
|
}
|
|
|
|
// Also update the Toggle's own label text if it exists (usually a child object)
|
|
Text toggleLabel = multiNoteNoticeToggle.GetComponentInChildren<Text>();
|
|
if (toggleLabel != null)
|
|
{
|
|
toggleLabel.text = isOn ? "启用" : "禁用";
|
|
}
|
|
}
|
|
}
|