예제 #1
0
 public static SynchronizedSettings getInstance()
 {
     if (instance == null)
     {
         instance = new SynchronizedSettings();
     }
     return(instance);
 }
예제 #2
0
 // Use this for initialization
 void Start()
 {
     // 最常見,缺點是在多執行緒中會有問題,確認不會在多執行緒中使用的話,用這個就好
     Debug.LogFormat("Settings volume is {0}", Settings.getInstance().volume);
     // 在多執行緒中不會有問題,但沒有延遲實例化的好處了,不過Singleton物件一般來說也都很早就實例化,沒啥差
     Debug.LogFormat("EagerlySettings volume is {0}", EagerlySettings.getInstance().volume);
     // 在多執行緒中不會有問題,但效能較差,每次試圖同時呼叫getInstance()都會造成等待
     Debug.LogFormat("SynchronizedSettings volume is {0}", SynchronizedSettings.getInstance().volume);
     // 在多執行緒中不會有問題,且只有第一次呼叫getInstance()時可能會造成等待,之後就沒有效能問題
     Debug.LogFormat("LockSettings volume is {0}", LockSettings.getInstance().volume);
 }
예제 #3
0
        public SynchronizedSettings Load(string name, string rootname)
        {
            if (!name.EndsWith(".xml", StringComparison.InvariantCultureIgnoreCase))
                name += ".xml";

            string path = Path.Combine(directory.FullName, name);

            SynchronizedSettings settings = new SynchronizedSettings(rootname);
            settings.Path = path;
            settings.Load();
            return settings;
        }
예제 #4
0
        public SpellList()
        {
            List<SpellAlias> list = new List<SpellAlias>(64);

            Settings settings = new SynchronizedSettings("SpellNames");
            settings.Path = Path.Combine(Core.Directory, FileName);

            if (File.Exists(settings.Path)) {
                settings.Load();
            }
            else {
                CreateDefault(settings);
                settings.Save();
            }

            ElementInfo[] elementList = settings.EnumarateElements("Spell");

            for (int i = 0; i < elementList.Length; i++) {
                object aliasObj;
                object spellObj;

                if (!elementList[i].Attributes.TryGetValue("alias", out aliasObj))
                    continue;

                if (!elementList[i].Attributes.TryGetValue("number", out spellObj))
                    continue;

                string alias = aliasObj.ToString().ToLowerInvariant();
                string spellStr = spellObj.ToString();

                byte spell;

                if (spellStr.StartsWith("0x") && Byte.TryParse(spellStr.Remove(0, 2), NumberStyles.HexNumber, null, out spell)) {
                    list.Add(new SpellAlias(alias, spell));
                }
                else if (Byte.TryParse(spellStr, out spell)) {
                    list.Add(new SpellAlias(alias, spell));
                }
            }

            spellList = list.ToArray();
        }