Base
#
Read more about the Base system in Hiro here.
In-App Purchases
#
You can use the IAPSystem
to manage in-app purchases.
Initialize the IAP system
#
The IAP system relies on the Economy System and an ILogger
, both must be passed in as dependencies via the constructor.
1
2
| var iapSystem = new IAPSystem(economySystem, Logger);
systems.Add(iapSystem);
|
Adding products
#
You can manually add products which are not defined in the Economy system. These product definitions could come from the Unity IAP definitions.
1
2
3
4
5
6
| var productDefinitions = new List<ProductDefinition>
{
new ProductDefinition("<productId>", ProductType.Consumable)
};
await iapSystem.AddProductsAsync(productDefinitions);
|
Purchasing a store item
#
You can purchase a store item defined in the Economy system.
1
2
3
4
5
| // Get a store item
var storeItem = economySystem.StoreItems.First();
var purchaseEventArgs = await iapSystem.BuyProductAsync(storeItem);
Debug.Log($"Receipt: {purchaseEventArgs.purchasedProduct.receipt}");
|
You can also purchase an item by product ID.
1
| var purchaseEventArgs = await iapSystem.BuyProductByIdAsync("<productId>");
|
Processing a purchase
#
You can process a purchase.
1
2
| var processingResult = iapSystem.ProcessPurchase(purchaseEventArgs);
Debug.Log($"Processing result: {processingResult}");
|
Restoring purchases
#
You can restore purchases.
1
| await iapSystem.RestorePurchasesAsync();
|
Getting localized product price
#
You can get the localized product price.
1
2
| var price = iapSystem.GetLocalizedProductPrice(storeItem);
Debug.Log($"{storeItem.Name} price: {price}");
|
You can also get a localized product price by product ID.
1
| var price = await iapSystem.GetLocalizedProductPriceById("<productId>");
|
App rating
#
You can use the InAppReviewSystem
to trigger a native app store review.
Initialize the review system
#
The in-app review system relies an ILogger
must be passed in as a dependency via the constructor.
1
2
| var inAppReviewSystem = new InAppReviewSystem(Logger);
systems.Add(inAppReviewSystem);
|
Trigerring a native app review
#
You can trigger a native app review.
1
| inAppReviewSystem.TriggerNativeInAppReview();
|
Email rating
#
You can also 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
| var score = 5;
var message = "I love this game!";
await nakamaSystem.RateAppAsync(score, message);
|
Push notifications
#
Initialize the local notifications system
#
The local notifications system takes an OperatingMode
as well as properties for determining if notifications should auto increment native badge number via the constructor.
1
2
3
4
| var operatingMode = LocalNotificationSystem.OperatingMode.QueueClearAndReschedule;
var autoBadging = true;
var localNotificationSystem = new LocalNotificationSystem(operatingMode, autoBadging);
systems.Add(localNotificationSystem);
|
Listing pending notifications
#
You can list pending notifications.
1
2
3
4
| foreach (var pendingNotification in localNotificationSystem.PendingNotifications)
{
Debug.Log($"{pendingNotification.Notification.Title} {pendingNotification.Notification.Body}");
}
|
Creating a notification
#
You can create a notification.
1
2
3
4
5
6
7
8
9
10
11
| var gameNotification = localNotificationSystem.CreateNotification();
gameNotification.Title = "Hello, World!";
gameNotification.Body = "This is a notification.";
gameNotification.SmallIcon = "<IconId>";
gameNotification.LargeIcon = "<LargeIconId>";
gameNotification.Data = new Dictionary<string, string>
{
{
"someKey", "someValue"
}
}.ToJson();
|
Scheduling a notification for delivery
#
You can schedule a notification for delivery.
1
2
| var pendingNotification = localNotificationSystem.ScheduleNotification(gameNotification);
Debug.Log($"{pendingNotification.Notification.Id} scheduled for delivery");
|
Cancelling a notification
#
You can cancel a notification.
1
2
3
4
| if (pendingNotification.Notification.Id.HasValue)
{
localNotificationSystem.CancelNotification(pendingNotification.Notification.Id.Value);
}
|
Cancelling all notifications
#
You can cancel all notifications.
1
| localNotificationSystem.CancelAllNotifications();
|
Dismissing a notification
#
You can dismiss a notification.
1
2
3
4
| if (gameNotification.Id.HasValue)
{
localNotificationSystem.DismissNotification(gameNotification.Id.Value);
}
|
Dismissing all notifications
#
You can dismiss all notifications.
1
| localNotificationSystem.DismissAllNotifications();
|
Getting last notification
#
You can get the last notification.
1
| var gameNotification = localNotificationSystem.GetLastNotification();
|
Pausing notifications
#
You can pause notifications.
1
| await localNotificationSystem.PauseAsync();
|
Resuming notifications
#
You can resume notifications.
1
| await localNotificationSystem.ResumeAsync();
|
Shutting down the notification system
#
You can shutdown the notification system.
1
| await localNotificationSystem.ShutdownAsync();
|