57 lines
1.3 KiB
C#
57 lines
1.3 KiB
C#
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.Audio;
|
||
|
using UnityEngine.Events;
|
||
|
|
||
|
public class Settings : MonoBehaviour
|
||
|
{
|
||
|
public delegate void OnSensitivityChangedDelegate(float sensitivity);
|
||
|
public delegate void OnVolumeChangedDelegate(float sensitivity);
|
||
|
|
||
|
public static event OnSensitivityChangedDelegate onSensitivityChanged;
|
||
|
public static event OnVolumeChangedDelegate onVolumeChanged;
|
||
|
|
||
|
[SerializeField] private AudioMixer audioMixer;
|
||
|
|
||
|
public static Settings instance;
|
||
|
|
||
|
void Awake()
|
||
|
{
|
||
|
if (instance == null)
|
||
|
{
|
||
|
instance = this;
|
||
|
}
|
||
|
|
||
|
DontDestroyOnLoad(this);
|
||
|
}
|
||
|
|
||
|
void Start()
|
||
|
{
|
||
|
if (!PlayerPrefs.HasKey("Sensitivity"))
|
||
|
{
|
||
|
PlayerPrefs.SetFloat("Sensitivity", 1.0f);
|
||
|
}
|
||
|
|
||
|
if (!PlayerPrefs.HasKey("Volume"))
|
||
|
{
|
||
|
PlayerPrefs.SetFloat("Volume", 0.5f);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void SetSensitivity(float sensitivity)
|
||
|
{
|
||
|
PlayerPrefs.SetFloat("Sensitivity", sensitivity);
|
||
|
onSensitivityChanged?.Invoke(sensitivity);
|
||
|
}
|
||
|
|
||
|
public void SetVolume(float volume)
|
||
|
{
|
||
|
PlayerPrefs.SetFloat("Volume", volume);
|
||
|
audioMixer.SetFloat("MasterVolume", Mathf.Log10(volume) * 60);
|
||
|
onVolumeChanged?.Invoke(volume);
|
||
|
}
|
||
|
|
||
|
}
|