Beispiel #1
0
        /// <summary>
        /// 惰式初始化
        /// </summary>
        public static void Init()
        {
            if (_isInited)
            {
                return;
            }

            var settingPath   = string.Format("I18N/{0}{1}", Lang, AppEngine.GetConfig(KEngineDefaultConfigs.SettingExt));
            var settingReader = SettingModule.Get(settingPath, false);

            foreach (var row in settingReader)
            {
                Strs[row["Id"]] = row["Value"];
            }

#if UNITY_EDITOR
            // 开发热重载
            if (SettingModule.IsFileSystemMode)
            {
                SettingModule.WatchSetting(settingPath, (_) =>
                {
                    _isInited = false;
                });
            }
#endif
            _isInited = true;
        }
Beispiel #2
0
    IEnumerator Start()
    {
        KGameSettings.Instance.InitAction += OnGameSettingsInit;

        var engine = KEngine.AppEngine.New(
            gameObject,
            new IModule[]
        {
            //KGameSettings.Instance,
        },
            null,
            null);

        while (!engine.IsInited)
        {
            yield return(null);
        }

        KUIModule.Instance.OpenWindow <KUIDemoHome>();

        KUIModule.Instance.CallUI <KUIDemoHome>(ui =>
        {
            // Do some UI stuff
        });

        Debug.Log("[SettingModule]Table: " + ExampleInfo.TabFilePath);
        var exampleInfoTable = SettingModule.Get <ExampleInfo>(ExampleInfo.TabFilePath);

        foreach (var info in exampleInfoTable.GetAll())
        {
            Debug.Log(string.Format("Name: {0}", info.Name));
        }
    }
Beispiel #3
0
        /// <summary>
        /// Do reload the setting file: GameConfig
        /// </summary>
        void _ReloadAll(bool throwWhenDuplicatePrimaryKey, string customContent = null)
        {
            for (var j = 0; j < TabFilePaths.Length; j++)
            {
                var       tabFilePath = TabFilePaths[j];
                TableFile tableFile;
                if (customContent == null)
                {
                    tableFile = SettingModule.Get(tabFilePath, false);
                }
                else
                {
                    tableFile = TableFile.LoadFromString(customContent);
                }

                using (tableFile)
                {
                    foreach (var row in tableFile)
                    {
                        var pk = GameConfigSetting.ParsePrimaryKey(row);
                        GameConfigSetting setting;
                        if (!_dict.TryGetValue(pk, out setting))
                        {
                            setting           = new GameConfigSetting(row);
                            _dict[setting.Id] = setting;
                        }
                        else
                        {
                            if (throwWhenDuplicatePrimaryKey)
                            {
                                throw new System.Exception(string.Format("DuplicateKey, Class: {0}, File: {1}, Key: {2}", this.GetType().Name, tabFilePath, pk));
                            }
                            else
                            {
                                setting.Reload(row);
                            }
                        }
                    }
                }
            }

            if (OnReload != null)
            {
                OnReload();
            }

            ReloadCount++;
            Log.Info("Reload settings: {0}, Row Count: {1}, Reload Count: {2}", GetType(), Count, ReloadCount);
        }
        /// <summary>
        /// Do reload the setting file: SubdirSubSubDirExample3
        /// </summary>
        void _ReloadAll(bool throwWhenDuplicatePrimaryKey)
        {
            for (var j = 0; j < TabFilePaths.Length; j++)
            {
                var tabFilePath = TabFilePaths[j];
                using (var tableFile = SettingModule.Get(tabFilePath, false))
                {
                    foreach (var row in tableFile)
                    {
                        var pk = SubdirSubSubDirExample3Setting.ParsePrimaryKey(row);
                        SubdirSubSubDirExample3Setting setting;
                        if (!_dict.TryGetValue(pk, out setting))
                        {
                            setting           = new SubdirSubSubDirExample3Setting(row);
                            _dict[setting.Id] = setting;
                        }
                        else
                        {
                            if (throwWhenDuplicatePrimaryKey)
                            {
                                throw new System.Exception(string.Format("DuplicateKey, Class: {0}, File: {1}, Key: {2}", this.GetType().Name, tabFilePath, pk));
                            }
                            else
                            {
                                setting.Reload(row);
                            }
                        }
                    }
                }
            }

            if (OnReload != null)
            {
                OnReload();
            }
        }