Пример #1
0
        void CreateTile(TileInfo ti)
        {
            Vector2       latLonTL = ti.latlons [0];
            Vector2       latLonBR;
            ZoomLevelInfo zi       = zoomLevelsInfo [ti.zoomLevel];
            int           tileCode = GetTileHashCode(ti.x + 1, ti.y + 1, ti.zoomLevel);
            TileInfo      cachedTile;

            if (cachedTiles.TryGetValue(tileCode, out cachedTile))
            {
                latLonBR = cachedTile.latlons [0];
            }
            else
            {
                latLonBR = Conversion.GetLatLonFromTile(ti.x + 1, ti.y + 1, ti.zoomLevel);
            }
            // Create container
            GameObject parentObj;

            if (ti.parent == null)
            {
                parentObj = zi.tilesContainer;
                if (parentObj == null)
                {
                    parentObj = new GameObject("Tiles" + ti.zoomLevel);
                    parentObj.transform.SetParent(tilesRoot, false);
                    parentObj.layer   = tilesRoot.gameObject.layer;
                    zi.tilesContainer = parentObj;
                }
            }
            else
            {
                parentObj = ti.parent.gameObject;
            }

            // Prepare mesh vertices
            Vector3[] tileCorners = new Vector3[4];
            tileCorners [0] = Conversion.GetLocalPositionFromLatLon(latLonTL);
            tileCorners [1] = Conversion.GetLocalPositionFromLatLon(new Vector2(latLonTL.x, latLonBR.y));
            tileCorners [2] = Conversion.GetLocalPositionFromLatLon(latLonBR);
            tileCorners [3] = Conversion.GetLocalPositionFromLatLon(new Vector2(latLonBR.x, latLonTL.y));
            // Add small offset to avoid seams on higher zoom levels
            if (ti.zoomLevel > 150)
            {
                const float offset = 0.00000001f;
                tileCorners [1].x += offset;
                tileCorners [2].x += offset;
                tileCorners [2].y -= offset;
                tileCorners [3].y -= offset;
            }

            // Setup tile materials
            TileInfo parent = ti.parent != null ? ti.parent : ti;

            if (parent.normalMat == null)
            {
                parent.normalMat = Instantiate(tileMatRef);
                if (disposalManager != null)
                {
                    disposalManager.MarkForDisposal(parent.normalMat);
                }
            }
            if (parent.transMat == null)
            {
                parent.transMat = Instantiate(tileMatTransRef);
                if (disposalManager != null)
                {
                    disposalManager.MarkForDisposal(parent.transMat);
                }
            }

            Material tileMat = ti.zoomLevel < TILE_MIN_ZOOM_LEVEL ? parent.normalMat : parent.transMat;

            // UVs wrt Earth texture
            Vector2 tl = new Vector2((latLonTL.y + 180) / 360f, (latLonTL.x + 90) / 180f);
            Vector2 br = new Vector2((latLonBR.y + 180) / 360f, (latLonBR.x + 90) / 180f);

            if (tl.x > 0.5f && br.x < 0.5f)
            {
                br.x = 1f;
            }
            ti.worldTextureCoords = new Vector4(tl.x, br.y, br.x, tl.y);
            ti.ClearPlaceholderImage();

            if (ti.zoomLevel < TILE_MIN_ZOOM_LEVEL)
            {
                ti.loadStatus = TILE_LOAD_STATUS.Loaded;
            }

            ti.texture          = currentEarthTexture;
            ti.renderer         = CreateObject(parentObj.transform, "Tile", tileCorners, tileIndices, tileUV, tileMat, ti.subquadIndex);
            ti.gameObject       = ti.renderer.gameObject;
            ti.renderer.enabled = false;
            ti.created          = true;

#if DEBUG_TILES
            ti.gameObject.AddComponent <TileInfoEx> ();
#endif
        }
Пример #2
0
        void MonitorInactiveTiles()
        {
            int  inactiveCount  = inactiveTiles.Count;
            bool changes        = false;
            bool releasedMemory = false;

            for (int k = 0; k < inactiveCount; k++)
            {
                TileInfo ti = inactiveTiles [k];
                if (ti == null || ti.gameObject == null || ti.visible || ti.texture == currentEarthTexture || ti.loadStatus != TILE_LOAD_STATUS.Loaded)
                {
                    inactiveTiles [k]    = null;
                    ti.isAddedToInactive = false;
                    changes = true;
                    continue;
                }
                if (Time.time - ti.inactiveTime > _tileKeepAlive)
                {
                    inactiveTiles [k]    = null;
                    ti.isAddedToInactive = false;
                    ti.loadStatus        = TILE_LOAD_STATUS.Inactive;
                    // tile is now invisible, setup material for when it appears again:
                    ti.ClearPlaceholderImage();
                    if (ti.source != TILE_SOURCE.Resources)
                    {
                        Destroy(ti.texture);
                    }
                    ti.texture = currentEarthTexture;
                    // Reset parentcoords on children
                    if (ti.children != null)
                    {
                        int cCount = ti.children.Count;
                        for (int c = 0; c < cCount; c++)
                        {
                            TileInfo tiChild = ti.children [c];
                            if (!tiChild.animationFinished)
                            {
                                tiChild.ClearPlaceholderImage();
                            }
                        }
                    }
                    changes        = true;
                    releasedMemory = true;
                }
            }
            if (changes)
            {
                List <TileInfo> newInactiveList = new List <TileInfo> ();
                for (int k = 0; k < inactiveCount; k++)
                {
                    if (inactiveTiles [k] != null)
                    {
                        newInactiveList.Add(inactiveTiles [k]);
                    }
                }
                inactiveTiles.Clear();
                inactiveTiles = newInactiveList;
                if (releasedMemory)
                {
                    Resources.UnloadUnusedAssets();
                    GC.Collect();
                }
            }
        }