Ejemplo n.º 1
0
        /// <summary>
        /// Get the singleton
        /// </summary>
        /// <returns></returns>
        public static TestDataTables GetInstance()
        {
            if (ReloadCount == 0)
            {
                _instance._ReloadAll(true);
    #if UNITY_EDITOR
                if (DataTableModule.IsFileSystemMode)
                {
                    for (var j = 0; j < TabFilePaths.Length; j++)
                    {
                        var tabFilePath = TabFilePaths[j];
                        DataTableModule.WatchDataTable(tabFilePath, (path) =>
                        {
                            if (path.Replace("\\", "/").EndsWith(path))
                            {
                                _instance.ReloadAll();
                                //UnityEngine.Debug.Log("File Watcher! Reload success! -> " + path);
                            }
                        });
                    }
                }
    #endif
            }

            return(_instance);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Quick method to get TableFile from instance
 /// </summary>
 /// <param name="path"></param>
 /// <param name="useCache"></param>
 /// <returns></returns>
 public static TableFile Get(string path, bool useCache = true)
 {
     if (_instance == null)
     {
         _instance = new DataTableModule();
     }
     return(_instance.GetTableFile(path, useCache));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Do reload the dataTable file: Test
        /// </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 = DataTableModule.Get(tabFilePath, false);
                }
                else
                {
                    tableFile = TableFile.LoadFromString(customContent);
                }

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

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

            ReloadCount++;
            UnityEngine.Debug.LogFormat("Reload dataTables: {0}, Row Count: {1}, Reload Count: {2}", GetType(), Count, ReloadCount);
        }