250408 TIL

박소희·2025년 4월 8일

Unity_7기

목록 보기
64/94

UGS

https://shlifedev.gitbook.io/unitygooglesheets

ResourceManager 수정

    public T LoadUI<T>(string name) where T : BaseUI
    {
        if (UIList.TryGetValue(name, out var cacheUi))
        {
            return cacheUi as T;
        }

        var ui = Resources.Load<BaseUI>($"UI/{name}") as T;
        if(ui == null)
        {
            Debug.Log("UI not found");
            return null;
        }
        UIList[name] = ui;
        return ui;
    }
  • 이름으로 불러올 수 있게 수정했다.

SoundManager - 볼륨 설정

    public float GetMasterVolume()
    {
        audioMixer.GetFloat(Master_Mixer, out float volume);
        return Mathf.Pow(10, volume / 20);
    }

    public void SetMasterVolume(float volume)
    {
        volume = Mathf.Max(0, 0.00001f);
        audioMixer.SetFloat(Master_Mixer, Mathf.Log10(volume) * 20);

        PlayerPrefs.SetFloat("MasterVolume", GetMasterVolume());
    }

    public float GetBGMVolume()
    {
        audioMixer.GetFloat(Bgm_Mixer, out float volume);
        return Mathf.Pow(10, volume / 20);
    }

    public void SetBGMVolume(float volume)
    {
        volume = Mathf.Max(0, 0.00001f);
        audioMixer.SetFloat(Bgm_Mixer, Mathf.Log10(volume) * 20);

        PlayerPrefs.SetFloat("BgmVolume", GetBGMVolume());
    }
    public float GetSFXVolume()
    {
        audioMixer.GetFloat(Sfx_Mixer, out float volume);
        return Mathf.Pow(10, volume / 20);
    }

    public void SetSFXVolume(float volume)
    {
        volume = Mathf.Max(0, 0.00001f);
        audioMixer.SetFloat(Sfx_Mixer, Mathf.Log10(volume) * 20);

        PlayerPrefs.SetFloat("SfxVolume", GetSFXVolume());
    }

    public void LoadVolume()
    {
        SetMasterVolume(PlayerPrefs.GetFloat("MasterVolume", 1f));
        SetMasterVolume(PlayerPrefs.GetFloat("BgmVolume", 1f));
        SetMasterVolume(PlayerPrefs.GetFloat("SfxVolume", 1f));
    }

0개의 댓글