这个插件我还没用哈,不过提个建议。
包装一层 GodotUtils.gd
, 把 方法和信号名称调整为snake_case, 方法参数和返回值也带上类型,最后适当的注释。
毕竟从get_plugin()开始就没半点代码提示。
还有就是最好把安卓工厂也发到github上,tap sdk更新的时候如果维护不及时大家也可以自行更新插件。
下面是我之前接的口袋工厂,也是封一层 GDS,可以参考参考
## Android 专用
## 确认能运行的 Inter Reward Fullscreen
## 使用前先配置 ID, 并开启权限
extends Node
# 激励视频广告信号
signal reward_video_ad_failed(err_msg)# str
signal reward_video_ad_gotten()
signal reward_video_ad_closed()
signal reward_video_ad_successed()
signal reward_video_ad_loaded()
signal reward_video_ad_video_cached()
signal reward_video_ad_shown()
signal reward_video_ad_exposed()
signal reward_video_ad_clicked()
signal reward_video_ad_completed()
signal reward_video_ad_skipped()
# 静态插屏广告信号
signal inter_ad_failed(err_msg)# str
signal inter_ad_successed()
signal inter_ad_closed()
signal inter_ad_exposed()
signal inter_ad_clicked()
signal inter_ad_loaded()
# 全屏视屏广告信号
signal fullscreen_video_ad_failed(err_msg) # str
signal fullscreen_video_ad_successed()
signal fullscreen_video_ad_closed()
signal fullscreen_video_ad_loaded()
signal fullscreen_video_ad_cached()
signal fullscreen_video_ad_shown()
signal fullscreen_video_ad_exposed()
signal fullscreen_video_ad_clicked()
signal fullscreen_video_ad_completed()
signal fullscreen_video_ad_skipped()
signal fullscreen_video_ad_preloaded()
# 原生广告信号
signal native_ad_failed(err_msg) # str
signal native_ad_exposed()
signal native_ad_clicked()
signal native_ad_closed()
signal native_ad_loaded()
var PocketAD
#banner广告id 请修改掉默认的id(默认的只能测试)
# 开屏广告
var splash_ad_spot_id = "55281" setget config_splash_ad_spot_id
#静态插屏id
var inter_ad_spot_id = "6" setget config_inter_sceene_id
#激励id
var reward_video_ad_spot_id = "2" setget config_reward_ad_spot_id
#全屏广告id
var full_screen_video_ad_spot_id = "7" setget config_full_screen_ad_spot_id
##Banner广告id
#var banner_ad_spot_id = "3" setget config_banner_ad_spot_id
#原生广告id
var native_ad_spot_id = "16" setget config_native_ad_spot_id
func config_splash_ad_spot_id(_splash_ad_spot_id: int) -> void:
splash_ad_spot_id = str(_splash_ad_spot_id)
func config_reward_ad_spot_id(_reward_video_ad_spot_id: int) -> void:
reward_video_ad_spot_id = str(_reward_video_ad_spot_id)
func config_inter_sceene_id(_inter_ad_spot_id: int) -> void:
inter_ad_spot_id = str(_inter_ad_spot_id)
func config_full_screen_ad_spot_id(_full_screen_video_ad_spot_id: int) -> void:
full_screen_video_ad_spot_id = str(_full_screen_video_ad_spot_id)
#func config_banner_ad_spot_id(_banner_ad_spot_id: int) -> void:
# banner_ad_spot_id = str(_banner_ad_spot_id)
func config_native_ad_spot_id(_native_ad_spot_id: int) -> void:
native_ad_spot_id = str(_native_ad_spot_id)
# 获取插件链接信号
func _ready() -> void:
_get_plugin()
#============================================================
# 方法
#============================================================
# ========================= [ 静态插屏广告 ]
func init_inter_ad(id:= inter_ad_spot_id, show_download_popup:= true , show_after_loaded:= true) -> void:
if OS.has_feature("Android") and is_instance_valid(PocketAD):
PocketAD.initInterAd(id, show_download_popup, show_after_loaded)
func load_inter_ad(show_download_popup:= true , show_after_loaded:= true) -> void:
if OS.has_feature("Android") and is_instance_valid(PocketAD):
PocketAD.loadInterAd(show_download_popup, show_after_loaded)
func is_inter_ad_loaded() -> bool:
if OS.has_feature("Android") and is_instance_valid(PocketAD):
return PocketAD.isInterAdLoaded()
return false
func show_inter_ad() -> void:
if OS.has_feature("Android") and is_instance_valid(PocketAD):
PocketAD.showInterAd()
# ========================= [ 全屏视频广告 ]
func init_fullscreen_video_ad(id:= full_screen_video_ad_spot_id, show_download_popup:= true , show_after_loaded:= true) -> void:
if OS.has_feature("Android") and is_instance_valid(PocketAD):
PocketAD.initFullscreenVideoAd(id, show_download_popup, show_after_loaded)
func load_fullscreen_video_ad(show_download_popup:= true , show_after_loaded:= true) -> void:
if OS.has_feature("Android") and is_instance_valid(PocketAD):
PocketAD.loadFullscreenVideoAd(show_download_popup, show_after_loaded)
func is_fullscreen_video_ad_loaded() -> bool:
if OS.has_feature("Android") and is_instance_valid(PocketAD):
return PocketAD.isFullscreenVideoAdLoaded()
return false
func show_fullscreen_video_ad() -> void:
if OS.has_feature("Android") and is_instance_valid(PocketAD):
PocketAD.showFullscreenVideoAd()
# ========================= [ 激励视频广告 ]
func init_reward_video_ad(id:= reward_video_ad_spot_id, show_download_popup:= true , show_after_loaded:= true) -> void:
if OS.has_feature("Android") and is_instance_valid(PocketAD):
PocketAD.initRewardVideoAd(id, show_download_popup, show_after_loaded)
func load_reward_video_ad(show_download_popup:= true , show_after_loaded:= true) -> void:
if OS.has_feature("Android") and is_instance_valid(PocketAD):
PocketAD.loadRewardVideoAd(show_download_popup, show_after_loaded)
func is_reward_video_ad_loaded() -> bool:
if OS.has_feature("Android") and is_instance_valid(PocketAD):
return PocketAD.isRewardVideoAdLoaded()
return false
func show_reward_video_ad() -> void:
if OS.has_feature("Android") and is_instance_valid(PocketAD):
PocketAD.showRewardVideoAd()
# ========================= [ 原生广告 ]
func init_native_ad(id:= reward_video_ad_spot_id, show_download_popup:= true , show_after_loaded:= true) -> void:
if OS.has_feature("Android") and is_instance_valid(PocketAD):
PocketAD.initNativeAd(id, show_download_popup, show_after_loaded)
func load_native_ad(show_download_popup:= true , show_after_loaded:= true) -> void:
if OS.has_feature("Android") and is_instance_valid(PocketAD):
PocketAD.loadNativeAd(show_download_popup, show_after_loaded)
func is_native_ad_loaded() -> bool:
if OS.has_feature("Android") and is_instance_valid(PocketAD):
return PocketAD.isNativeAdLoaded()
return false
func show_native_ad() -> void:
if OS.has_feature("Android") and is_instance_valid(PocketAD):
PocketAD.showNativeAd()
#============================================================
# 内部方法
#============================================================
func _get_plugin():
if PocketAD == null and OS.has_feature("Android"):
assert(Engine.has_singleton("PocketPlugin"))
if Engine.has_singleton("PocketPlugin"):
PocketAD = Engine.get_singleton("PocketPlugin")
_connect_fullscreen_video_ad_signals(PocketAD)
_connect_inter_signals(PocketAD)
_connect_native_ad_signals(PocketAD)
_connect_reward_signals(PocketAD)
else:
if OS.is_debug_build():
OS.alert("不存在PocketPlugin")
func _on_RewardADFailed(err_msg: String) -> void: emit_signal("reward_video_ad_failed", err_msg)
func _connect_reward_signals(pp: Object) -> void:
pp.connect("RewardADFailed",self,"_on_RewardADFailed")
pp.connect("RewardADGotten",self,"emit_signal",["reward_video_ad_gotten"])
pp.connect("RewardADClosed",self,"emit_signal",["reward_video_ad_closed"])
pp.connect("RewardADSuccess",self,"emit_signal",["reward_video_ad_successed"])
pp.connect("RewardADLoaded",self,"emit_signal",["reward_video_ad_loaded"])
pp.connect("RewardADVideoCached",self,"emit_signal",["reward_video_ad_video_cached"])
pp.connect("RewardADShown",self,"emit_signal",["reward_video_ad_shown"])
pp.connect("RewardADExposed",self,"emit_signal",["reward_video_ad_exposed"])
pp.connect("RewardADClicked",self,"emit_signal",["reward_video_ad_clicked"])
pp.connect("RewardADCompleted",self,"emit_signal",["reward_video_ad_completed"])
pp.connect("RewardADSkipped",self,"emit_signal",["reward_video_ad_skipped"])
func _on_InterAdFailed(err_msg: String)->void: emit_signal("inter_ad_failed", err_msg)
func _connect_inter_signals(pp: Object) -> void:
pp.connect("InterAdFailed",self,"_on_InterAdFailed")
pp.connect("InterAdSuccess",self,"emit_signal",["inter_ad_successed"])
pp.connect("InterAdClosed",self,"emit_signal",["inter_ad_closed"])
pp.connect("InterAdExposed",self,"emit_signal",["inter_ad_exposed"])
pp.connect("InterAdClicked",self,"emit_signal",["inter_ad_clicked"])
pp.connect("InterAdLoaded",self,"emit_signal",["inter_ad_clicked"])
func _on_FullAdFailed(err_msg: String) -> void: emit_signal("fullscreen_video_ad_failed", err_msg)
func _connect_fullscreen_video_ad_signals(pp: Object) -> void:
pp.connect("FullAdFailed", self, "_on_FullAdFailed")
pp.connect("FullAdSuccess",self,"emit_signal",["fullscreen_video_ad_successed"])
pp.connect("FullAdClosed",self,"emit_signal",["fullscreen_video_ad_closed"])
pp.connect("FullAdLoaded",self,"emit_signal",["fullscreen_video_ad_loaded"])
pp.connect("FullAdVideoCached",self,"emit_signal",["fullscreen_video_ad_cached"])
pp.connect("FullAdShown",self,"emit_signal",["fullscreen_video_ad_shown"])
pp.connect("FullAdExposed",self,"emit_signal",["fullscreen_video_ad_exposed"])
pp.connect("FullAdClicked",self,"emit_signal",["fullscreen_video_ad_clicked"])
pp.connect("FullAdCompleted",self,"emit_signal",["fullscreen_video_ad_completed"])
pp.connect("FullAdSkipped",self,"emit_signal",["fullscreen_video_ad_skipped"])
pp.connect("FullAdPreloaded",self,"emit_signal",["fullscreen_video_ad_preloaded"])
func _on_NativeAdFailed(err_msg: String) -> void: emit_signal("native_ad_failed", err_msg)
func _connect_native_ad_signals(pp: Object) -> void:
pp.connect("NativeAdFailed", self, "_on_NativeAdFailed")
pp.connect("NativeAdLoaded",self,"emit_signal",["native_ad_loaded"])
pp.connect("NativeAdClosed",self,"emit_signal",["native_ad_closed"])
pp.connect("NativeAdClicked",self,"emit_signal",["native_ad_clicked"])
pp.connect("NativeAdExposed",self,"emit_signal",["native_ad_exposed"])