
#12 - Внутриигровые покупки через плагин Soomla
Для получения дохода от вашей игры её необходимо монетизировать. Это можно сделать за счёт рекламы или же внутриигровых покупок. В ходе урока вы научитесь добавлять покупки через плагин Soomla.
Видеоурок
Материалы для курса
Чтобы скачивать материалы к видеокурсам необходимо оформить подписку на сайт
Исходный код
Скрипт BuyGame
using System;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Soomla.Store.Example {
public class BuyGame : MonoBehaviour {
private float secTime = 1.0f, totTime = 0.0f;
private bool adsBought, add;
private static bool soomlaInitialized;
void Start () {
if (gameObject.name == "Restore Purchase")
StoreEvents.OnRestoreTransactionsFinished += onRestoreTransactionsFinished;
if (!soomlaInitialized)
SoomlaStore.Initialize(new BuyGogPlay());
if (PlayerPrefs.GetString ("NoAds") == "yes")
gameObject.SetActive (false);
soomlaInitialized = true;
}
void Update () {
if (gameObject.name != "Restore Purchase") {
if (Time.timeSinceLevelLoad > totTime) {
CheckIAP_PurchaseStatus ();
totTime = Time.timeSinceLevelLoad + secTime;
}
if (adsBought && !add) {
PlayerPrefs.SetString ("NoAds", "yes");
add = true;
}
}
}
public void onRestoreTransactionsFinished(bool success) {
// success - true if the restore transactions operation has succeeded
if (success)
adsBought = true;
}
void CheckIAP_PurchaseStatus () {
if (StoreInventory.GetItemBalance ("no_ads") >= 1)
adsBought = true;
}
void OnMouseUpAsButton () {
try {
if (gameObject.name != "Restore Purchase")
StoreInventory.BuyItem ("no_ads");
else
SoomlaStore.RestoreTransactions ();
}
catch (Exception e) {
Debug.Log ("SOOMLA/UNITY" + e.Message);
}
}
}
}
Скрипт BuyGogPlay
using UnityEngine;
using System.Collections;
namespace Soomla.Store.Example {
public class BuyGogPlay : IStoreAssets {
public int GetVersion() { // Get Current Version
return 0;
}
public VirtualCurrency[] GetCurrencies() {
return new VirtualCurrency[]{};
}
public VirtualGood[] GetGoods() {
return new VirtualGood[]{NO_ADS};
}
public VirtualCurrencyPack[] GetCurrencyPacks() {
return new VirtualCurrencyPack[]{};
}
public VirtualCategory[] GetCategories() {
return new VirtualCategory[]{};
}
public const string NO_ADS_PRODUCT_ID = "no_ads";
public static VirtualGood NO_ADS = new LifetimeVG(
"No more ads",
"No more ads forever",
"no_ads",
new PurchaseWithMarket(NO_ADS_PRODUCT_ID, 0.99));
}
}
Также стоит посмотреть
Комментарии