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 ...
随机推荐
- net.sf.json.JSONObject 和org.json.JSONObject
参考 net.sf.json.JSONObject 和org.json.JSONObject 的差别
- 某个应用使cpu使用率100%
--CPU使用率 Linux是一个多任务的操作系统,将每个cpu的时间划分为很短的时间片,再通过调度器轮流分配给各个任务使用,因此造成多任务同时运行的错觉 为了维护cpu时间,linux通过事先定义的 ...
- [更新中]【South使用总结】django开发中使用South进行数据库迁移
Django开发中使用South进行数据库迁移的使用总结 South的详细资料可产看官方文档http://south.readthedocs.org/en/latest South安装配置 pip i ...
- Linux 正文处理命令及tar vi 编辑器 homework
作业一: 1) 将用户信息数据库文件和组信息数据库文件纵向合并为一个文件/1.txt(覆盖) cat /etc/passwd /etc/group >/1.txt 2) 将用户信息数据库文件和用 ...
- openGL一些概念01
顶点数据: 顶点数据是一系列顶点的集合. 一个顶点(Vertex)是一个3d坐标的数据的集合. 而顶点数据是用顶点属性(Vertex Attribute)表示的,它可以包含任何我们想用的数据. (但是 ...
- 安卓SQLite数据库操作(上)
安卓系统自带数据库,名为SQLite.这篇文章我们用一个Demo来讲解安卓操作数据库的例子. By the way, 安卓创建的数据库文件存放在/data/data/<包名>/databa ...
- Android中pull解析XML文件的简单使用
首先,android中解析XML文件有三种方式,dom,sax,pull 这里先讲pull,稍候会说SAX和DOM pull是一种事件驱动的xml解析方式,不需要解析整个文档,返回的值是数值型,是推荐 ...
- startactivityforresult使用
与startactivity基本相同,不过需要传入(intent,int)第二个int为请求ID,用来识别 在该activity中还应该重写nActivityResult(int requestCod ...
- 关于service和线程的区别
主要有两方面,访问控制和功能区别 首先,service是运行在主线程上的,并不是一个新的线程 其次,service在运行的时候可以被多个activity访问和控制,而线程是不可以的 最后,servic ...
- 关于TortoiseGit设置代理服务器会自动取消的问题解决方法
在前些日子,我使用TortoiseGit的并给其设置代理服务器的时候,每次设置好之后,关闭打开总是会自动取消勾选,通过不断的尝试和分析之后,得出了解决方案. 首先,这个配置项是保存在HOME环境变量对 ...