Created
August 8, 2014 15:17
-
-
Save gclsoft/65c22b63317bed02eff9 to your computer and use it in GitHub Desktop.
ExampleEventHandler.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Copyright (C) 2012-2014 Soomla Inc. | |
/// | |
/// Licensed under the Apache License, Version 2.0 (the "License"); | |
/// you may not use this file except in compliance with the License. | |
/// You may obtain a copy of the License at | |
/// | |
/// http://www.apache.org/licenses/LICENSE-2.0 | |
/// | |
/// Unless required by applicable law or agreed to in writing, software | |
/// distributed under the License is distributed on an "AS IS" BASIS, | |
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
/// See the License for the specific language governing permissions and | |
/// limitations under the License. | |
using System; | |
using System.Collections.Generic; | |
using UnityEngine; | |
namespace Soomla.Store.Example { | |
/// <summary> | |
/// This class contains functions that receive events that they are subscribed to. | |
/// </summary> | |
public class ExampleEventHandler// :MonoBehaviour | |
{ | |
public GeneralController general; | |
/// <summary> | |
/// Constructor. | |
/// Subscribes to potential events. | |
/// </summary> | |
public ExampleEventHandler () { | |
Debug.Log("###ExampleEventHandler! "); | |
StoreEvents.OnMarketPurchase += onMarketPurchase; | |
StoreEvents.OnMarketRefund += onMarketRefund; | |
StoreEvents.OnItemPurchased += onItemPurchased; | |
StoreEvents.OnGoodEquipped += onGoodEquipped; | |
StoreEvents.OnGoodUnEquipped += onGoodUnequipped; | |
StoreEvents.OnGoodUpgrade += onGoodUpgrade; | |
StoreEvents.OnBillingSupported += onBillingSupported; | |
StoreEvents.OnBillingNotSupported += onBillingNotSupported; | |
StoreEvents.OnMarketPurchaseStarted += onMarketPurchaseStarted; | |
StoreEvents.OnItemPurchaseStarted += onItemPurchaseStarted; | |
StoreEvents.OnUnexpectedErrorInStore += onUnexpectedErrorInStore; | |
StoreEvents.OnCurrencyBalanceChanged += onCurrencyBalanceChanged; | |
StoreEvents.OnGoodBalanceChanged += onGoodBalanceChanged; | |
StoreEvents.OnMarketPurchaseCancelled += onMarketPurchaseCancelled; | |
StoreEvents.OnRestoreTransactionsStarted += onRestoreTransactionsStarted; | |
StoreEvents.OnRestoreTransactionsFinished += onRestoreTransactionsFinished; | |
StoreEvents.OnSoomlaStoreInitialized += onSoomlaStoreInitialized; | |
#if UNITY_ANDROID && !UNITY_EDITOR | |
StoreEvents.OnIabServiceStarted += onIabServiceStarted; | |
StoreEvents.OnIabServiceStopped += onIabServiceStopped; | |
#endif | |
} | |
/// <summary> | |
/// Handles a market purchase event. | |
/// </summary> | |
/// <param name="pvi">Purchasable virtual item.</param> | |
/// <param name="purchaseToken">Purchase token.</param> | |
public void onMarketPurchase(PurchasableVirtualItem pvi, string purchaseToken, string payload) { | |
Debug.Log("###explameple Just purchased an item with itemId: " + pvi.ItemId); | |
if(pvi.ItemId==MuffinRushAssets.THOUSANDMUFF_PACK.ItemId) | |
{ | |
GameObject ob=GameObject.FindGameObjectsWithTag("Me")[0]; | |
general=(GeneralController)ob.GetComponent(typeof(GeneralController)); | |
general.useRMB *= 100; | |
GameObject gameObject=GameObject.Find("RightGeneral"); | |
foreach (Transform child in gameObject.transform) | |
{ | |
Debug.Log(child.gameObject.name); | |
child.renderer.material.color =Color.red; | |
} | |
} | |
} | |
/// <summary> | |
/// Handles a market refund event. | |
/// </summary> | |
/// <param name="pvi">Purchasable virtual item.</param> | |
public void onMarketRefund(PurchasableVirtualItem pvi) { | |
Debug.Log("###onMarketRefund" + pvi.ItemId); | |
} | |
/// <summary> | |
/// Handles an item purchase event. | |
/// </summary> | |
/// <param name="pvi">Purchasable virtual item.</param> | |
public void onItemPurchased(PurchasableVirtualItem pvi, string payload) { | |
Debug.Log("###onItemPurchased" + pvi.ItemId); | |
} | |
/// <summary> | |
/// Handles a good equipped event. | |
/// </summary> | |
/// <param name="good">Equippable virtual good.</param> | |
public void onGoodEquipped(EquippableVG good) { | |
Debug.Log("###onGoodEquipped" ); | |
} | |
/// <summary> | |
/// Handles a good unequipped event. | |
/// </summary> | |
/// <param name="good">Equippable virtual good.</param> | |
public void onGoodUnequipped(EquippableVG good) { | |
Debug.Log("###onGoodUnequipped" ); | |
} | |
/// <summary> | |
/// Handles a good upgraded event. | |
/// </summary> | |
/// <param name="good">Virtual good that is being upgraded.</param> | |
/// <param name="currentUpgrade">The current upgrade that the given virtual | |
/// good is being upgraded to.</param> | |
public void onGoodUpgrade(VirtualGood good, UpgradeVG currentUpgrade) { | |
Debug.Log("###onGoodUpgrade" ); | |
} | |
/// <summary> | |
/// Handles a billing supported event. | |
/// </summary> | |
public void onBillingSupported() { | |
Debug.Log("###onBillingSupported" ); | |
} | |
/// <summary> | |
/// Handles a billing NOT supported event. | |
/// </summary> | |
public void onBillingNotSupported() { | |
Debug.Log("###onBillingNotSupported" ); | |
} | |
/// <summary> | |
/// Handles a market purchase started event. | |
/// </summary> | |
/// <param name="pvi">Purchasable virtual item.</param> | |
public void onMarketPurchaseStarted(PurchasableVirtualItem pvi) { | |
Debug.Log("###onMarketPurchaseStarted" ); | |
} | |
/// <summary> | |
/// Handles an item purchase started event. | |
/// </summary> | |
/// <param name="pvi">Purchasable virtual item.</param> | |
public void onItemPurchaseStarted(PurchasableVirtualItem pvi) { | |
Debug.Log("###onItemPurchaseStarted" ); | |
} | |
/// <summary> | |
/// Handles an item purchase cancelled event. | |
/// </summary> | |
/// <param name="pvi">Purchasable virtual item.</param> | |
public void onMarketPurchaseCancelled(PurchasableVirtualItem pvi) { | |
Debug.Log("###onMarketPurchaseCancelled" ); | |
} | |
/// <summary> | |
/// Handles an unexpected error in store event. | |
/// </summary> | |
/// <param name="message">Error message.</param> | |
public void onUnexpectedErrorInStore(string message) { | |
Debug.Log("###onUnexpectedErrorInStore" ); | |
} | |
/// <summary> | |
/// Handles a currency balance changed event. | |
/// </summary> | |
/// <param name="virtualCurrency">Virtual currency whose balance has changed.</param> | |
/// <param name="balance">Balance of the given virtual currency.</param> | |
/// <param name="amountAdded">Amount added to the balance.</param> | |
public void onCurrencyBalanceChanged(VirtualCurrency virtualCurrency, int balance, int amountAdded) { | |
Debug.Log("###onCurrencyBalanceChanged" ); | |
ExampleLocalStoreInfo.UpdateBalances(); | |
} | |
/// <summary> | |
/// Handles a good balance changed event. | |
/// </summary> | |
/// <param name="good">Virtual good whose balance has changed.</param> | |
/// <param name="balance">Balance.</param> | |
/// <param name="amountAdded">Amount added.</param> | |
public void onGoodBalanceChanged(VirtualGood good, int balance, int amountAdded) { | |
Debug.Log("###onGoodBalanceChanged" ); | |
ExampleLocalStoreInfo.UpdateBalances(); | |
} | |
/// <summary> | |
/// Handles a restore Transactions process started event. | |
/// </summary> | |
public void onRestoreTransactionsStarted() { | |
Debug.Log("###onRestoreTransactionsStarted" ); | |
} | |
/// <summary> | |
/// Handles a restore transactions process finished event. | |
/// </summary> | |
/// <param name="success">If set to <c>true</c> success.</param> | |
public void onRestoreTransactionsFinished(bool success) { | |
Debug.Log("###onRestoreTransactionsFinished" ); | |
} | |
/// <summary> | |
/// Handles a store controller initialized event. | |
/// </summary> | |
public void onSoomlaStoreInitialized() { | |
Debug.Log("###onSoomlaStoreInitialized" ); | |
ExampleLocalStoreInfo.Init(); | |
// some usage examples for add/remove currency | |
// some examples | |
if (ExampleLocalStoreInfo.VirtualCurrencies.Count>0) { | |
try { | |
StoreInventory.GiveItem(ExampleLocalStoreInfo.VirtualCurrencies[0].ItemId,4000); | |
SoomlaUtils.LogDebug("SOOMLA ExampleEventHandler", "Currency balance:" | |
+ StoreInventory.GetItemBalance(ExampleLocalStoreInfo.VirtualCurrencies[0].ItemId)); | |
} catch (VirtualItemNotFoundException ex){ | |
SoomlaUtils.LogError("SOOMLA ExampleEventHandler", ex.Message); | |
} | |
} | |
// ExampleWindow.GetInstance().setupItemsTextures(); | |
} | |
#if UNITY_ANDROID && !UNITY_EDITOR | |
public void onIabServiceStarted() { | |
} | |
public void onIabServiceStopped() { | |
} | |
#endif | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment