Beispiel #1
0
    private bool FindLayer(string layerName, ref DataLayer layer, bool add = false)
    {
        if (dataLayers.HasLayer(layerName))
        {
            layer = dataLayers.GetLayer(layerName);
            if (layer != null)
            {
                return(true);
            }

            Debug.LogError("Data layer '" + layerName + "' is null");
        }
        else if (add && networkLayer != null)
        {
            var dataManager = ComponentManager.Instance.Get <DataManager>();
            layer = new DataLayer(dataManager, layerName, networkLayer.Color, networkLayer.Group);             //+ Don't use network Color
            layer.SetIsTemp(true);
            dataLayers.RebuildList(dataManager.groups);
            return(true);
        }

        ShowError(new MessageBuilder(BuildRequiredLayerMessage, layerName));
        ResetTool(true);
        return(false);
    }
Beispiel #2
0
    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();
    }