SetBool() public static méthode

public static SetBool ( string key, bool value ) : void
key string
value bool
Résultat void
 static void ToggleMute(string key, bool value)
 {
     PlayerPrefsUtil.SetBool(
         key,
         value
         );
 }
Exemple #2
0
    private void LoadAllSetting()
    {
        bool isAppLaunchedFirstTime = PlayerPrefsUtil.GetBool(PrefsConstant.KEY_IS_APP_LAUNCHED_FIRST_TIME);

        if (!isAppLaunchedFirstTime)
        {
            PlayerPrefsUtil.SetBool(PrefsConstant.KEY_IS_APP_LAUNCHED_FIRST_TIME, true);
            PlayerPrefsUtil.SetFloat(PrefsConstant.KEY_SOUND_VOLUME, 1f);
            PlayerPrefsUtil.SetFloat(PrefsConstant.KEY_MUSIC_VOLUME, 1f);
            PlayerPrefsUtil.SetFloat(PrefsConstant.KEY_GLOBAL_VOLUME, 1f);
        }
        mSoundVolume  = PlayerPrefsUtil.GetFloat(PrefsConstant.KEY_SOUND_VOLUME);
        mMusicVolume  = PlayerPrefsUtil.GetFloat(PrefsConstant.KEY_MUSIC_VOLUME);
        mGlobalVolume = PlayerPrefsUtil.GetFloat(PrefsConstant.KEY_GLOBAL_VOLUME);
        //Debug.Log("Load " + mSoundVolume);
        //Debug.Log("Load " + mMusicVolume);
        //Debug.Log("Load " + mGlobalVolume);
    }
        private void OnDestroy()
        {
            string type = typeof(T).ToString();

            PlayerPrefs.SetInt(type + "_RESULTSIZE_X", m_ResultSize.x);
            PlayerPrefs.SetInt(type + "_RESULTSIZE_Y", m_ResultSize.y);

            PlayerPrefsUtil.SetStringArray(type + "_BOXKEYS", m_ComponentBoxes.ExtractKeys().ToArray());

            foreach (KeyValuePair <string, TextureColorContainer> tcc in m_ComponentBoxes)
            {
                PlayerPrefsUtil.SetBool(type + "_ISCOLOR_" + tcc.Key, tcc.Value.IsColor);
                PlayerPrefs.SetString(type + "_TEXPATH_" + tcc.Key, AssetDatabase.GetAssetPath(tcc.Value.Texture));
                PlayerPrefsUtil.SetColor(type + "_COLOR_" + tcc.Key, tcc.Value.Color);
            }

            PlayerPrefsUtil.SetFloatArray(type + "_SAVEABLES", GetSaveableValues());
        }
        /// <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);
            }
        }