/// <summary> /// Load values found inside PlayerPrefs. /// </summary> private void LoadValues() { ResolutionIndex = PlayerPrefs.GetInt("SETTINGSMANAGER_RESOLUTIONINDEX", ResolutionIndex); if (ResolutionIndex <= -1) { Vector2Int currentResolution = new Vector2Int(Screen.currentResolution.width, Screen.currentResolution.height); bool exit = false; foreach (KeyValuePair <AspectRatioTypes, Vector2Int[]> aspectRatio in m_ResolutionList) { for (int i = 0; i < aspectRatio.Value.Length; i++) { if (currentResolution == aspectRatio.Value[i]) { ResolutionIndex = i; AspectRatio = aspectRatio.Key; exit = true; break; } } if (exit) { break; } } if (ResolutionIndex == -1) { // Standard 1080p ResolutionIndex = 2; AspectRatio = AspectRatioTypes.Ratio16by9; } } else { AspectRatio = PlayerPrefsUtil.GetEnum("SETTINGSMANAGER_ASPECTRATIO", AspectRatio); } Fullscreen = PlayerPrefsUtil.GetBool("SETTINGSMANAGER_FULLSCREEN", Fullscreen); RefreshRate = PlayerPrefs.GetInt("SETTINGSMANAGER_REFRESHRATE", RefreshRate); PixelLightCount = PlayerPrefs.GetInt("SETTINGSMANAGER_PIXELLIGHTCOUNT", PixelLightCount); TextureQuality = PlayerPrefsUtil.GetEnum("SETTINGSMANAGER_TEXTUREQUALITYTYPE", TextureQuality); AnisotropicFiltering = PlayerPrefsUtil.GetBool("SETTINGSMANAGER_ANISOTROPICFILTERING", AnisotropicFiltering); AntiAliasing = PlayerPrefsUtil.GetEnum("SETTINGSMANAGER_ANTIALIASING", AntiAliasing); SoftParticles = PlayerPrefsUtil.GetBool("SETTINGSMANAGER_SOFTPARTICLES", SoftParticles); RealtimeReflectionProbe = PlayerPrefsUtil.GetBool("SETTINGSMANAGER_REALTIMEREFLECTIONPROBE", RealtimeReflectionProbe); VSyncCount = PlayerPrefs.GetInt("SETTINGSMANAGER_VSYNCCOUNT", VSyncCount); ShadowQualityType = PlayerPrefsUtil.GetEnum("SETTINGSMANAGER_SHADOWQUALITYTYPE", ShadowQualityType); ShadowResolutionType = PlayerPrefsUtil.GetEnum("SETTINGSMANAGER_SHADOWRESOLUTIONTYPE", ShadowResolutionType); ShadowProjectionType = PlayerPrefsUtil.GetEnum("SETTINGSMANAGER_SHADOWPROJECTIONTYPE", ShadowProjectionType); ShadowDistance = PlayerPrefsUtil.GetEnum("SETTINGSMANAGER_SHADOWDISTANCETYPE", ShadowDistance); ShadowmaskModeType = PlayerPrefsUtil.GetEnum("SETTINGSMANAGER_SHADOWMASKMODE", ShadowmaskModeType); ShadowNearPlaneOffset = PlayerPrefs.GetInt("SETTINGSMANAGER_SHADOWNEARPLANEOFFSET", ShadowNearPlaneOffset); ShadowCascadeType = PlayerPrefsUtil.GetEnum("SETTINGSMANAGER_SHADOWCASCADETYPE", ShadowCascadeType); }
/// <summary> /// Load values from a SettingPreset object minus resolution. /// </summary> public void LoadValues(SettingsPreset preset) { PixelLightCount = preset.PixelLightCount; TextureQuality = preset.TextureQuality; AnisotropicFiltering = preset.AnisotropicFiltering; AntiAliasing = preset.AntiAliasing; SoftParticles = preset.SoftParticles; RealtimeReflectionProbe = preset.RealtimeReflectionProbe; VSyncCount = preset.VSyncCount; ShadowQualityType = preset.ShadowQualityType; ShadowResolutionType = preset.ShadowResolutionType; ShadowProjectionType = preset.ShadowProjectionType; ShadowDistance = preset.ShadowDistance; ShadowmaskModeType = preset.ShadowmaskModeType; ShadowNearPlaneOffset = preset.ShadowNearPlaneOffset; ShadowCascadeType = preset.ShadowCascadeType; }
/// <summary> /// Load values from a SettingPreset object including resolution. /// </summary> public void LoadValues(SettingsPreset preset, bool loadResolution) { if (loadResolution) { ResolutionIndex = PlayerPrefs.GetInt("SETTINGSMANAGER_RESOLUTIONINDEX", ResolutionIndex); if (ResolutionIndex <= -1) { Vector2Int currentResolution = new Vector2Int(Screen.currentResolution.width, Screen.currentResolution.height); bool exit = false; foreach (KeyValuePair <AspectRatioTypes, Vector2Int[]> aspectRatio in m_ResolutionList) { for (int i = 0; i < aspectRatio.Value.Length; i++) { if (currentResolution == aspectRatio.Value[i]) { ResolutionIndex = i; AspectRatio = aspectRatio.Key; exit = true; break; } } if (exit) { break; } } if (ResolutionIndex == -1) { // Standard 1080p ResolutionIndex = 2; AspectRatio = AspectRatioTypes.Ratio16by9; } } else { AspectRatio = PlayerPrefsUtil.GetEnum("SETTINGSMANAGER_ASPECTRATIO", AspectRatio); } Fullscreen = PlayerPrefsUtil.GetBool("SETTINGSMANAGER_FULLSCREEN", Fullscreen); RefreshRate = PlayerPrefs.GetInt("SETTINGSMANAGER_REFRESHRATE", RefreshRate); } PixelLightCount = preset.PixelLightCount; TextureQuality = preset.TextureQuality; AnisotropicFiltering = preset.AnisotropicFiltering; AntiAliasing = preset.AntiAliasing; SoftParticles = preset.SoftParticles; RealtimeReflectionProbe = preset.RealtimeReflectionProbe; VSyncCount = preset.VSyncCount; ShadowQualityType = preset.ShadowQualityType; ShadowResolutionType = preset.ShadowResolutionType; ShadowProjectionType = preset.ShadowProjectionType; ShadowDistance = preset.ShadowDistance; ShadowmaskModeType = preset.ShadowmaskModeType; ShadowNearPlaneOffset = preset.ShadowNearPlaneOffset; ShadowCascadeType = preset.ShadowCascadeType; }
/// <summary> /// Apply changes done to the manager towards the actual game. If overwrite, it will force save all settings, not just the changed ones. /// </summary> public void ApplyChanges(bool overwrite = false) { // Screen if (overwrite || (m_CurrentResolutionIndex != ResolutionIndex || m_CurrentAspectRatio != AspectRatio || m_CurrentlyFullscreen != Fullscreen || m_CurrentRefreshRate != RefreshRate)) { m_CurrentAspectRatio = AspectRatio; m_CurrentResolutionIndex = ResolutionIndex; m_CurrentlyFullscreen = Fullscreen; m_CurrentRefreshRate = RefreshRate; Vector2Int resolution = m_ResolutionList[m_CurrentAspectRatio][m_CurrentResolutionIndex]; Screen.SetResolution(resolution.x, resolution.y, m_CurrentlyFullscreen, m_CurrentRefreshRate); PlayerPrefsUtil.SetEnum("SETTINGSMANAGER_ASPECTRATIO", m_CurrentAspectRatio); PlayerPrefs.SetInt("SETTINGSMANAGER_RESOLUTIONINDEX", m_CurrentResolutionIndex); PlayerPrefsUtil.SetBool("SETTINGSMANAGER_FULLSCREEN", m_CurrentlyFullscreen); PlayerPrefs.GetInt("SETTINGSMANAGER_REFRESHRATE", m_CurrentRefreshRate); } // Graphics if (overwrite || (m_CurrentPixelLightCount != PixelLightCount)) { m_CurrentPixelLightCount = PixelLightCount; QualitySettings.pixelLightCount = m_CurrentPixelLightCount; PlayerPrefs.SetInt("SETTINGSMANAGER_PIXELLIGHTCOUNT", m_CurrentPixelLightCount); } if (overwrite || (m_CurrentTextureQualityType != TextureQuality)) { m_CurrentTextureQualityType = TextureQuality; QualitySettings.masterTextureLimit = (int)m_CurrentTextureQualityType; PlayerPrefsUtil.SetEnum("SETTINGSMANAGER_TEXTUREQUALITYTYPE", m_CurrentTextureQualityType); } if (overwrite || (m_CurrentAnisotropicFiltering != AnisotropicFiltering)) { m_CurrentAnisotropicFiltering = AnisotropicFiltering; QualitySettings.anisotropicFiltering = m_CurrentAnisotropicFiltering ? UnityEngine.AnisotropicFiltering.Enable : UnityEngine.AnisotropicFiltering.Disable; PlayerPrefsUtil.SetBool("SETTINGSMANAGER_ANISOTROPICFILTERING", m_CurrentAnisotropicFiltering); } if (overwrite || (m_CurrentAntiAliasingType != AntiAliasing)) { m_CurrentAntiAliasingType = AntiAliasing; QualitySettings.antiAliasing = (int)m_CurrentAntiAliasingType; PlayerPrefsUtil.SetEnum("SETTINGSMANAGER_ANTIALIASINGTYPE", m_CurrentAntiAliasingType); } if (overwrite || (m_CurrentSoftParticles != SoftParticles)) { m_CurrentSoftParticles = SoftParticles; QualitySettings.softParticles = m_CurrentSoftParticles; PlayerPrefsUtil.SetBool("SETTINGSMANAGER_SOFTPARTICLES", m_CurrentSoftParticles); } if (overwrite || (m_CurrentRealtimeReflectionProbe != RealtimeReflectionProbe)) { m_CurrentRealtimeReflectionProbe = RealtimeReflectionProbe; QualitySettings.realtimeReflectionProbes = m_CurrentRealtimeReflectionProbe; PlayerPrefsUtil.SetBool("SETTINGSMANAGER_REALTIMEREFLECTIONPROBE", m_CurrentRealtimeReflectionProbe); } if (overwrite || (m_CurrentVSyncCount != VSyncCount)) { m_CurrentVSyncCount = VSyncCount; QualitySettings.vSyncCount = VSyncCount; PlayerPrefs.SetInt("SETTINGSMANAGER_VSYNCCOUNT", m_CurrentVSyncCount); } // Shadows if (overwrite || (m_CurrentShadowQualityType != ShadowQualityType)) { m_CurrentShadowQualityType = ShadowQualityType; QualitySettings.shadows = m_CurrentShadowQualityType; PlayerPrefsUtil.SetEnum("SETTINGSMANAGER_SHADOWQUALITYTYPE", m_CurrentShadowQualityType); } if (overwrite || (m_CurrentShadowResolutionType != ShadowResolutionType)) { m_CurrentShadowResolutionType = ShadowResolutionType; QualitySettings.shadowResolution = m_CurrentShadowResolutionType; PlayerPrefsUtil.SetEnum("SETTINGSMANAGER_SHADOWRESOLUTIONTYPE", m_CurrentShadowQualityType); } if (overwrite || (m_CurrentShadowProjectionType != ShadowProjectionType)) { m_CurrentShadowProjectionType = ShadowProjectionType; QualitySettings.shadowProjection = m_CurrentShadowProjectionType; PlayerPrefsUtil.SetEnum("SETTINGSMANAGER_SHADOWPROJECTIONTYPE", m_CurrentShadowProjectionType); } if (overwrite || (m_CurrentShadowDistanceType != ShadowDistance)) { m_CurrentShadowDistanceType = ShadowDistance; QualitySettings.shadowDistance = (int)m_CurrentShadowDistanceType; PlayerPrefsUtil.SetEnum("SETTINGSMANAGER_SHADOWDISTANCETYPE", m_CurrentShadowProjectionType); } if (overwrite || (m_CurrentShadowmaskModeType != ShadowmaskModeType)) { m_CurrentShadowmaskModeType = ShadowmaskModeType; QualitySettings.shadowmaskMode = m_CurrentShadowmaskModeType; PlayerPrefsUtil.SetEnum("SETTINGSMANAGER_SHADOWMASKMODE", m_CurrentShadowmaskModeType); } if (overwrite || (m_CurrentShadowNearPlaneOffset != ShadowNearPlaneOffset)) { m_CurrentShadowNearPlaneOffset = ShadowNearPlaneOffset; QualitySettings.shadowNearPlaneOffset = m_CurrentShadowNearPlaneOffset; PlayerPrefs.SetInt("SETTINGSMANAGER_SHADOWNEARPLANEOFFSET", m_CurrentShadowNearPlaneOffset); } if (overwrite || (m_CurrentShadowCascadeType != ShadowCascadeType)) { m_CurrentShadowCascadeType = ShadowCascadeType; QualitySettings.shadowCascades = (int)m_CurrentShadowCascadeType; PlayerPrefsUtil.SetEnum("SETTINGSMANAGER_SHADOWCASCADETYPE", m_CurrentShadowCascadeType); } }