Skip to main content

Purchasable

A class in Root.Township, Alta.Customization.

Base asset for a shop item or cosmetic that can be owned, loaded through Addressables by its hash. With external cosmetics on, the catalog comes from Alta's DigitalOcean bundle store.

Constructors​

MemberWhat it is
Purchasable()Use ScriptableObject.CreateInstance instead of new; Unity loads the saved ones from assets.

Fields​

MemberWhat it is
static Dictionary<uint, Purchasable> LoadedPurchasablesEvery purchasable by hash, once LoadAllIntoRAM has run. Null before that.
protected string skuBacking field for Sku.
11 private and internal fields
MemberWhat it is
private const string AndroidTargetUrlAddress of Alta's Android cosmetics bundles. That host is gone.
private string displayNameBacking field for DisplayName.
private uint hashBacking field for Hash; Get sets it to the hash it was loaded by.
private static bool isCatalogLoadedTrue once CheckCatalogAsync has run.
private bool isFreeForDevsBacking field for IsFreeForDevs.
private bool isLockedBacking field for IsLocked.
private static DateTime lastCatalogRefreshWhen the catalog was last loaded or checked.
private const string LinuxTargetUrlAddress of Alta's Linux cosmetics bundles. That host is gone.
private static readonly Logger LoggerLogger for this class.
private uint overrideHashBacking field for OverrideHash.
private const string WindowsTargetUrlAddress of Alta's Windows cosmetics bundles. That host is gone.

Properties​

MemberWhat it is
string DisplayName { get; }Name shown to players.
uint Hash { get; }The item's hash, which other systems use as its id.
bool IsFreeForDevs { get; }Probably whether developers get the item without buying it.
bool IsLocked { get; }Whether the item starts locked.
uint OverrideHash { get; }Alternative hash set in the inspector.
string Sku { get; }The store SKU string. Its compressed hash is the lookup key.
1 private and internal property
MemberWhat it is
private static bool IsUsingAllInRAM { get; set; }True once LoadAllIntoRAM has loaded every purchasable, so Get reads LoadedPurchasables instead of loading.

Methods​

MemberWhat it is
static async Task CheckCatalogAsync()Loads the remote Addressables catalog once, if the build uses external cosmetics.
static async Task<T> Get<T>(AddressableSession session, string sku)Loads a purchasable by SKU or hash, from RAM if preloaded. Retries once after a catalog refresh, then logs an error.
static async Task<T> Get<T>(AddressableSession session, uint hash)Loads a purchasable by SKU or hash, from RAM if preloaded. Retries once after a catalog refresh, then logs an error.
static async Task LoadAllIntoRAM()Loads every purchasable listed in PurchasableMap into LoadedPurchasables, so later Get calls skip Addressables.
void SetDisplayName(string name)Sets the display name.
void SetHash(uint hash)Sets the hash.
void SetSku(string sku)Sets the SKU.
5 private and internal methods
MemberWhat it is
internal virtual string FormattedSku()The display name in lower case with spaces as dashes.
private static string GetTargetUrl()Picks the cosmetics bundle address for the current platform (Windows, Android or Linux).
private static async Task<bool> RefreshWasSuccessful()Checks for Addressables catalog updates and returns true if there were any.
private static async Task<bool> TryRefreshCatalog()With external cosmetics on, checks for catalog updates at most once a minute. Get retries after one.
private static bool WasLastRefreshedOverAMinuteAgo()True if the catalog was last checked more than a minute ago.

Used in​

Members of other types that take, return or hold a Purchasable: