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.
- Listed in Customization and screenshots
- Inherits or implements
MonoBehaviour
Constructors
| Member | What it is |
|---|---|
MainMenuShopItem() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
13 private and internal fields
| Member | What it is |
|---|---|
private Transform center | Where the preview items are placed. |
private TextRenderer costText | Text showing the price, or "Owned". |
private PickupDock depositDock | Dock the player puts currency in to pay. |
private Vector3 internalSize | Size of the box around center that a cosmetic set's items are scattered in at random. |
private Purchasable item | The Purchasable this slot sells, loaded in Setup. |
private uint itemHash | Hash of the shop item's SKU, used to look up the Purchasable. |
private TextRenderer itemName | Text showing the item's display name. |
private static Logger logger | NLog logger for this class. |
private float maxObjectSize | Largest size a preview item is scaled to. |
private TextFont numberFont | Font used for the price. |
private ShopItemDetailedForUser shopItem | Shop API data for the item, including price and whether the player owns it. |
private AltaEvent successfullPurchase | Event run after a successful purchase. |
private TextFont textFont | Font used for the "Owned" text. |
Events
| Member | What it is |
|---|---|
event Action<uint> ItemPurchased | Raised with the item's hash after a purchase goes through. |
Methods
| Member | What 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
| Member | What 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: