text 在Godot Engine的应用程序购买中:示例
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text 在Godot Engine的应用程序购买中:示例相关的知识,希望对你有一定的参考价值。
# Intent: interface to the GodotPayments module (remember to add the java path in the project settings android>modules )
"Intent.gd"
extends Node
# Interface for the GodotPayments module
# To use extend this script and save the result on the Global singleton 'Data'
const STATIC_RESPONSE_NONE = 0
const STATIC_RESPONSE_ALL = 1
const STATIC_RESPONSE_PURCHASED = 2
const STATIC_RESPONSE_CANCELED = 3
const STATIC_RESPONSE_REFUNDED = 4
const STATIC_RESPONSE_ITEM_UNAVAILABLE = 5
var payments = null
var static_response = STATIC_RESPONSE_PURCHASED
# CALLBACKS: overwrite these
func do_intent():
pass
func purchase_success(receipt, signature, sku):
pass
func purchase_fail():
pass
func purchase_cancel():
pass
func purchase_owned(sku):
pass
func consume_success(receipt, signature, sku):
pass
func has_purchased(receipt, signature, sku):
pass
# PUBLICS
func _ready():
payments = Globals.get_singleton("GodotPayments")
func start_intent():
if payments != null:
payments.setPurchaseCallbackId(get_instance_ID())
do_intent()
func set_static_response(static_response_type):
static_response = static_response_type
func set_auto_consume(autoConsume):
if payments != null:
payments.setAutoConsume(autoConsume)
func request_purchased():
if payments != null:
payments.requestPurchased()
func consume_unconsumed_purchases():
if payments != null:
payments.consumeUnconsumedPurchases()
func purchase(item, payload = ""):
if payments != null:
payments.purchase(get_sku(item), payload)
func consume(item):
if payments != null:
payments.consume(item)
# PRIVATES: DO NOT OVERWRITE!
func get_sku(item):
if static_response == STATIC_RESPONSE_NONE:
return item
elif static_response == STATIC_RESPONSE_ALL:
var i = randi() % 4
if i == 0:
return "android.test.purchased"
elif i == 1:
return "android.test.canceled"
elif i == 2:
return "android.test.refunded"
elif i == 3:
return "android.test.item_unavailable"
elif static_response == STATIC_RESPONSE_PURCHASED:
return "android.test.purchased"
elif static_response == STATIC_RESPONSE_CANCELED:
return "android.test.canceled"
elif static_response == STATIC_RESPONSE_REFUNDED:
return "android.test.refunded"
elif static_response == STATIC_RESPONSE_ITEM_UNAVAILABLE:
return "android.test.item_unavailable"
# EXAMPLE 1: An intent to consume previous purchases on startup:
extends "Intent.gd"
func _ready():
start_intent()
func do_intent():
consume_unconsumed_purchases()
func consume_success(receipt, signature, sku):
print("consuming previous purchased: ", sku, ", receipt: ", receipt, ", signature: ", signature)
if sku == "power" or sku == "android.test.purchased":
var c = Globals.get("Data").get("power") + 1
Globals.get("Data").set("power", c)
Globals.get("Data").flush_database()
# EXAMPLE 2: Buy an item
func _on_buyButton_pressed():
if OS.get_name().findn("android") >= 0:
get_node("buyPower").start_intent()
# On node 'buyPower' (extends Intent.gd):
func buyPower():
purchase("power")
以上是关于text 在Godot Engine的应用程序购买中:示例的主要内容,如果未能解决你的问题,请参考以下文章
时隔 5 年,3 年匠心打造的 Godot Engine 4.0 都带来了哪些惊喜?
Godot Engine 4.0横空出世,Vulkan大怪兽加持,画质提升简直亮瞎眼
text Godot Quick Tips 01:用于等待X秒的create_timer()助手
如何将从谷歌域购买的网络域名连接到在谷歌 App Engine 上开发的网站?
Godot,为啥我的 android 导出找不到/打开文件?
Godot 4.0 设置应用程序图标项目图标