示例#1
0
        internal OptionInfo(CategoryInfo category, OptionAttribute attr, Type type, PropertyInfo prop)
        {
            Name         = attr.Name ?? prop.Name;
            Category     = category;
            PropertyInfo = prop;
            Attribute    = attr;
            Key          = Argument.NotNull(type).FullName + OptionsManager.optionSeperator +
                           Argument.NotNull(prop).Name;
            var propType = prop.PropertyType;

            if (!Prefs.Exists(Key))
            {
                var val = attr.DefaultValue;
                if (val == null)
                {
                    val = CreateDefaultValue(propType);
                }
                else if (val.GetType() != propType)
                {
                    Log.Warning("Default value for {0} option does not match target type.", prop);
                    val = CreateDefaultValue(propType);
                }
                Prefs.SetString(Key, val.ToString());
            }
            ResetValue();
        }
示例#2
0
 void CheckOptionVersion()
 {
     if (!Prefs.Exists(optionVersionKey) || optionVersion != Prefs.GetInt(optionVersionKey))
     {
         ClearRegistry();
     }
     Prefs.SetInt(optionVersionKey, optionVersion);
 }
示例#3
0
 public void SetStoredLanguageId(string language)
 {
     if (Prefs.Exists(_playerPrefKey) || Prefs.GetString(_playerPrefKey) != language)
     {
         Prefs.SetString(_playerPrefKey, language);
         OnChangeLangauge.SafeInvoke(language);
     }
 }
示例#4
0
 public string GetStoredLangaugeId(string defaultLangauge)
 {
     if (!Prefs.Exists(_playerPrefKey))
     {
         SetStoredLanguageId(defaultLangauge);
     }
     return(Prefs.GetString(_playerPrefKey));
 }
示例#5
0
        // A function to initializa the OptionSystem Object
        void Initialize()
        {
            Autosave = _autosave;
            Instance = this;
            CheckOptionVersion();
            // get all classes that have Options attributes
            var query = from type in Assembly.GetExecutingAssembly().GetTypes()
                        where type.IsClass && type.GetCustomAttributes(typeof(OptionCategoryAttribute), true).Length > 0
                        select type;

            var allPropertiesStr = new StringBuilder();

            foreach (var type in query)
            {
                string categoryClassName = type.FullName;
                foreach (var property in type.GetProperties())
                {
                    allPropertiesStr.Append(categoryClassName)
                    .Append(optionSeperator)
                    .Append(property.Name)
                    .Append(keySeperator);
                }
            }

            // Remove excess characters
            if (allPropertiesStr.Length > 0)
            {
                allPropertiesStr.Remove(allPropertiesStr.Length - 1, 1);
            }
            string allProperties          = allPropertiesStr.ToString();
            IEnumerable <string> currKeys = allProperties.Split(keySeperator);

            if (Prefs.Exists(allOptionsKey))
            {
                IEnumerable <string> oldKeys = Prefs.GetString(allOptionsKey).Split(keySeperator);
                var obsoleteKeys             = oldKeys.Except(currKeys);
                foreach (string key in obsoleteKeys)
                {
                    Prefs.Delete(key);
                }
            }

            Prefs.SetString(allOptionsKey, allProperties);
            Prefs.Save();

            var types =
                currKeys.Select(k => k.Split(optionSeperator)[0])
                .Distinct()
                .Select(t => Type.GetType(t))
                .IgnoreNulls();

            foreach (Type type in types)
            {
                Get(type);
            }
        }
示例#6
0
        protected virtual void Awake()
        {
            Match = this.SafeGetComponent <Match>();
#if !UNITY_EDITOR
            if (Prefs.Exists(_playerPrefCheck))
            {
                _isActive = Prefs.GetBool(_playerPrefCheck);
            }
#endif
        }
示例#7
0
        internal OptionInfo(CategoryInfo category, OptionAttribute attr, Type type, PropertyInfo prop)
        {
            Name         = attr.Name ?? prop.Name;
            Category     = category;
            PropertyInfo = prop;
            Attribute    = attr;
            Key          = Argument.NotNull(type).FullName + optionSeperator +
                           Argument.NotNull(prop).Name;
            var propType = prop.PropertyType;

            if (!Prefs.Exists(Key))
            {
                Reset();
            }
            Revert();
        }