Exemple #1
0
    private void Update()
    {
        /// Deletes the terrain if the reference to player or tile desapears
        /// this fixes problemes in editor when recompiling the code
        if (player == null || tile == null)
        {
            destroy();
        }

        /// Check if the thread has finished his work
        if (loader != null)
        {
            if (loader.Update())
            {
                /// Here the thread have finished
                genHeight();
                downloaded = true;
                loader     = null;
            }
        }

        /// fullFixed    - all the fixes has been applied (this one is the first because
        ///                is the most restrictive and there is no need to process the
        ///                other comparasions)
        /// generated    - guarantee that all the data info from this terrain is fully
        ///                downloaded
        /// tile != null - fixes errors in editor when recompiling the code
        if (!fullFixed && downloaded && tile != null)
        {
            /// if X border is not fixed, fix it
            if (!borderXFixed)
            {
                Hashtable map           = player.getMap();
                string    topTerrainKey = UPlayer.genTerrainName(tile.x, tile.y - 1);
                if (map.ContainsKey(topTerrainKey))
                {
                    GameObject terrain = (GameObject)map[topTerrainKey];
                    if (terrain.GetComponent <UTerrain>().downloaded)
                    {
                        fixBorderX(terrain.GetComponent <Terrain>());
                        borderXFixed = true;
                    }
                }
            }

            /// if Y border is not fixed, fix it
            if (!borderYFixed)
            {
                Hashtable map             = player.getMap();
                string    rightTerrainKey = UPlayer.genTerrainName(tile.x + 1, tile.y);
                if (map.ContainsKey(rightTerrainKey))
                {
                    GameObject terrain = (GameObject)map[rightTerrainKey];
                    if (terrain.GetComponent <UTerrain>().downloaded)
                    {
                        fixBorderY(terrain.GetComponent <Terrain>());
                        borderYFixed = true;
                    }
                }
            }

            /// if the farest edge from (0,0) is not fixed, fix it
            if (!edgeFixed)
            {
                Hashtable map             = player.getMap();
                string    rightTerrainKey = UPlayer.genTerrainName(tile.x + 1, tile.y - 1);
                if (map.ContainsKey(rightTerrainKey))
                {
                    GameObject terrain = (GameObject)map[rightTerrainKey];
                    if (terrain.GetComponent <UTerrain>().downloaded)
                    {
                        fixEdge(terrain.GetComponent <Terrain>());
                        edgeFixed = true;
                    }
                }
            }

            if (borderXFixed && borderYFixed && edgeFixed)
            {
                GetComponent <TerrainCollider>().terrainData = GetComponent <Terrain>().terrainData;
                fullFixed = true;
                // TODO: throw a thread and save the height in disk.
            }
        }
    }
Exemple #2
0
 private void Start()
 {
     neighbors = new Terrain[4];
     loader    = new UTerrainLoader(tile);
     loader.Start();
 }