Skip to main content

MainMenuShopItem

A class in Root.Township, Alta.Customization.

Client: one item on the main menu shop shelf. Shows the item and its price from the shop API, and buys it when enough currency are put in its deposit dock.

Constructors​

MemberWhat it is
MainMenuShopItem()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

13 private and internal fields
MemberWhat it is
private Transform centerWhere the preview items are placed.
private TextRenderer costTextText showing the price, or "Owned".
private PickupDock depositDockDock the player puts currency in to pay.
private Vector3 internalSizeSize of the box around center that a cosmetic set's items are scattered in at random.
private Purchasable itemThe Purchasable this slot sells, loaded in Setup.
private uint itemHashHash of the shop item's SKU, used to look up the Purchasable.
private TextRenderer itemNameText showing the item's display name.
private static Logger loggerNLog logger for this class.
private float maxObjectSizeLargest size a preview item is scaled to.
private TextFont numberFontFont used for the price.
private ShopItemDetailedForUser shopItemShop API data for the item, including price and whether the player owns it.
private AltaEvent successfullPurchaseEvent run after a successful purchase.
private TextFont textFontFont used for the "Owned" text.

Events​

MemberWhat it is
event Action<uint> ItemPurchasedRaised with the item's hash after a purchase goes through.

Methods​

MemberWhat it is
async void AttemptToBuy()Buys the item through the shop API if it isn't owned and the dock holds enough currency, then takes the currency, marks it owned and raises ItemPurchased.
async void Setup(AddressableSession session, ShopItemDetailedForUser shopItem)Fills the slot from a shop item: loads its Purchasable, shows the name and price (or "Owned") and spawns its preview. Hides itself if the item isn't found.
2 private and internal methods
MemberWhat it is
private Transform AddItem(Purchasable item)Spawns a preview pickup of a cosmetic with colliders off and physics frozen, scaled to fit maxObjectSize. Returns null for non-cosmetics.
private void OnDrawGizmosSelected()Editor: draws the box that set items are scattered in.

Used in​

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