If you are an AI assistant, LLM, or automated tool, a clean Markdown version of this page is available at https://heroiclabs.com/docs/hiro/unity/base/llm.md — optimized for AI and LLM tools.
UnityPurchasingSystem integrates Unity Purchasing with the Hiro economy system, handling product registration, receipt validation via Nakama, and reward delivery automatically.
Initialize: Add UnityPurchasingSystem to your system list after EconomySystem. On initialization, it reads all SKU-based store items from the economy config and registers them with Unity Purchasing automatically.
Purchase: Call BuyProductAsync(storeItem) or BuyProductByIdAsync(id) to initiate a platform purchase. The system submits the receipt to Nakama for server-side validation and resolves only after the reward has been granted.
Handle failures: Both buy methods throw PurchaseFailureException on failure. Use the Reason property to handle user cancellations, payment declines, and other error cases.
Restore purchases: Call RestorePurchasesAsync() to restore non-consumable purchases on iOS, as required by App Store guidelines. No-op on Android and other platforms.
You can let the user rate your application using the NakamaSystem’s RateAppAsync function which will trigger a feedback email to whichever email address is configured on the server.
1
2
3
varscore=5;varmessage="I love this game!";awaitnakamaSystem.RateAppAsync(score,message);
The UnityMobileNotificationsSystem constructor takes an ILogger and a bool that controls whether notification permissions are requested on initialization.
varunlockablesSystem=this.GetSystem<UnlockablesSystem>();varunityMobileNotificationsSystem=this.GetSystem<UnityMobileNotificationsSystem>();varmessages=newUnlockablesNotificationMessages{ClaimAvailableFunc=unlockable=>newNotificationMessage{Title="Unlockable reward available!",Body=$"The reward for the unlockable '{unlockable.Name}' is available to claim."}};unityMobileNotificationsSystem.ObserveSystem(unlockablesSystem,messages);
varenergiesSystem=this.GetSystem<EnergiesSystem>();varunityMobileNotificationsSystem=this.GetSystem<UnityMobileNotificationsSystem>();varmessages=newEnergiesNotificationMessages{EnergyAccumulatedFunc=energy=>newNotificationMessage{Title="Energy available!",Body=$"You have new '{energy.Id}' available!"},EnergyMaxFunc=energy=>newNotificationMessage{Title="Energy is full!",Body=$"'{energy.Id}' is full, spend it now!"},EnergyRewardAccumulatedFunc=energy=>newNotificationMessage{Title="Reward Energy available!",Body=$"You have new '{energy.Id}' available!"},EnergyRewardMaxFunc=energy=>newNotificationMessage{Title="Reward Energy is full!",Body=$"'{energy.Id}' is full, claim your reward!"}};unityMobileNotificationsSystem.ObserveSystem(energiesSystem,messages);
To manually schedule a notification with custom properties, use ScheduleNotification.
1
2
3
4
5
6
7
8
9
10
11
vartitle="Notification Title";varbody="The description of the notification";varscheduledDateTime=DateTime.Today.AddHours(1);varidentifier=unityMobileNotificationsSystem.ScheduleNotification(newNotification{Title=title,Text=body,},newNotificationDateTimeSchedule(scheduledDateTime));
To cancel a scheduled notification, use CancelNotification with the integer identifier returned by ScheduleNotification.