-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdsTest.gd
114 lines (81 loc) · 2.8 KB
/
AdsTest.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
extends Node
var rewarded_ad_uid: String = "ca-app-pub-3940256099942544/5224354917"
var psa: Object = null
var psa_opt: Dictionary = {
"USE_TEST_ADS": true, # this will force test uid,
# so uid provided in the load stage will be overwritten
}
var rewarded_ad_ready: bool = false
#var interstitial_ad_ready: bool = false
func _ready() -> void:
# Forward Consent
psa_opt["NON_PERSONALIZED_ADS"] = Globals.non_personalized_ads
# get and init SBBPlayServicesAds
if Engine.has_singleton("SBBPlayServicesAds"):
psa = Engine.get_singleton("SBBPlayServicesAds")
psa.init(get_instance_id(), psa_opt)
# print log in-game
func print_app(p_text: String) -> void:
$Log.newline()
$Log.add_text(p_text)
# Rewarded Ad States
func rewarded_ad_set_state(p_state: String):
match p_state:
"loading":
rewarded_ad_ready = false
$RewardedAdBtn.disabled = true
$RewardedAdBtn.text = "Loading..."
"ready":
rewarded_ad_ready = true
$RewardedAdBtn.disabled = false
$RewardedAdBtn.text = "Show Rewarded Ad"
"error", _:
rewarded_ad_ready = false
$RewardedAdBtn.disabled = false
$RewardedAdBtn.text = "Load Rewarded Ad"
# Signals
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
func _on_MenuBtn_pressed() -> void:
SceneManager.goto_scene_n("Menu")
func _on_RewardedAdBtn_pressed() -> void:
if psa:
if rewarded_ad_ready:
psa.showRewardedAd()
else:
psa.loadRewardedAd(rewarded_ad_uid)
rewarded_ad_set_state("loading")
func _on_InterstitialAdBtn_pressed() -> void:
pass # Replace with function body.
# Signals from the module
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
func _get_message(p_message: String) -> void:
print(p_message)
print_app(p_message)
# Init
#
func _on_initialization_complete() -> void:
print("_on_initialization_complete")
$RewardedAdBtn.disabled = false
#$InterstitialAdBtn.disabled = false
# Rewarded Ad Load
#
func _on_rewarded_ad_loaded() -> void:
print("_on_rewarded_ad_loaded")
rewarded_ad_set_state("ready")
func _on_rewarded_ad_failed_to_loaded(p_error_code: int) -> void:
print("_on_rewarded_ad_failed_to_loaded, errorCode: " + str(p_error_code))
rewarded_ad_set_state("error")
# Rewarded Ad Show
#
func _on_rewarded_ad_opened() -> void:
print("_on_rewarded_ad_opened")
func _on_rewarded_ad_closed() -> void:
print("_on_rewarded_ad_closed")
# now is when you want to load the next ad
psa.loadRewardedAd(rewarded_ad_uid)
rewarded_ad_set_state("loading")
func _on_user_earned_reward(p_currency: String, p_amount: int) -> void:
print("_on_user_earned_reward, currency: " + p_currency + ", amount: " + str(p_amount))
func _on_rewarded_ad_failed_to_show(p_error_code: int) -> void:
print("_on_rewarded_ad_failed_to_show, errorCode: " + str(p_error_code))
rewarded_ad_set_state("error")