add tile key selection for addressables builds

This commit is contained in:
2026-01-23 16:07:24 +01:00
parent bd1e6f4f4d
commit 04ef2c68cc
16 changed files with 1383 additions and 185 deletions

View File

@@ -89,8 +89,9 @@ public class GeoTileAddressablesLoader : MonoBehaviour
tiles.Clear();
foreach (var tile in manifest.tiles)
{
if (!string.IsNullOrWhiteSpace(tile.tileId))
tiles[tile.tileId] = tile;
var key = !string.IsNullOrWhiteSpace(tile.tileKey) ? tile.tileKey : tile.tileId;
if (!string.IsNullOrWhiteSpace(key))
tiles[key] = tile;
}
Log($"Manifest loaded. Tiles={tiles.Count} CatalogFile={manifest.catalogFile}");
@@ -149,69 +150,69 @@ public class GeoTileAddressablesLoader : MonoBehaviour
if (distance <= loadRadiusMeters)
{
EnqueueTileLoad(tile.tileId);
EnqueueTileLoad(kvp.Key);
}
else if (distance >= unloadRadiusMeters)
{
UnloadTile(tile.tileId);
UnloadTile(kvp.Key);
}
}
}
private void EnqueueTileLoad(string tileId)
private void EnqueueTileLoad(string tileKey)
{
if (loaded.ContainsKey(tileId) || loading.Contains(tileId) || queued.Contains(tileId))
if (loaded.ContainsKey(tileKey) || loading.Contains(tileKey) || queued.Contains(tileKey))
return;
loadQueue.Enqueue(tileId);
queued.Add(tileId);
loadQueue.Enqueue(tileKey);
queued.Add(tileKey);
}
private void ProcessQueue()
{
while (loading.Count < maxConcurrentLoads && loadQueue.Count > 0)
{
var tileId = loadQueue.Dequeue();
queued.Remove(tileId);
StartLoad(tileId);
var tileKey = loadQueue.Dequeue();
queued.Remove(tileKey);
StartLoad(tileKey);
}
}
private void StartLoad(string tileId)
private void StartLoad(string tileKey)
{
if (!tiles.TryGetValue(tileId, out var tile))
if (!tiles.TryGetValue(tileKey, out var tile))
return;
loading.Add(tileId);
Log($"Loading tile {tileId}...");
loading.Add(tileKey);
Log($"Loading tile {tileKey}...");
var handle = Addressables.InstantiateAsync(tileId, tilesParent);
var handle = Addressables.InstantiateAsync(tileKey, tilesParent);
handle.Completed += op =>
{
loading.Remove(tileId);
loading.Remove(tileKey);
if (op.Status != AsyncOperationStatus.Succeeded)
{
Debug.LogError($"[GeoTileAddressablesLoader] Load failed for {tileId}: {op.OperationException}");
Debug.LogError($"[GeoTileAddressablesLoader] Load failed for {tileKey}: {op.OperationException}");
return;
}
var instance = op.Result;
instance.name = tileId;
instance.name = tileKey;
instance.transform.position = new Vector3(tile.offsetX, tile.baseY, tile.offsetZ);
loaded[tileId] = instance;
Log($"Loaded tile {tileId}. LoadedCount={loaded.Count}");
loaded[tileKey] = instance;
Log($"Loaded tile {tileKey}. LoadedCount={loaded.Count}");
};
}
private void UnloadTile(string tileId)
private void UnloadTile(string tileKey)
{
if (!loaded.TryGetValue(tileId, out var instance))
if (!loaded.TryGetValue(tileKey, out var instance))
return;
Addressables.ReleaseInstance(instance);
loaded.Remove(tileId);
Log($"Unloaded tile {tileId}. LoadedCount={loaded.Count}");
loaded.Remove(tileKey);
Log($"Unloaded tile {tileKey}. LoadedCount={loaded.Count}");
}
private static string GetBuildTargetFolderName()
@@ -222,13 +223,13 @@ public class GeoTileAddressablesLoader : MonoBehaviour
return "Android";
case RuntimePlatform.WindowsPlayer:
case RuntimePlatform.WindowsEditor:
return "Windows";
return "StandaloneWindows64";
case RuntimePlatform.LinuxPlayer:
case RuntimePlatform.LinuxEditor:
return "Linux";
return "StandaloneLinux64";
case RuntimePlatform.OSXPlayer:
case RuntimePlatform.OSXEditor:
return "OSX";
return "StandaloneOSX";
default:
return "Android";
}