public void LateUpdate()
        {
            TileCache.MarkAllUnused();

            _lateUpdate();

            RequestManager.ForEachQueuedDownload(DerateUnusedTilePriority);
            RequestManager.ForEachActiveDownload(DerateUnusedTilePriority);
            TileCache.ForEach(DerateUnusedTilePriority);

            int maxNewRequests = TileCache.HasMaxSize ? TileCache.MaxSize - TileCache.Count() : -1;

            RequestManager.Process(maxNewRequests);

            int processed = 0;

            while (processed < SceneOptions.MaximumTilesToProcessPerFrame && ProcessingQueue.Count != 0)
            {
                var tile = ProcessingQueue.Dequeue();
                if (tile.Process()) //bake colliders, load indices, etc...
                {
                    // We allow requests to terminate early if the (would be) tile goes out of view, so check if a tile
                    // is actually processed
                    processed++;
                }
            }

            //if there are queued requests with higher priority than existing tiles but the TileCache cache is too full
            //to allow them to load, unload a corresponding number of lowest-priority tiles
            int ejected = 0;

            if (maxNewRequests >= 0 && maxNewRequests < SceneOptions.MaxConcurrentRequests &&
                RequestManager.Count() > maxNewRequests)
            {
                var re = RequestManager.GetEnumerator();       //high priority (low value) first
                ejected = TileCache.MarkLowPriorityUnused(t => //low priority (high value) first
                                                          re.MoveNext() &&
                                                          t.FrameState.Priority > re.Current.FrameState.Priority,
                                                          SceneOptions.MaxConcurrentRequests - maxNewRequests);
            }

            if (ejected > 0 || (TileCache.TargetSize > 0 && TileCache.Count() > TileCache.TargetSize))
            {
                //this will trigger Resources.UnloadUnusedAssets() as needed
                TileCache.UnloadUnusedContent(ejected);
            }

            if (unloadAssetsPending)
            {
                if (lastUnloadAssets == null || lastUnloadAssets.isDone)
                {
                    unloadAssetsPending = false;
                    lastUnloadAssets    = Resources.UnloadUnusedAssets();
                }
            }

            UpdateStats();
        }
Exemple #2
0
 protected override void UpdateStats()
 {
     //this works but is very inefficient and drags down framerate significantly when many tilesets are loaded
     //foreach (var tileset in tilesets)
     //{
     //    tileset.UpdateStats();
     //}
     RequestManager.ForEachQueuedDownload(t => { t.Tileset.Statistics.RequestQueueLength++; });
     RequestManager.ForEachActiveDownload(t => { t.Tileset.Statistics.ActiveDownloads++; });
     foreach (var tile in ProcessingQueue)
     {
         tile.Tileset.Statistics.ProcessingQueueLength++;
     }
     TileCache.ForEach(t => {
         t.Tileset.Statistics.DownloadedTiles++;
         if (t.ContentState == Unity3DTileContentState.READY)
         {
             t.Tileset.Statistics.ReadyTiles++;
         }
     });
     Unity3DTilesetStatistics.MaxLoadedTiles = TileCache.MaxSize;
     Stats = Unity3DTilesetStatistics.Aggregate(tilesets.Select(t => t.Statistics).ToArray());
 }