Exemplo n.º 1
0
        /// <summary>
        /// Delete the saved setting. Does not clear the current value.
        /// </summary>
        /// <see cref="M:UnityEditor.SettingsManagement.UserSetting`1.Reset(System.Boolean)" />
        /// <param name="saveProjectSettingsImmediately">True to immediately re-serialize project settings.</param>
        /// <inheritdoc cref="IUserSetting.Delete"/>
        public void Delete(bool saveProjectSettingsImmediately = false)
        {
            settings.DeleteKey <T>(key, scope);
            // Don't Init() because that will set the key again. We just want to reset the m_Value with default and
            // pretend that this field hasn't been initialised yet.
            m_Value = ValueWrapper <T> .DeepCopy(m_DefaultValue);

            m_Initialized = false;
        }
Exemplo n.º 2
0
        void Init()
        {
            if (!m_Initialized)
            {
                if (m_Scope == SettingsScope.Project && settings == null)
                {
                    throw new Exception("UserSetting \"" + m_Key + "\" is attempting to access SettingsScope.Project setting with no Settings instance!");
                }

                m_Initialized = true;

                // DeepCopy uses EditorJsonUtility which is not permitted during construction
                m_DefaultValue = ValueWrapper <T> .DeepCopy(m_Value);

                if (settings.ContainsKey <T>(m_Key, m_Scope))
                {
                    m_Value = settings.Get <T>(m_Key, m_Scope);
                }
                else
                {
                    settings.Set <T>(m_Key, m_Value, m_Scope);
                }
            }
        }