浮动小游戏已经基本搞好
新做了两个设置界面 一些bug修复和优化
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class audioMerger : MonoBehaviour
|
||||
{
|
||||
[Header("sv object")]
|
||||
public GameObject sv_audioSettings;
|
||||
[Header("所有声音给我站一边")]
|
||||
[Tooltip("因为静音键我要出现")]
|
||||
public Toggle enableGlobalMute_toggle;
|
||||
[Header("一堆slider")]
|
||||
public Slider mainVolumn_slider;
|
||||
public Slider noteHit_slider;
|
||||
public Slider musicInGame_slider;
|
||||
public Slider musicOutGame_slider;
|
||||
public Slider skillEffect_slider;
|
||||
public Slider uiInteration_slider;
|
||||
public Slider cvVolumn_slider;
|
||||
[Header("配套的一堆text")]
|
||||
public Text mainVolumn_text;
|
||||
public Text noteHit_text;
|
||||
public Text musicInGame_text;
|
||||
public Text musicOutGame_text;
|
||||
public Text skillEffect_text;
|
||||
public Text uiInteration_text;
|
||||
public Text cvVolumn_text;
|
||||
|
||||
// PlayerPrefs key for storing the toggle state
|
||||
const string PlayerPrefKey_EnableGlobalMute = "EnableGlobalMute";
|
||||
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
// Load saved state (default: false)
|
||||
bool isOn = PlayerPrefs.GetInt(PlayerPrefKey_EnableGlobalMute, 0) == 1;
|
||||
|
||||
// Apply to toggle (if available) and sv_audioSettings
|
||||
if (enableGlobalMute_toggle != null)
|
||||
{
|
||||
// Prevent accidentally invoking listeners while initializing
|
||||
enableGlobalMute_toggle.onValueChanged.RemoveAllListeners();
|
||||
enableGlobalMute_toggle.isOn = isOn;
|
||||
enableGlobalMute_toggle.onValueChanged.AddListener(OnEnableGlobalMuteChanged);
|
||||
}
|
||||
|
||||
if (sv_audioSettings != null)
|
||||
{
|
||||
// 非模式:当 toggle 为开启 (isOn == true) 时,禁用 sv_audioSettings
|
||||
sv_audioSettings.SetActive(!isOn);
|
||||
}
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
if (enableGlobalMute_toggle != null)
|
||||
{
|
||||
enableGlobalMute_toggle.onValueChanged.RemoveListener(OnEnableGlobalMuteChanged);
|
||||
}
|
||||
}
|
||||
|
||||
// Listener called when the toggle value changes
|
||||
void OnEnableGlobalMuteChanged(bool isOn)
|
||||
{
|
||||
// Save to PlayerPrefs
|
||||
PlayerPrefs.SetInt(PlayerPrefKey_EnableGlobalMute, isOn ? 1 : 0);
|
||||
PlayerPrefs.Save();
|
||||
|
||||
// 应用非模式:当 toggle 为开启时,禁用 sv_audioSettings
|
||||
if (sv_audioSettings != null)
|
||||
{
|
||||
sv_audioSettings.SetActive(!isOn);
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user