using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.Events; public class ControlSettings : MonoBehaviour { private const string ControlOnRightKey = "ControlOnRight"; private const string HapticKey = "ControlOnRight"; public Button left; public Button right; public Toggle HapticToggle; public static bool ControlIsOnRight = true; public static bool HapticEnabled = true; public UnityEvent OnChanged; void Awake() { if(PlayerPrefs.HasKey(ControlOnRightKey)){ ControlIsOnRight = PlayerPrefs.GetInt(ControlOnRightKey) == 1; } if(PlayerPrefs.HasKey(HapticKey)){ HapticEnabled = PlayerPrefs.GetInt(HapticKey) == 1; } left.onClick.AddListener(()=>{ChangeControlSide(true);}); right.onClick.AddListener(()=>{ChangeControlSide(false);}); HapticToggle.onValueChanged.AddListener(ToggleHaptic); UpdateSettingsPage(); } void ChangeControlSide(bool value){ ControlIsOnRight = value; PlayerPrefs.SetInt(ControlOnRightKey, value? 1: 0); PlayerPrefs.Save(); UpdateSettingsPage(); OnChanged.Invoke(); AudioManager.instnace.UIClick(); } public void ToggleHaptic(bool value){ PlayerPrefs.SetInt(HapticKey, value ? 1 : 0); PlayerPrefs.Save(); HapticEnabled = value; } void UpdateSettingsPage(){ left.transform.GetChild(0).GetComponent().color = (!ControlIsOnRight) ? Color.blue : Color.green; right.transform.GetChild(0).GetComponent().color = (ControlIsOnRight) ? Color.blue : Color.green; HapticToggle.isOn = HapticEnabled; } }