Table of Contents

Class TileCachePlatformDefaults

Picks the disk tile cache size for the machine the app is running on.

public static class TileCachePlatformDefaults
Inheritance
object
TileCachePlatformDefaults

Remarks

This lives in Runtime rather than Core for one reason: choosing needs UnityEngine.RuntimePlatform and a look at the free disk, and Core is pure C# with no UnityEngine reference. Core owns the sizes (TileCacheSettings); this owns the choice.

Why the default is not one flat number any more: developers ship defaults, so the default is what end users get. A desktop disk makes 10 GB of map cache a non-ask. A phone does not, and a phone that is nearly full cannot even afford the phone number, which is why free space is part of the sum rather than a separate warning nobody reads.

Anyone who wants a fixed size sets it in one line and none of this runs: ScreenMapView.DiskCacheSizeMode = Manual plus DiskCacheMB, or new TileCacheSettings(bytes) straight into the TileStreamer constructor.

Fields

DesktopCeilingBytes

Most a desktop default will ever take. Read from DesktopLarge so the 10 GB figure has one definition rather than a named preset nothing reads and a constant here that everything reads.

public static readonly long DesktopCeilingBytes

Field Value

long

DesktopFreeShare

Share of the free disk a desktop default will take.

public const double DesktopFreeShare = 0.1

Field Value

double

FloorBytes

Floor under the free-disk share. A 64 MB cache is small but still holds a few thousand wire-format tiles, and a device this full has worse problems than map caching.

public const long FloorBytes = 67108864

Field Value

long

MobileCeilingBytes

Most a mobile default will ever take.

public const long MobileCeilingBytes = 2147483648

Field Value

long

MobileFreeShare

Share of the free disk a mobile default will take.

public const double MobileFreeShare = 0.05

Field Value

double

UnknownFreeDesktopBytes

Desktop size when the free disk cannot be read or the reading is not believable. Small on purpose: it is a fallback for not knowing, and 1 GB of cache costs at most 2 GB of disk under the waste allowance, which is defensible on any machine that runs a desktop player.

public const long UnknownFreeDesktopBytes = 1073741824

Field Value

long

Methods

CapBytes(bool, long)

The cap for a platform and a free-disk figure, in bytes.

public static long CapBytes(bool isDesktop, long freeDiskBytes)

Parameters

isDesktop bool

From IsDesktop(RuntimePlatform).

freeDiskBytes long

Free bytes on the volume holding the cache, or 0 when unknown.

Returns

long

Remarks

min(ceiling, share of free), then never below FloorBytes. Worked: a desktop with 40 GB free takes 4 GB, not 10; a 256 GB phone with 200 GB free takes the 2 GB ceiling; a phone with 3 GB free takes 153.6 MB; a phone with 500 MB free takes the 64 MB floor.

A 0 (unknown) free figure falls back to a flat number rather than to the floor, and the flat number is a small one on both sides: UnknownFreeDesktopBytes on desktop, and on mobile the 256 MB Default. An unknown reading cannot justify the largest allowance: that could spend 11 GB on a disk whose free space was never measured. Consumers with better information can select Manual.

Current(string)

Settings for the machine this is running on.

public static TileCacheSettings Current(string cacheDirectory)

Parameters

cacheDirectory string

Returns

TileCacheSettings

CurrentOverlay(string)

Overlay settings for the machine this is running on.

public static TileCacheSettings CurrentOverlay(string cacheDirectory)

Parameters

cacheDirectory string

Returns

TileCacheSettings

ForPlatform(bool, long)

Base-map settings for a platform and free-disk figure.

public static TileCacheSettings ForPlatform(bool isDesktop, long freeDiskBytes)

Parameters

isDesktop bool
freeDiskBytes long

Returns

TileCacheSettings

FreeDiskBytes(string)

Free bytes on the volume holding path, or 0 when the platform will not say.

public static long FreeDiskBytes(string path)

Parameters

path string

Returns

long

Remarks

Unity offers no free-space API of its own (enumerated, 6000.3.19f1: nothing on Application, SystemInfo or Caching reports free disk), so this is System.IO.DriveInfo. Documented to work on Windows, macOS and Linux, and tried on Windows here. On iOS and Android it is assumed unreliable - Mono's DriveInfo has historically reported the wrong volume or thrown on sandboxed paths - which is why the caller treats 0 as "unknown" and falls back to a flat number instead of trusting a small or zero reading.

A reading that is present but wrong is the case a try/catch cannot see, and it is the likelier one on a platform where the API is assumed unreliable: a wrong volume answers confidently. So the reading is checked against the same volume's total size before it is believed - see PlausibleFreeBytes(long, long).

IsDesktop(RuntimePlatform)

True for desktop players, desktop editors and dedicated servers.

public static bool IsDesktop(RuntimePlatform platform)

Parameters

platform RuntimePlatform

Returns

bool

Remarks

Enumerated against UnityEngine.RuntimePlatform in 6000.3.19f1; anything not named here (mobile, console, web, embedded) takes the mobile sizes, which is the safe side of a wrong guess.

OverlayForPlatform(bool, long)

Overlay settings: half the base cap, matching the 256/128 pair the inspector has always shipped. The overlay is a second tile set on the same disk, so it scales with the base rather than having its own rule.

public static TileCacheSettings OverlayForPlatform(bool isDesktop, long freeDiskBytes)

Parameters

isDesktop bool
freeDiskBytes long

Returns

TileCacheSettings

PlausibleFreeBytes(long, long)

A free-space reading, or 0 when it cannot be believed.

public static long PlausibleFreeBytes(long freeBytes, long totalBytes)

Parameters

freeBytes long
totalBytes long

Returns

long

Remarks

Free bytes above the volume's own size is not a small error, it is a reading about a different volume or a broken one, and it is the shape that does real damage: a 20 TB answer on a phone sizes the cache at the 2 GB ceiling on a device with nothing to spare. A total size that is itself absent or zero says the same thing more directly. Negative is impossible per the API contract and rejected anyway, because the whole point here is not trusting the contract.

Separated from FreeDiskBytes(string) so it can be tested with readings a real volume will not produce.