// // Unity Methods // private void Awake() { StartCoroutine(FileRequest.GetText(Paths.Data + "MapboxToken.txt", (sr) => { token = sr.ReadLine(); if (string.IsNullOrEmpty(token)) { Debug.LogWarning("Mapbox token is empty. Please paste your Mapbox token inside Data/MapboxToken.txt"); } FinishInit(); }, () => Debug.LogError("Couldn't find Mapbox Token"))); string backgroundsFile = Paths.Data + "backgrounds.csv"; StartCoroutine(FileRequest.GetText(backgroundsFile, (sr) => { backgrounds = Parse(sr); if (backgrounds.Count == 0) { CreateDefaultBackgrounds(backgroundsFile); } FinishInit(); }, () => { Debug.LogWarning("Couldn't find Mapbox backgrounds"); CreateDefaultBackgrounds(backgroundsFile); FinishInit(); })); }
// // Private Methods // private IEnumerator Init() { languageFilePath = Path.Combine(Paths.Data, LanguageFile); // Read config file (or create a default one) yield return(ReadConfigFile()); // Read list of available languages and translations yield return(FileRequest.GetText(languageFilePath, ReadLanguagesAndTranslations, OnLanguageFileDoesNotExist)); // Update UI UpdateAllTexts(); // Localization manager is finally ready Instance = this; OnReady?.Invoke(); }
public static IEnumerator Load(string filename, OnConfigLoadedCallbackDic callback) { yield return(FileRequest.GetText(filename, (sr) => callback(Parse(sr)))); }
public static IEnumerator LoadCsv(string filename, PatchDataLoadedCallback <GridData> callback) { yield return(FileRequest.GetText(filename, (sr) => callback(ParseCsv(sr, filename)))); }
private IEnumerator LoadTranslations() { localizedTexts.Clear(); yield return(FileRequest.GetText(languageFilePath, ReadTranslations)); }
private IEnumerator ReadConfigFile() { string configFile = Path.Combine(Paths.Data, ConfigFilename); yield return(FileRequest.GetText(configFile, ParseConfigFile, () => OnConfigFileDoesNotExist(configFile))); }
public static IEnumerator Load(string filename, UnityAction <MunicipalityData> callback, UnityAction errCallback) { yield return(FileRequest.GetText(filename, (sr) => callback(Parse(sr)), errCallback)); }
private IEnumerator InitLayers() { if (dataLayers == null) { CloseProgressDialog(); yield break; } #if !UNITY_WEBGL if (!Directory.Exists(Paths.Sites)) { Debug.LogError("Data path '" + Paths.Sites + "' doesn't exist. Trying to create it."); CloseProgressDialog(); Directory.CreateDirectory(Paths.Sites); yield break; } #endif #if UNITY_WEBGL // Show progress message progressDialog.SetMessage(Translator.Get("Downloading data") + "..."); progressDialog.SetProgress(0); yield return(PatchDataIO.StartReadingHeaders()); progressDialog.SetProgress(0.5f); yield return(null); var paths = new List <string>(); yield return(FileRequest.GetText(Paths.DataWebDBPatches, (tr) => { string line; while ((line = tr.ReadLine()) != null) { paths.Add(line); } })); #else // Find valid data directories var paths = GetDataDirectories(); #endif // Show progress message progressDialog.SetMessage(Translator.Get("Loading") + " ..."); progressDialog.SetProgress(0); yield return(null); // Count the layers int layerCount = 0; foreach (var group in groups) { foreach (var layer in group.layers) { layerCount++; } } // Rebuild the UI dataLayers.Show(false); // Create the patches/sites for each layer float index = 0; float time = 0; float invLayerCount = 1f / layerCount; var bounds = map.MapCoordBounds; foreach (var group in groups) { var groupController = dataLayers.AddLayerGroup(group.name); foreach (var layer in group.layers) { dataLayers.AddLayer(layer, groupController); List <string> patchFiles = null; var filesIt = layer.GetPatchFiles(paths, (pf) => patchFiles = pf); if (filesIt.MoveNext()) { do { yield return(null); } while (filesIt.MoveNext()); time = Time.realtimeSinceStartup + MaxProcessingTimePerFrame; } #if UNITY_EDITOR if (findUnusedLayers && patchFiles.Count == 0) { Debug.LogWarning("Layer " + layer.Name + " doesn't have any files."); } #endif if (patchFiles.Count > 0) { int patchCount = 0; float invPatchCount = 1f / patchFiles.Count; var patches = layer.CreatePatches(patchFiles); while (patches.MoveNext()) { patchCount++; progressDialog.SetProgress((index + (patchCount * invPatchCount)) * invLayerCount); if (patches.RunThruChildren()) { do { if (Time.realtimeSinceStartup > time) { yield return(null); time = Time.realtimeSinceStartup + MaxProcessingTimePerFrame; } }while (patches.RunThru()); } else if (Time.realtimeSinceStartup > time) { yield return(null); time = Time.realtimeSinceStartup + MaxProcessingTimePerFrame; } } } else if (Time.realtimeSinceStartup > time) { yield return(null); time = Time.realtimeSinceStartup + MaxProcessingTimePerFrame; } index++; } } PatchDataIO.StopParsingThread(); #if UNITY_EDITOR && !UNITY_WEBGL if (findUnusedPatches) { var extensions = new string[] { "*.csv", "*.bin" }; var dirs = GetDataDirectories(); foreach (var dir in dirs) { foreach (var ext in extensions) { var files = Directory.GetFiles(dir, ext); foreach (var file in files) { if (Path.GetFileName(file).StartsWith("_")) { continue; } var layerName = Patch.GetFileNameLayer(file); if (!dataLayers.HasLayer(layerName)) { Debug.LogWarning("Patch is being ignored: " + file); } } } } } #endif dataLayers.Show(true); yield return(null); // Update DataLayers UI (activate those layers that have sites/patches within view bounds) dataLayers.UpdateLayers(); // Hide Message CloseProgressDialog(); // Clean up #if UNITY_WEBGL PatchDataIO.FinishReadingHeaders(); #endif OnDataLoaded?.Invoke(); }
public static IEnumerator LoadCsv(string filename, PatchDataLoadedCallback <MultiGridData> callback) { yield return(FileRequest.GetText(filename, (sr) => PatchDataIO.ParseAsync(sr, filename, ParseCsv, callback))); }
private IEnumerator InitLayers() { if (dataLayers == null) { messageController.Show(false); yield break; } #if !UNITY_WEBGL if (!Directory.Exists(Paths.Sites)) { Debug.LogError("Data path '" + Paths.Sites + "' doesn't exist"); messageController.Show(false); yield break; } #endif // Show Message messageController.Show(true); messageController.SetProgress(0); #if UNITY_WEBGL messageController.SetMessage("Downloading database ..."); yield return(PatchDataIO.StartReadingHeaders()); messageController.SetProgress(0.5f); yield return(null); allPatchFiles.Clear(); yield return(FileRequest.GetText(Paths.DataWebDBPatches, (tr) => { string line; while ((line = tr.ReadLine()) != null) { allPatchFiles.Add(line); } })); #else // Find valid data directories InitValidDataDirs(); #endif messageController.SetMessage("Initializing database ..."); messageController.SetProgress(0); yield return(null); // Rebuild the UI int groupCount = 0; int layerCount = 0; dataLayers.Show(false); foreach (var group in groups) { var groupController = dataLayers.AddLayerGroup(group.name); foreach (var layer in group.layers) { dataLayers.AddLayer(layer, groupController); layer.BuildFileList(); layerCount++; } groupCount++; } dataLayers.Show(true); yield return(null); // Create the patches/sites for each layer float index = 0; int counter = 0; float invLayerCount = 1f / layerCount; var bounds = map.MapCoordBounds; foreach (var group in groups) { foreach (var layer in group.layers) { if (layer.PatchCount > 0) { int patchCount = 0; float invPatchCount = 1f / layer.PatchCount; var patches = layer.CreatePatches(); while (patches.MoveNext()) { patchCount++; messageController.SetProgress((index + (patchCount * invPatchCount)) * invLayerCount); while (patches.RunThruChildren()) { counter = 0; yield return(null); } if (++counter % 50 == 0) { yield return(null); } } } #if SAFETY_CHECK if (layers.ContainsKey(layer.name)) { Debug.LogError(layer.name + " layer already exists. Looks like a duplicate line in layers.csv"); } else #endif layers.Add(layer.name, layer); index++; } } CreateSitesList(); // Update DataLayers UI (activate those layers that have sites/patches within view bounds) dataLayers.UpdateLayers(); // Hide Message messageController.Show(false); // Clean up the cached files & directories #if UNITY_WEBGL PatchDataIO.FinishReadingHeaders(); allPatchFiles.Clear(); allPatchFiles = null; #else DataDirs = null; #endif if (OnDataLoaded != null) { OnDataLoaded(); } }
// // Private Methods // private IEnumerator Load(string filename) { yield return(FileRequest.GetText(filename, (sr) => Parse(sr))); }
private IEnumerator LoadSavedLocations() { string savedLocationsFile = Path.Combine(Paths.Data, SavedLocationsFile); yield return(FileRequest.GetText(savedLocationsFile, ParseSavedLocationsFile, () => OnSavedLocationsFileDoesNotExist(savedLocationsFile))); }
public static IEnumerator Load(string filename, UnityAction <List <MobilityMode> > callback, UnityAction errCallback) { yield return(FileRequest.GetText(filename, (sr) => callback(Parse(sr)), errCallback)); }
public static IEnumerator Load(string filename, UnityAction <API[]> callback) { yield return(FileRequest.GetText(filename, (stream) => callback(ParseAPIConfigFile(stream, filename)))); }