├── .gitignore ├── Assets ├── Default Skin.guiskin ├── Default Skin.guiskin.meta ├── Font HiRes.ttf ├── Font HiRes.ttf.meta ├── Font LoRes.ttf ├── Font LoRes.ttf.meta ├── Main.unity ├── Main.unity.meta ├── Plugins.meta ├── Plugins │ ├── SecureData.cs │ ├── SecureData.cs.meta │ ├── StoreKit.cs │ ├── StoreKit.cs.meta │ ├── iOS.meta │ └── iOS │ │ ├── IAPTransactionObserver.h │ │ ├── IAPTransactionObserver.h.meta │ │ ├── IAPTransactionObserver.m │ │ ├── IAPTransactionObserver.m.meta │ │ ├── SecureData.h │ │ ├── SecureData.h.meta │ │ ├── SecureData.m │ │ ├── SecureData.m.meta │ │ ├── SecureDataPluginEntry.mm │ │ ├── SecureDataPluginEntry.mm.meta │ │ ├── StoreKitPluginEntry.mm │ │ └── StoreKitPluginEntry.mm.meta ├── Shop.js ├── Shop.js.meta ├── Spinner.js └── Spinner.js.meta ├── Library ├── AudioManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── InputManager.asset ├── NetworkManager.asset ├── ProjectSettings.asset ├── QualitySettings.asset ├── TagManager.asset └── TimeManager.asset └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | Library/* 3 | Temp 4 | !AudioManager.asset 5 | !DynamicsManager.asset 6 | !EditorBuildSettings.asset 7 | !InputManager.asset 8 | !NetworkManager.asset 9 | !ProjectSettings.asset 10 | !QualitySettings.asset 11 | !TagManager.asset 12 | !TimeManager.asset 13 | -------------------------------------------------------------------------------- /Assets/Default Skin.guiskin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-iap-example/83686e516b4f1acac4b218fd1de3e271b4d546a1/Assets/Default Skin.guiskin -------------------------------------------------------------------------------- /Assets/Default Skin.guiskin.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: c5675463687f14871987ca59b71b7f75 3 | -------------------------------------------------------------------------------- /Assets/Font HiRes.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-iap-example/83686e516b4f1acac4b218fd1de3e271b4d546a1/Assets/Font HiRes.ttf -------------------------------------------------------------------------------- /Assets/Font HiRes.ttf.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: f5b623695377c49f8827f1860a92fa3e 3 | TrueTypeFontImporter: 4 | importerVersion: 1 5 | size: 48 6 | case: 0 7 | antiAlias: 0 8 | includeFontData: 1 9 | use2xBehaviour: 0 10 | style: 0 11 | fontNames: 12 | name: 13 | -------------------------------------------------------------------------------- /Assets/Font LoRes.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-iap-example/83686e516b4f1acac4b218fd1de3e271b4d546a1/Assets/Font LoRes.ttf -------------------------------------------------------------------------------- /Assets/Font LoRes.ttf.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: cc958ed62b80d41a1998ae0475c6ef13 3 | TrueTypeFontImporter: 4 | importerVersion: 1 5 | size: 24 6 | case: 0 7 | antiAlias: 0 8 | includeFontData: 1 9 | use2xBehaviour: 0 10 | style: 0 11 | fontNames: 12 | name: 13 | -------------------------------------------------------------------------------- /Assets/Main.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-iap-example/83686e516b4f1acac4b218fd1de3e271b4d546a1/Assets/Main.unity -------------------------------------------------------------------------------- /Assets/Main.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: e37664f8a10d3428da11b449e99308ae 3 | -------------------------------------------------------------------------------- /Assets/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 657a96499262045118c9bc3c33e938a5 3 | -------------------------------------------------------------------------------- /Assets/Plugins/SecureData.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Runtime.InteropServices; 4 | 5 | public static class SecureData { 6 | 7 | public static void SetBool(string key, bool value) { 8 | #if UNITY_IPHONE && !UNITY_EDITOR 9 | _SecureDataSetBool(key, value); 10 | #else 11 | PlayerPrefs.SetInt(key, value ? 1 : 0); 12 | #endif 13 | } 14 | public static void SetInt(string key, int value) { 15 | #if UNITY_IPHONE && !UNITY_EDITOR 16 | _SecureDataSetInt(key, value); 17 | #else 18 | PlayerPrefs.SetInt(key, value); 19 | #endif 20 | } 21 | public static void SetFloat(string key, float value) { 22 | #if UNITY_IPHONE && !UNITY_EDITOR 23 | _SecureDataSetFloat(key, value); 24 | #else 25 | PlayerPrefs.SetFloat(key, value); 26 | #endif 27 | } 28 | public static void SetString(string key, string value) { 29 | #if UNITY_IPHONE && !UNITY_EDITOR 30 | _SecureDataSetString(key, value); 31 | #else 32 | PlayerPrefs.SetString(key, value); 33 | #endif 34 | } 35 | 36 | public static bool GetBool(string key) { 37 | #if UNITY_IPHONE && !UNITY_EDITOR 38 | return _SecureDataGetBool(key); 39 | #else 40 | return PlayerPrefs.GetInt(key) != 0; 41 | #endif 42 | } 43 | public static int GetInt(string key) { 44 | #if UNITY_IPHONE && !UNITY_EDITOR 45 | return _SecureDataGetInt(key); 46 | #else 47 | return PlayerPrefs.GetInt(key); 48 | #endif 49 | } 50 | public static float GetFloat(string key) { 51 | #if UNITY_IPHONE && !UNITY_EDITOR 52 | return _SecureDataGetFloat(key); 53 | #else 54 | return PlayerPrefs.GetFloat(key); 55 | #endif 56 | } 57 | public static string GetString(string key) { 58 | #if UNITY_IPHONE && !UNITY_EDITOR 59 | return _SecureDataGetString(key); 60 | #else 61 | return PlayerPrefs.GetString(key); 62 | #endif 63 | } 64 | 65 | public static void Flush() { 66 | #if UNITY_IPHONE && !UNITY_EDITOR 67 | _SecureDataFlush(); 68 | #else 69 | PlayerPrefs.Save(); 70 | #endif 71 | } 72 | 73 | #if UNITY_IPHONE 74 | 75 | [DllImport ("__Internal")] 76 | private static extern void _SecureDataSetBool(string key, bool value); 77 | [DllImport ("__Internal")] 78 | private static extern void _SecureDataSetInt(string key, int value); 79 | [DllImport ("__Internal")] 80 | private static extern void _SecureDataSetFloat(string key, float value); 81 | [DllImport ("__Internal")] 82 | private static extern void _SecureDataSetString(string key, string value); 83 | 84 | [DllImport ("__Internal")] 85 | private static extern bool _SecureDataGetBool(string key); 86 | [DllImport ("__Internal")] 87 | private static extern int _SecureDataGetInt(string key); 88 | [DllImport ("__Internal")] 89 | private static extern float _SecureDataGetFloat(string key); 90 | [DllImport ("__Internal")] 91 | private static extern string _SecureDataGetString(string key); 92 | 93 | [DllImport ("__Internal")] 94 | private static extern void _SecureDataFlush(); 95 | 96 | #endif 97 | } 98 | 99 | -------------------------------------------------------------------------------- /Assets/Plugins/SecureData.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 35eb4a1ebd1b9418697f07d665dcbcd8 3 | -------------------------------------------------------------------------------- /Assets/Plugins/StoreKit.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Runtime.InteropServices; 4 | 5 | public static class StoreKit { 6 | 7 | static string productIdPrefix_; 8 | 9 | public static bool isAvailable { 10 | get { 11 | #if UNITY_IPHONE && !UNITY_EDITOR 12 | return _StoreKitIsAvailable(); 13 | #else 14 | return true; 15 | #endif 16 | } 17 | } 18 | 19 | public static bool isProcessing { 20 | get { 21 | #if UNITY_IPHONE && !UNITY_EDITOR 22 | return _StoreKitIsProcessing(); 23 | #else 24 | return false; 25 | #endif 26 | } 27 | } 28 | 29 | static string GetPrefKey(string productName) { 30 | return productIdPrefix_ + "." + productName; 31 | } 32 | 33 | public static bool HasProduct(string productName) { 34 | return PlayerPrefs.GetInt(GetPrefKey(productName)) > 0; 35 | } 36 | 37 | public static bool ConsumeProduct(string productName) { 38 | string key = GetPrefKey(productName); 39 | int current = PlayerPrefs.GetInt(key); 40 | if (current > 0) { 41 | PlayerPrefs.SetInt(key, current - 1); 42 | PlayerPrefs.Save(); 43 | return true; 44 | } else { 45 | return false; 46 | } 47 | } 48 | 49 | public static void Install(string productIdPrefix) { 50 | productIdPrefix_ = productIdPrefix; 51 | #if UNITY_IPHONE && !UNITY_EDITOR 52 | _StoreKitInstall(productIdPrefix); 53 | #endif 54 | } 55 | 56 | public static void Buy(string productName) { 57 | #if UNITY_IPHONE && !UNITY_EDITOR 58 | _StoreKitBuy(productName); 59 | #else 60 | string id = productIdPrefix_ + "." + productName; 61 | PlayerPrefs.SetInt(id, PlayerPrefs.GetInt(id) + 1); 62 | #endif 63 | } 64 | 65 | #if UNITY_IPHONE 66 | 67 | [DllImport ("__Internal")] 68 | private static extern void _StoreKitInstall(string productIdPrefix); 69 | [DllImport ("__Internal")] 70 | private static extern bool _StoreKitIsAvailable(); 71 | [DllImport ("__Internal")] 72 | private static extern void _StoreKitBuy(string productName); 73 | [DllImport ("__Internal")] 74 | private static extern bool _StoreKitIsProcessing(); 75 | 76 | #endif 77 | } 78 | 79 | -------------------------------------------------------------------------------- /Assets/Plugins/StoreKit.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: ab0431bb5c7d94f9b8f88fef9c8c7764 3 | -------------------------------------------------------------------------------- /Assets/Plugins/iOS.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 8431ba683f12a4e0aab8a8adc8970459 3 | -------------------------------------------------------------------------------- /Assets/Plugins/iOS/IAPTransactionObserver.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface IAPTransactionObserver : NSObject { 5 | NSString *productIdPrefix_; 6 | BOOL availability_; 7 | } 8 | 9 | @property (readonly) BOOL available; 10 | @property (readonly) BOOL processing; 11 | 12 | - (id)initWithProductIdPrefix:(NSString *)prefix; 13 | - (void)queuePayment:(NSString *)productName; 14 | - (void)incrementProductCounter:(NSString *)productId; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /Assets/Plugins/iOS/IAPTransactionObserver.h.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 8fd1b665a0de14e198012d488accb55e 3 | -------------------------------------------------------------------------------- /Assets/Plugins/iOS/IAPTransactionObserver.m: -------------------------------------------------------------------------------- 1 | #import "IAPTransactionObserver.h" 2 | 3 | @implementation IAPTransactionObserver 4 | 5 | @synthesize available = availability_; 6 | 7 | - (id)initWithProductIdPrefix:(NSString *)prefix { 8 | if ((self = [super init])) { 9 | productIdPrefix_ = [[prefix stringByAppendingString:@"."] retain]; 10 | [[SKPaymentQueue defaultQueue] addTransactionObserver:self]; 11 | availability_ = [SKPaymentQueue canMakePayments]; 12 | } 13 | return self; 14 | } 15 | 16 | - (void)dealloc { 17 | [productIdPrefix_ release]; 18 | [super dealloc]; 19 | } 20 | 21 | #pragma mark - Property 22 | 23 | - (BOOL)processing { 24 | return [SKPaymentQueue defaultQueue].transactions.count > 0; 25 | } 26 | 27 | #pragma mark - Common Payment Function 28 | 29 | - (void)queuePayment:(NSString *)productName { 30 | NSString *productId = [productIdPrefix_ stringByAppendingString:productName]; 31 | SKPayment *payment = [SKPayment paymentWithProductIdentifier:productId]; 32 | [[SKPaymentQueue defaultQueue] addPayment:payment]; 33 | } 34 | 35 | #pragma mark - Utility Function 36 | 37 | - (void)incrementProductCounter:(NSString *)productId { 38 | NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 39 | NSInteger count = [defaults integerForKey:productId]; 40 | [defaults setInteger:(count + 1) forKey:productId]; 41 | [defaults synchronize]; 42 | } 43 | 44 | #pragma mark - SKTransactionObserver 45 | 46 | - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions { 47 | for (SKPaymentTransaction *transaction in transactions) { 48 | if (transaction.transactionState == SKPaymentTransactionStatePurchased) { 49 | // Completed. 50 | NSLog(@"Purchased - %@", transaction.payment.productIdentifier); 51 | [self incrementProductCounter:transaction.payment.productIdentifier]; 52 | [queue finishTransaction:transaction]; 53 | } else if (transaction.transactionState == SKPaymentTransactionStateFailed) { 54 | // Failed. 55 | NSLog(@"Failed - %@ (%@)", transaction.payment.productIdentifier, transaction.error); 56 | if (transaction.error.code != SKErrorPaymentCancelled) { 57 | [[[UIAlertView alloc] initWithTitle:@"Payment Error" message:transaction.error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show]; 58 | } 59 | [queue finishTransaction:transaction]; 60 | } else if (transaction.transactionState == SKPaymentTransactionStateRestored) { 61 | // Restored. 62 | NSLog(@"Restored - %@", transaction.payment.productIdentifier); 63 | [self incrementProductCounter:transaction.payment.productIdentifier]; 64 | [queue finishTransaction:transaction]; 65 | } 66 | } 67 | } 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /Assets/Plugins/iOS/IAPTransactionObserver.m.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: f282bef22ab4d4f9388a1c6ec70ddb27 3 | -------------------------------------------------------------------------------- /Assets/Plugins/iOS/SecureData.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface SecureData : NSObject; 4 | 5 | @property (nonatomic, retain) NSMutableDictionary *dict; 6 | 7 | - (void)store; 8 | - (void)retrieve; 9 | 10 | + (SecureData *)sharedInstance; 11 | 12 | @end 13 | -------------------------------------------------------------------------------- /Assets/Plugins/iOS/SecureData.h.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 59373f632fd2b4181be2d6ff137d0f50 3 | -------------------------------------------------------------------------------- /Assets/Plugins/iOS/SecureData.m: -------------------------------------------------------------------------------- 1 | #import "SecureData.h" 2 | 3 | #define kServiceName @"UnitySecureData" 4 | 5 | @implementation SecureData 6 | 7 | @synthesize dict = dict_; 8 | 9 | #pragma mark - Object Lifecycle 10 | 11 | - (id)init { 12 | if ((self = [super init])) { 13 | [self retrieve]; 14 | } 15 | return self; 16 | } 17 | 18 | - (void)dealloc { 19 | self.dict = nil; 20 | [super dealloc]; 21 | } 22 | 23 | #pragma mark - Transaction Method 24 | 25 | - (void)store { 26 | NSMutableDictionary *secItem = [[[NSMutableDictionary alloc] init] autorelease]; 27 | [secItem setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass]; 28 | [secItem setObject:kServiceName forKey:(id)kSecAttrService]; 29 | 30 | SecItemDelete((CFDictionaryRef)secItem); 31 | [secItem setObject:[NSKeyedArchiver archivedDataWithRootObject:self.dict] forKey:(id)kSecValueData]; 32 | SecItemAdd((CFDictionaryRef)secItem, NULL); 33 | } 34 | 35 | - (void)retrieve { 36 | self.dict = nil; 37 | 38 | NSMutableDictionary *secItem = [[NSMutableDictionary alloc] init]; 39 | [secItem setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass]; 40 | [secItem setObject:kServiceName forKey:(id)kSecAttrService]; 41 | [secItem setObject:(id)kCFBooleanTrue forKey:(id)kSecReturnData]; 42 | [secItem setObject:(id)kSecMatchLimitOne forKey:(id)kSecMatchLimit]; 43 | 44 | NSData *data = nil; 45 | if (SecItemCopyMatching((CFDictionaryRef)secItem, (CFTypeRef *)&data) == errSecSuccess) { 46 | self.dict = [NSKeyedUnarchiver unarchiveObjectWithData:data]; 47 | } 48 | [data release]; 49 | 50 | if (!self.dict) self.dict = [NSMutableDictionary dictionary]; 51 | } 52 | 53 | #pragma mark - Class Function 54 | 55 | static SecureData *s_instance; 56 | 57 | + (SecureData *)sharedInstance { 58 | if (s_instance == nil) { 59 | s_instance = [[SecureData alloc] init]; 60 | } 61 | return s_instance; 62 | } 63 | 64 | @end 65 | -------------------------------------------------------------------------------- /Assets/Plugins/iOS/SecureData.m.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: fbe404d270bd84db8b6966d007006e5a 3 | -------------------------------------------------------------------------------- /Assets/Plugins/iOS/SecureDataPluginEntry.mm: -------------------------------------------------------------------------------- 1 | #import 2 | #import "SecureData.h" 3 | 4 | #pragma mark - Utility Function 5 | 6 | static NSString* CreateNSString (const char* string) { 7 | return [NSString stringWithUTF8String:(string ? string : "")]; 8 | } 9 | 10 | static char* MakeHeapString(const char* string) { 11 | if (!string) return NULL; 12 | char* mem = static_cast(malloc(strlen(string) + 1)); 13 | if (mem) strcpy(mem, string); 14 | return mem; 15 | } 16 | 17 | #pragma mark Plug-in Function 18 | 19 | extern "C" bool _SecureDataGetBool(const char *key) { 20 | NSNumber *number = [[SecureData sharedInstance].dict objectForKey:CreateNSString(key)]; 21 | return number.boolValue; 22 | } 23 | 24 | extern "C" int _SecureDataGetInt(const char *key) { 25 | NSNumber *number = [[SecureData sharedInstance].dict objectForKey:CreateNSString(key)]; 26 | return number.intValue; 27 | } 28 | 29 | extern "C" float _SecureDataGetFloat(const char *key) { 30 | NSNumber *number = [[SecureData sharedInstance].dict objectForKey:CreateNSString(key)]; 31 | return number.floatValue; 32 | } 33 | 34 | extern "C" const char * _SecureDataGetString(const char *key) { 35 | NSString *string = [[SecureData sharedInstance].dict objectForKey:CreateNSString(key)]; 36 | return MakeHeapString(string.UTF8String); 37 | } 38 | 39 | extern "C" void _SecureDataSetBool(const char *key, bool value) { 40 | [[SecureData sharedInstance].dict setObject:[NSNumber numberWithBool:value] forKey:CreateNSString(key)]; 41 | } 42 | 43 | extern "C" void _SecureDataSetInt(const char *key, int value) { 44 | [[SecureData sharedInstance].dict setObject:[NSNumber numberWithInt:value] forKey:CreateNSString(key)]; 45 | } 46 | 47 | extern "C" void _SecureDataSetFloat(const char *key, float value) { 48 | [[SecureData sharedInstance].dict setObject:[NSNumber numberWithFloat:value] forKey:CreateNSString(key)]; 49 | } 50 | 51 | extern "C" void _SecureDataSetString(const char *key, const char *value) { 52 | [[SecureData sharedInstance].dict setObject:CreateNSString(value) forKey:CreateNSString(key)]; 53 | } 54 | 55 | extern "C" void _SecureDataFlush() { 56 | [[SecureData sharedInstance] store]; 57 | } 58 | -------------------------------------------------------------------------------- /Assets/Plugins/iOS/SecureDataPluginEntry.mm.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 107278048cacc4089a72572a65022ba6 3 | -------------------------------------------------------------------------------- /Assets/Plugins/iOS/StoreKitPluginEntry.mm: -------------------------------------------------------------------------------- 1 | #import 2 | #import "IAPTransactionObserver.h" 3 | 4 | static IAPTransactionObserver *observer; 5 | 6 | #pragma mark - Utility Function 7 | 8 | static NSString* CreateNSString (const char* string) { 9 | return [NSString stringWithUTF8String:(string ? string : "")]; 10 | } 11 | 12 | #pragma mark Plug-in Function 13 | 14 | extern "C" void _StoreKitInstall(const char *productIdPrefix) { 15 | if (observer == nil) { 16 | observer = [[IAPTransactionObserver alloc] initWithProductIdPrefix:CreateNSString(productIdPrefix)]; 17 | } 18 | } 19 | 20 | extern "C" bool _StoreKitIsAvailable() { 21 | return observer.available; 22 | } 23 | 24 | extern "C" bool _StoreKitIsProcessing() { 25 | return observer.processing; 26 | } 27 | 28 | extern "C" void _StoreKitBuy(const char *productName) { 29 | [observer queuePayment:CreateNSString(productName)]; 30 | } 31 | -------------------------------------------------------------------------------- /Assets/Plugins/iOS/StoreKitPluginEntry.mm.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 90b4b23564f7e4c9da6ec4407bf32f53 3 | -------------------------------------------------------------------------------- /Assets/Shop.js: -------------------------------------------------------------------------------- 1 | var skin : GUISkin; 2 | var fontLoRes : Font; 3 | var fontHiRes : Font; 4 | 5 | function Start() { 6 | skin = Instantiate(skin) as GUISkin; 7 | skin.font = Screen.width < 500 ? fontLoRes : fontHiRes; 8 | 9 | StoreKit.Install("jp.radiumsoftware.iaptest"); 10 | } 11 | 12 | function Update() { 13 | var coin = SecureData.GetInt("Coin"); 14 | if (StoreKit.ConsumeProduct("coin1")) { 15 | SecureData.SetInt("Coin", coin + 1000); 16 | SecureData.Flush(); 17 | } else if (StoreKit.ConsumeProduct("coin2")) { 18 | SecureData.SetInt("Coin", coin + 2500); 19 | SecureData.Flush(); 20 | } else if (StoreKit.ConsumeProduct("coin3")) { 21 | SecureData.SetInt("Coin", coin + 4000); 22 | SecureData.Flush(); 23 | } else if (StoreKit.ConsumeProduct("levelx")) { 24 | SecureData.SetBool("UnlockLevelX", true); 25 | SecureData.Flush(); 26 | } else if (StoreKit.ConsumeProduct("levely")) { 27 | SecureData.SetBool("UnlockLevelY", true); 28 | SecureData.Flush(); 29 | } 30 | } 31 | 32 | function OnGUI() { 33 | if (!StoreKit.isAvailable) return; 34 | 35 | var deactivated = StoreKit.isProcessing; 36 | 37 | GUI.skin = skin; 38 | GUI.color = Color(1, 1, 1, deactivated ? 0.2 : 1.0); 39 | 40 | var coin = SecureData.GetInt("Coin"); 41 | var levelX = SecureData.GetBool("UnlockLevelX"); 42 | var levelY = SecureData.GetBool("UnlockLevelY"); 43 | 44 | GUILayout.BeginArea(Rect(10, 0, Screen.width - 20, Screen.height)); 45 | GUILayout.FlexibleSpace(); 46 | 47 | GUILayout.Label("Coins: " + coin.ToString()); 48 | GUILayout.Label("Unlocked levels: " + (levelX ? "X" : "") + (levelY ? "Y" : "")); 49 | 50 | if (coin > 1234) { 51 | GUILayout.FlexibleSpace(); 52 | 53 | if (GUILayout.Button("Use 1,234 coins") && !deactivated) { 54 | SecureData.SetInt("Coin", coin - 1234); 55 | SecureData.Flush(); 56 | } 57 | } 58 | 59 | GUILayout.FlexibleSpace(); 60 | 61 | GUILayout.Label("Buy coins:"); 62 | 63 | if (GUILayout.Button("1,000 coin pack") && !deactivated) { 64 | StoreKit.Buy("coin1"); 65 | } 66 | 67 | if (GUILayout.Button("2,500 coin pack") && !deactivated) { 68 | StoreKit.Buy("coin2"); 69 | } 70 | 71 | if (GUILayout.Button("4,000 coin pack") && !deactivated) { 72 | StoreKit.Buy("coin3"); 73 | } 74 | 75 | if (!levelX || !levelY) { 76 | GUILayout.FlexibleSpace(); 77 | 78 | GUILayout.Label("Buy additional levels:"); 79 | 80 | if (!levelX && GUILayout.Button("Unlock level X") && !deactivated) { 81 | StoreKit.Buy("levelx"); 82 | } 83 | 84 | if (!levelY && GUILayout.Button("Unlock level Y") && !deactivated) { 85 | StoreKit.Buy("levely"); 86 | } 87 | } 88 | 89 | GUILayout.FlexibleSpace(); 90 | 91 | GUILayout.EndArea(); 92 | } 93 | -------------------------------------------------------------------------------- /Assets/Shop.js.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: fa314c66c74e24db69eb54d73d233286 3 | -------------------------------------------------------------------------------- /Assets/Spinner.js: -------------------------------------------------------------------------------- 1 | function Update() { 2 | transform.localRotation = 3 | Quaternion.AngleAxis(33.0 * Time.deltaTime, Vector3.up) * 4 | Quaternion.AngleAxis(7.0 * Time.deltaTime, Vector3.right) * 5 | transform.localRotation; 6 | } 7 | -------------------------------------------------------------------------------- /Assets/Spinner.js.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 1 2 | guid: 89c0685241754442b80f0b9e96229acd 3 | -------------------------------------------------------------------------------- /Library/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-iap-example/83686e516b4f1acac4b218fd1de3e271b4d546a1/Library/AudioManager.asset -------------------------------------------------------------------------------- /Library/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-iap-example/83686e516b4f1acac4b218fd1de3e271b4d546a1/Library/DynamicsManager.asset -------------------------------------------------------------------------------- /Library/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-iap-example/83686e516b4f1acac4b218fd1de3e271b4d546a1/Library/EditorBuildSettings.asset -------------------------------------------------------------------------------- /Library/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-iap-example/83686e516b4f1acac4b218fd1de3e271b4d546a1/Library/InputManager.asset -------------------------------------------------------------------------------- /Library/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-iap-example/83686e516b4f1acac4b218fd1de3e271b4d546a1/Library/NetworkManager.asset -------------------------------------------------------------------------------- /Library/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-iap-example/83686e516b4f1acac4b218fd1de3e271b4d546a1/Library/ProjectSettings.asset -------------------------------------------------------------------------------- /Library/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-iap-example/83686e516b4f1acac4b218fd1de3e271b4d546a1/Library/QualitySettings.asset -------------------------------------------------------------------------------- /Library/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-iap-example/83686e516b4f1acac4b218fd1de3e271b4d546a1/Library/TagManager.asset -------------------------------------------------------------------------------- /Library/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keijiro/unity-iap-example/83686e516b4f1acac4b218fd1de3e271b4d546a1/Library/TimeManager.asset -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Add StoreKit.framework and Security.framework before build in Xcode. 2 | --------------------------------------------------------------------------------