unity googleplay随手记
googleplay设置




进入play console后可以发布应用
点击所有应用->创建应用(这部经常报错误码,多试几次就ok可能和vpn有关)

创建一个应用成功后,这个应用就会包含上面所有选项
先在应用版本中传包,
然后商品详情中填写游戏相关说明图片,
内容分级中填写分级调查问卷,
定价和分发范围中填写游戏付费类型
应用内商品填写内购商品信息,这里注意商品id要与后面代码中的的id一致,eg:
服务和API中有个key,这个key要填写到unity service in-purchase googlePlay需要的那个key的位置
付费测试说明
新建号应用后,查看应用版本,能看到可以上传4个版本,内部测试渠道,封闭测试渠道,开放式渠道,正式版渠道
每个里面都可以管理添加测试账号,添加了测试账号后,测试计费时会提示当前是测试版本不会真正收取费用相关的提示

unity配置
Services->
IN-APP PURCHASING 中设置好googleplay中得到的的keyid

代码
在商店启动前初始化这个类
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Purchasing; public class Purchaser : MonoBehaviour, IStoreListener
{
private static IStoreController m_StoreController; private static IExtensionProvider m_StoreExtensionProvider; public static string kProductIDSubscription = "subscription"; private static string kProductNameAppleSubscription = "com.unity3d.subscription.new"; private static string kProductNameGooglePlaySubscription = "com.unity3d.subscription.original"; public string[] kPurchaserIdList = {
"com.diffcolor.gaincoins1",
"com.diffcolor.gaincoins2",
"com.diffcolor.gaincoins3",
"com.diffcolor.gaincoins4",
}; private static Purchaser Ins; public static Purchaser GetIns ()
{
return Ins;
} void Awake ()
{
Ins = this;
} void Start ()
{
DontDestroyOnLoad (gameObject);
if (m_StoreController == null) {
Debug.Log ("[n]----Purchaser.Start Init");
InitializePurchasing ();
}
} #region init public void InitializePurchasing ()
{
if (IsInitialized ()) {
Debug.Log ("[n]----Purchaser.InitializePurchasing Already.Init");
return;
} Debug.Log ("[n]----Purchaser.InitializePurchasing Begain Init"); var builder = ConfigurationBuilder.Instance (StandardPurchasingModule.Instance ());
builder.AddProduct (kProductIDSubscription, ProductType.NonConsumable, new IDs () {
{ kProductNameAppleSubscription, AppleAppStore.Name },
{ kProductNameGooglePlaySubscription, GooglePlay.Name },
});
//初始化各分类内购 ID
for (int x = 0; x < kPurchaserIdList.Length - 1; x++) {
String purchaseID = kPurchaserIdList [x];
builder.AddProduct (purchaseID, ProductType.Consumable);
}
//初始化广告内购 ID
builder.AddProduct (kPurchaserIdList [kPurchaserIdList.Length - 1], ProductType.NonConsumable);
UnityPurchasing.Initialize (this, builder);
} private bool IsInitialized ()
{
//bool b = m_StoreController != null && m_StoreExtensionProvider != null;
bool b0 = m_StoreController != null;
bool b1 = m_StoreExtensionProvider != null;
bool b = b0 && b1;
Debug.Log ("[n]----Purchaser.IsInitialized b0:" + b0 + " b1:" + b1);
return b;
} public void OnInitialized (IStoreController controller, IExtensionProvider extensions)
{
Debug.Log ("[n]----Purchaser.OnInitialized init CB success ");
m_StoreController = controller;
m_StoreExtensionProvider = extensions;
} public void OnInitializeFailed (InitializationFailureReason error)
{
Debug.Log ("[ne]----Purchaser.OnInitializeFailed init CB faile errer:" + error); } #endregion #region buy public string getPrice (string id)
{
string tstr = null; Product product = m_StoreController.products.WithID (id); if (product != null && product.availableToPurchase) {
tstr = m_StoreController.products.WithID (id).metadata.localizedPriceString.ToString ();
}
Debug.Log ("[n]----Purchaser.getPrice id:" + id + " content:" + tstr);
return tstr;
} public void BuyConsumable (string id)
{
BuyProductID (id);
} void BuyProductID (string productId)
{
if (IsInitialized ()) {
Debug.Log ("[n]----Purchaser.BuyProductID productId:" + productId);
Product product = m_StoreController.products.WithID (productId);
if (product != null && product.availableToPurchase) {
Debug.Log ("[n]----Purchaser.BuyProductID 启动计费 productId:" + product.definition.id);
//Debug.Log(string.Format("Purchasing product asychronously: '{0}'", product.definition.id));
m_StoreController.InitiatePurchase (product);
} else {
if (product == null)
Debug.Log ("[ne]----Purchaser.BuyProductID product==null productId:" + productId);
if (!product.availableToPurchase)
Debug.Log ("[ne]----Purchaser.BuyProductID availableToPurchase==false productId:" + productId);
onPurchaseFailed ("Not Found product.");
}
} else {
Debug.Log ("[ne]----Purchaser.BuyProductID fail,Not Init productId:" + productId);
onPurchaseFailed ("Not initialized."); } } #endregion #region restore public void RestorePurchases ()
{ if (!IsInitialized ()) {
Debug.Log ("[n]----Purchaser.RestorePurchases fail,Not initialized");
return;
} if (Application.platform == RuntimePlatform.IPhonePlayer ||
Application.platform == RuntimePlatform.OSXPlayer) { Debug.Log ("[n]----Purchaser.RestorePurchases restoreStart!");
var apple = m_StoreExtensionProvider.GetExtension<IAppleExtensions> ();
apple.RestoreTransactions ((result) => {
if (result) {
Debug.Log ("[n]----Purchaser.RestorePurchases Success!");
GameManager.instance.onRestorePurchasesSuccess ();
} else {
Debug.Log ("[ne]----Purchaser.RestorePurchases Fail!");
GameManager.instance.onRestorePurchasesFailed ();
}
});
} else {
Debug.Log ("[ne]----Purchaser.RestorePurchases platform error current=" + Application.platform);
GameManager.instance.onRestorePurchasesFailed ();
}
} #endregion #region cb //success;
public PurchaseProcessingResult ProcessPurchase (PurchaseEventArgs args)
{ Product product = args.purchasedProduct;
Dictionary<string, object> parameters = new Dictionary<string, object> ();
//parameters[AppEventParameterName.ContentID] = product.definition.id; float price = (float)product.metadata.localizedPrice;
string currency = product.metadata.isoCurrencyCode; Debug.Log ("[n]----Purchaser.ProcessPurchase PayCB===>productID:"
+ product.definition.id +
" price:" + price
+ " currentcy:" + currency); if (String.Equals (args.purchasedProduct.definition.id, kPurchaserIdList [0], StringComparison.Ordinal)) {
GameManager.instance.purchansedCallback (450);
AnalyticsUtils.analyPurchase (1.99f, price, currency, product.definition.id, parameters);
} else if (String.Equals (args.purchasedProduct.definition.id, kPurchaserIdList [1], StringComparison.Ordinal)) {
GameManager.instance.purchansedCallback (2000);
AnalyticsUtils.analyPurchase (7.99f, price, currency, product.definition.id, parameters);
} else if (String.Equals (args.purchasedProduct.definition.id, kPurchaserIdList [2], StringComparison.Ordinal)) {
GameManager.instance.purchansedCallback (5600);
AnalyticsUtils.analyPurchase (20.99f, price, currency, product.definition.id, parameters);
} else if (String.Equals (args.purchasedProduct.definition.id, kPurchaserIdList [3], StringComparison.Ordinal)) {
GameManager.instance.purchansedCallback (15200);
AnalyticsUtils.analyPurchase (53.99f, price, currency, product.definition.id, parameters);
} else if (String.Equals (args.purchasedProduct.definition.id, kPurchaserIdList [4], StringComparison.Ordinal)) {
GameManager.instance.onPurchaseNoAdsSuccess ();
AnalyticsUtils.analyPurchase (2.99f, price, currency, product.definition.id, parameters);
} Debug.Log ("[n]----Purchaser.ProcessPurchase befor data report!!!"); //添加购买成功统计
Dictionary<string, object> dict = new Dictionary<string, object> ();
dict.Add ("Level", "Level_" + GameData.instance.cLevel);
dict.Add ("productId", product.definition.id);
AnalyticsUtils.analyticsEvent ("Purchase Success", dict); Debug.Log ("[n]----Purchaser.ProcessPurchase after data report!!!"); return PurchaseProcessingResult.Complete; } void onPurchaseFailed (string failureReason)
{
Debug.Log ("[ne]----Purchaser.onPurchaseFailed befor data report!!! errorMsg:" + failureReason); GameManager.instance.onPurchaseFailed ();
Dictionary<string, object> dict = new Dictionary<string, object> ();
dict.Add ("FailureReason", failureReason);
AnalyticsUtils.analyticsEvent ("Purchase Fail", dict); Debug.Log ("[ne]----Purchaser.onPurchaseFailed after data report!!!");
} #endregion #region unuse public void OnPurchaseFailed (Product product, PurchaseFailureReason failureReason)
{
Debug.Log (string.Format ("[ne]----OnPurchaseFailed: FAIL. Product: '{0}', PurchaseFailureReason: {1}", product.definition.storeSpecificId, failureReason));
onPurchaseFailed (string.Format ("Product: '{0}', FailureReason: {1}", product.definition.storeSpecificId, failureReason));
} #endregion
}
unity googleplay随手记的更多相关文章
- [Unity优化] Unity CPU性能优化
前段时间本人转战unity手游,由于作者(Chwen)之前参与端游开发,有些端游的经验可以直接移植到手游,比如项目框架架构.代码设计.部分性能分析,而对于移动终端而言,CPU.内存.显卡甚至电池等硬件 ...
- Unity随手记
过年11天假期,带娃带了7天,吃吃喝喝.也看了点书,<射雕英雄传>(书)看了一半,还有就是在看<unity官方案例精讲>这本. 随手记一些自觉有价值或者有意思的点. 1. 对脚 ...
- Unity自带IAP插件使用(googleplay)
https://blog.csdn.net/ar__ha/article/details/64439872 Unity Services里的Unity IAP对于IOS和GooglePlay的支付用这 ...
- Unity AssetBundle爬坑手记
这篇文章从AssetBundle的打包,使用,管理以及内存占用各个方面进行了比较全面的分析,对AssetBundle使用过程中的一些坑进行填补指引以及喷! AssetBundle是Unity推荐的 ...
- (转)Unity AssetBundle爬坑手记
转自:http://www.cnblogs.com/ybgame/p/3973177.html 这篇文章从AssetBundle的打包,使用,管理以及内存占用各个方面进行了比较全面的分析,对Asset ...
- HoloLens开发手记 - Unity之Tracking loss
当HoloLens设备不能识别到自己在世界中的位置时,应用就会发生tracking loss.默认情况下,Unity会暂停Update更新循环并显示一张闪屏图片给用户.当设备重新能追踪到位置时,闪屏图 ...
- HoloLens开发手记 - Unity之Recommended settings 推荐设置
Unity提供了大量的设置选项来满足全平台的配置,对于HoloLens,Unity可以通过切换一些特定的设置来启用HoloLens特定的行为. Holographic splash screen 闪屏 ...
- HoloLens开发手记 - Unity development overview 使用Unity开发概述
Unity Technical Preview for HoloLens最新发行版为:Beta 24,发布于 09/07/2016 开始使用Unity开发HoloLens应用之前,确保你已经安装好了必 ...
- HoloLens开发手记 - Unity之摄像头篇
当你穿戴好HoloLens后,你就会处在全息应用世界的中心.当你的项目开启了"Virtual Reality Support"选项并选中了"Windows Hologra ...
随机推荐
- clone对象的克隆
用一句简单的话来说就是浅拷贝,只是对指针的拷贝,拷贝后两个指针指向同一个内存空间,深拷贝不但对指针进行拷贝,而且对指针指向的内容进行拷贝,经深拷贝后的指针是指向两个不同地址的指针. 等多 http:/ ...
- OpenCV 视频监控(Video Surveilance)的算法体系
如前面说到的,OpenCV VS提供了6组算法的接口,分别是:前景检测.新目标检测.目标跟踪.轨迹生成.跟踪后处理.轨迹分析,除了轨迹生成用于轨迹数据的保存以外,其他5个部分都是标准的视频监控算法体系 ...
- SpringMVC—对Ajax的处理(含 JSON 类型)(2)
这里编写了一个通用的类型转换器: 用来转换形如: firstName=jack&lastName=lily&gender=1&foods=Steak&foods=Piz ...
- 问题:oracle CLOB类型;结果:oracle中Blob和Clob类型的区别
BLOB和CLOB都是大字段类型,BLOB是按二进制来存储的,而CLOB是可以直接存储文字的.其实两个是可以互换的的,或者可以直接用LOB字段代替这两个.但是为了更好的管理ORACLE数据库,通常像图 ...
- 监控和安全运维 1.4 nagios安装
1. Nagios 简介是一个开源软件,可以监控网络设备网络流量.Linux/windows主机状态,甚至可以监控打印机它可以运行在Linux上或windows上基于浏览器的web界面方便运维人员查看 ...
- LNMP 1.2 Nginx编译安装
Nginx官网是:nginx.org 下载稳定版本 cd /usr/local/src wget http://nginx.org/download/nginx-1.8.0.tar.gz tar zx ...
- LAMP 2.7 Apache通过rewrite限制某个目录
我们可以 allow 和 deny 去现在网站根目录下的某个子目录,当然这个 rewrite 也可以实现,配置如下: 创建一个目录和文件随便写些东西 mkdir /data/www/data/tmp ...
- Android Fragment用法详解(2)--动态添加Fragment
在上一篇文章<Android Fragment用法详解(1)--静态使用Fragment>我们讲解了Fragment的最简单的用法.这次我们来说一说Fragment复杂一丢丢的用法.在代码 ...
- .net 4 安装未成功,无意中的解决办法!
公司 电脑是chost的系统,由于使用时间过长,重装纯净版系统的话,代价太大,故网上寻求各种解决办法! 安装.net 4 总是失败,查看百度,各种: WIN7系统哈哈跟我的问题一样,我的刚才解决了:1 ...
- mysql 打印随机数
select rand(); 这样取出来的数据是类似这样的: 0.5389902438400223 要几位自己取几位: 取得方法类似 select substr(concat("000000 ...