Ejemplo n.º 1
0
        private IEnumerator SpawnLineObjects(SewerLines sewerLines, TileChange tileChange, Vector3RD boundingBoxMinimum, Vector3RD boundingBoxMaximum, Tile tile, System.Action <TileChange> callback = null)
        {
            tile.gameObject.SetActive(isEnabled);
            SewerLines.Feature sewerLineFeature;
            for (int i = 0; i < sewerLines.features.Length; i++)
            {
                if ((i % maxSpawnsPerFrame) == 0)
                {
                    yield return(new WaitForEndOfFrame());
                }

                sewerLineFeature = sewerLines.features[i];

                sewerPipeSpawner.CreateSewerLine(
                    sewerLineFeature.geometry.unity_coordinates[0],
                    sewerLineFeature.geometry.unity_coordinates[1],
                    float.Parse(sewerLineFeature.properties.diameter),
                    tile.gameObject
                    );
            }

            //Lines are done spawing. Start loading and spawing the manholes.
            StartCoroutine(GetSewerManholesInBoundingBox(tileChange, boundingBoxMinimum, boundingBoxMaximum, tile, callback));

            yield return(null);
        }
Ejemplo n.º 2
0
        IEnumerator GetSewerLinesInBoundingBox()
        {
            string escapedUrl = sewerPipesWfsUrl;

            escapedUrl += UnityWebRequest.EscapeURL((boundingBoxMinimum.x - boundingBoxMargin).ToString(CultureInfo.InvariantCulture) + "," + (boundingBoxMinimum.y + boundingBoxMargin).ToString(CultureInfo.InvariantCulture) + "," + (boundingBoxMaximum.x + boundingBoxMargin).ToString(CultureInfo.InvariantCulture) + "," + (boundingBoxMaximum.y - boundingBoxMargin).ToString(CultureInfo.InvariantCulture));
            var sewerageRequest = UnityWebRequest.Get(escapedUrl);

            yield return(sewerageRequest.SendWebRequest());

            if (!sewerageRequest.isNetworkError && !sewerageRequest.isHttpError)
            {
                //Replace multidimensional arrays with strings. JsonUtility doesnt support it (yet)
                string dataString = sewerageRequest.downloadHandler.text.Replace("[[", "\"").Replace("]]", "\"");
                sewerLines = JsonUtility.FromJson <SewerLines>(dataString);

                for (int i = 0; i < sewerLines.features.Length; i++)
                {
                    //Smear out the heavy parsing over a few frames, to avoid spikes and memory issues in WebGL
                    if ((i % maxParsesPerFrame) == 0)
                    {
                        yield return(new WaitForEndOfFrame());
                    }

                    var       feature         = sewerLines.features[i];
                    Vector3[] pointCoordinate = SplitToCoordinatesArray(feature.geometry.coordinates, feature.properties.bob_beginpunt, feature.properties.bob_eindpunt);
                    feature.geometry.unity_coordinates = pointCoordinate;
                }

                yield return(new WaitForEndOfFrame());

                StartCoroutine(SpawnLineObjects());
            }
            //We have a new network now that can start to spawn. Clear the old objects.
            ClearNetwork();

            yield return(null);
        }