@@ -73,14 +73,7 @@ public virtual void Load(TileCover tileCover)
73
73
{
74
74
if ( unityMapTile . IsTemporary )
75
75
{
76
- var tileFinished = true ;
77
- foreach ( var module in LayerModules )
78
- {
79
- var moduleFinished = module . LoadInstant ( unityMapTile ) ;
80
- tileFinished &= moduleFinished ;
81
- if ( ! moduleFinished ) break ;
82
- }
83
- if ( tileFinished ) unityMapTile . IsTemporary = false ;
76
+ FinalizeTempTile ( unityMapTile ) ;
84
77
}
85
78
86
79
ShowTile ( unityMapTile ) ;
@@ -109,9 +102,10 @@ public virtual void Load(TileCover tileCover)
109
102
110
103
foreach ( var tileId in _toRemove )
111
104
{
112
- if ( ActiveTiles . ContainsKey ( tileId ) )
105
+ if ( ActiveTiles . TryGetValue ( tileId , out var tile ) )
113
106
{
114
- PoolTile ( ActiveTiles [ tileId ] ) ;
107
+ TileUnloading ( tile ) ;
108
+ PoolTile ( tile ) ;
115
109
}
116
110
else
117
111
{
@@ -125,6 +119,30 @@ public virtual void Load(TileCover tileCover)
125
119
}
126
120
}
127
121
122
+ /// <summary>
123
+ /// Minimal function that'll try to load view with whatever data is available.
124
+ /// It will not unload any tiles, it will not trigger any data fetching.
125
+ /// It'll only organize and use data already in memory.
126
+ /// If resources required for the requested tile aren't ready, it'll use whatever available
127
+ /// and create a "temporary tile".
128
+ /// </summary>
129
+ /// <param name="tileCover"></param>
130
+ public void LoadSnapshot ( TileCover tileCover )
131
+ {
132
+ foreach ( var tileId in tileCover . Tiles )
133
+ {
134
+ if ( CreateTileInstant ( tileId , out var unityMapTile ) )
135
+ {
136
+
137
+ }
138
+ else
139
+ {
140
+ CreateTempTile ( tileId , out unityMapTile ) ;
141
+ }
142
+ ShowTile ( unityMapTile ) ;
143
+ }
144
+ }
145
+
128
146
public void OnDestroy ( )
129
147
{
130
148
foreach ( var layerModule in LayerModules )
@@ -210,13 +228,9 @@ protected void PoolTile(UnityMapTile tile)
210
228
211
229
protected void CreateTempTile ( UnwrappedTileId tileId , out UnityMapTile tile )
212
230
{
213
- var rectd = Conversions . TileBoundsInUnitySpace ( tileId , _mapInformation . CenterMercator , _mapInformation . Scale ) ;
214
- tile = null ;
215
- tile = _tileCreator . GetTile ( ) ;
216
- tile . transform . position = new Vector3 ( ( float ) rectd . Center . x , 0 , ( float ) rectd . Center . y ) ;
217
- tile . transform . localScale = Vector3 . one * ( float ) rectd . Size . x ;
218
- tile . Initialize ( tileId , ( float ) rectd . Size . x * _mapInformation . Scale ) ;
219
-
231
+ //we need to do positioning and scaling before mesh gen for now
232
+ GetMapTile ( tileId , out tile ) ;
233
+
220
234
foreach ( var module in LayerModules )
221
235
{
222
236
module . LoadTempTile ( tile ) ;
@@ -227,31 +241,46 @@ protected void CreateTempTile(UnwrappedTileId tileId, out UnityMapTile tile)
227
241
}
228
242
229
243
protected bool CreateTileInstant ( UnwrappedTileId tileId , out UnityMapTile tile )
244
+ {
245
+ //we need to do positioning and scaling before mesh gen for now
246
+ GetMapTile ( tileId , out tile ) ;
247
+
248
+ var result = FinalizeTempTile ( tile ) ;
249
+
250
+ //couldn't create the tile
251
+ if ( ! result ) PoolTile ( tile ) ;
252
+
253
+ return result ;
254
+ }
255
+
256
+ protected void GetMapTile ( UnwrappedTileId tileId , out UnityMapTile tile )
230
257
{
231
258
var rectd = Conversions . TileBoundsInUnitySpace ( tileId , _mapInformation . CenterMercator , _mapInformation . Scale ) ;
232
259
tile = null ;
233
260
tile = _tileCreator . GetTile ( ) ;
234
261
tile . transform . position = new Vector3 ( ( float ) rectd . Center . x , 0 , ( float ) rectd . Center . y ) ;
235
262
tile . transform . localScale = Vector3 . one * ( float ) rectd . Size . x ;
236
- tile . Initialize ( tileId , ( float ) rectd . Size . x * _mapInformation . Scale ) ;
237
-
238
- var loaded = true ;
263
+ tile . Initialize ( tileId , ( float ) rectd . Size . x * _mapInformation . Scale ) ;
264
+ }
265
+
266
+ protected bool FinalizeTempTile ( UnityMapTile unityMapTile )
267
+ {
268
+ var tileFinished = true ;
239
269
foreach ( var module in LayerModules )
240
270
{
241
- var moduleFinished = module . LoadInstant ( tile ) ;
242
- loaded &= moduleFinished ;
271
+ var moduleFinished = module . LoadInstant ( unityMapTile ) ;
272
+ tileFinished &= moduleFinished ;
273
+ if ( ! moduleFinished ) break ;
243
274
}
244
275
245
- if ( ! loaded )
276
+ if ( tileFinished )
246
277
{
247
- PoolTile ( tile ) ;
248
- return false ;
278
+ unityMapTile . IsTemporary = false ;
279
+ ActiveTiles . TryAdd ( unityMapTile . UnwrappedTileId , unityMapTile ) ;
280
+ TileLoaded ( unityMapTile ) ;
249
281
}
250
-
251
- tile . IsTemporary = false ;
252
- ActiveTiles . Add ( tileId , tile ) ;
253
282
254
- return true ;
283
+ return tileFinished ;
255
284
}
256
285
257
286
protected void RepositionAllTiles ( IMapInformation mapInformation )
@@ -266,5 +295,8 @@ protected void RepositionAllTiles(IMapInformation mapInformation)
266
295
module . UpdatePositioning ( mapInformation ) ;
267
296
}
268
297
}
298
+
299
+ public event Action < UnityMapTile > TileLoaded = ( tile ) => { } ;
300
+ public event Action < UnityMapTile > TileUnloading = ( tile ) => { } ;
269
301
}
270
302
}
0 commit comments