├── .github
└── ISSUE_TEMPLATE
│ └── bug_report.md
├── .gitignore
├── .idea
├── codeStyles
│ └── Project.xml
├── misc.xml
└── runConfigurations.xml
├── AdsExampleProject
├── .import
│ ├── icon.png-487276ed1e3a0c39cad0279d744ee560.md5
│ └── icon.png-487276ed1e3a0c39cad0279d744ee560.stex
├── AdExample.gd
├── MainScene.tscn
├── default_env.tres
├── export_presets.cfg
├── icon.png
├── icon.png.import
└── project.godot
├── Godot
└── UnityAdsGodot.gdap
├── README.md
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── unityadsgodot
├── .gitignore
├── build.gradle
├── consumer-rules.pro
├── proguard-rules.pro
└── src
└── main
├── AndroidManifest.xml
└── java
└── com
└── jandans
└── unityaddsgodot
└── UnityAdsInterface.java
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps to reproduce the behavior:
15 | 1. Go to '...'
16 | 2. Click on '....'
17 | 3. Scroll down to '....'
18 | 4. See error
19 |
20 | **Expected behavior**
21 | A clear and concise description of what you expected to happen.
22 |
23 | **Screenshots**
24 | If applicable, add screenshots to help explain your problem.
25 |
26 | **Logcat output**
27 | If applicable, add Logcat output to help troubleshoot your problem.
28 |
29 | **Versions:**
30 | - Godot version: [e.g. 3.2.0]
31 | - Unity ads version:
32 |
33 | **Smartphone (please complete the following information):**
34 | - Device: [e.g. Sony Xperia x1]
35 | - OS: [e.g. Android 11]
36 | - Version [e.g. 22]
37 |
38 | **Additional context**
39 | Add any other context about the problem here.
40 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 |
16 | # Built application files
17 | *.apk
18 | *.aar
19 | *.ap_
20 | *.aab
21 |
22 | # Files for the ART/Dalvik VM
23 | *.dex
24 |
25 | # Java class files
26 | *.class
27 |
28 | # Generated files
29 | bin/
30 | gen/
31 | out/
32 | # Uncomment the following line in case you need and you don't have the release build type files in your app
33 | # release/
34 |
35 | # Gradle files
36 | .gradle/
37 | build/
38 |
39 | # Local configuration file (sdk path, etc)
40 | local.properties
41 |
42 | # Proguard folder generated by Eclipse
43 | proguard/
44 |
45 | # Log Files
46 | *.log
47 |
48 | # Android Studio Navigation editor temp files
49 | .navigation/
50 |
51 | # Android Studio captures folder
52 | captures/
53 |
54 | # IntelliJ
55 | *.iml
56 | .idea/workspace.xml
57 | .idea/tasks.xml
58 | .idea/gradle.xml
59 | .idea/assetWizardSettings.xml
60 | .idea/dictionaries
61 | .idea/libraries
62 | # Android Studio 3 in .gitignore file.
63 | .idea/caches
64 | .idea/modules.xml
65 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you
66 | .idea/navEditor.xml
67 |
68 | # Keystore files
69 | # Uncomment the following lines if you do not want to check your keystore files in.
70 | *.jks
71 | *.keystore
72 |
73 | # External native build folder generated in Android Studio 2.2 and later
74 | .externalNativeBuild
75 | .cxx/
76 |
77 | # Google Services (e.g. APIs or Firebase)
78 | google-services.json
79 |
80 | # Freeline
81 | freeline.py
82 | freeline/
83 | freeline_project_description.json
84 |
85 | # fastlane
86 | fastlane/report.xml
87 | fastlane/Preview.html
88 | fastlane/screenshots
89 | fastlane/test_output
90 | fastlane/readme.md
91 |
92 | # Version control
93 | vcs.xml
94 |
95 | # lint
96 | lint/intermediates/
97 | lint/generated/
98 | lint/outputs/
99 | lint/tmp/
100 | lint/reports/
101 | AdsExampleProject/android
102 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | xmlns:android
14 |
15 | ^$
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | xmlns:.*
25 |
26 | ^$
27 |
28 |
29 | BY_NAME
30 |
31 |
32 |
33 |
34 |
35 |
36 | .*:id
37 |
38 | http://schemas.android.com/apk/res/android
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | .*:name
48 |
49 | http://schemas.android.com/apk/res/android
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | name
59 |
60 | ^$
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | style
70 |
71 | ^$
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | .*
81 |
82 | ^$
83 |
84 |
85 | BY_NAME
86 |
87 |
88 |
89 |
90 |
91 |
92 | .*
93 |
94 | http://schemas.android.com/apk/res/android
95 |
96 |
97 | ANDROID_ATTRIBUTE_ORDER
98 |
99 |
100 |
101 |
102 |
103 |
104 | .*
105 |
106 | .*
107 |
108 |
109 | BY_NAME
110 |
111 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/AdsExampleProject/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.md5:
--------------------------------------------------------------------------------
1 | source_md5="47313fa4c47a9963fddd764e1ec6e4a8"
2 | dest_md5="2ded9e7f9060e2b530aab678b135fc5b"
3 |
4 |
--------------------------------------------------------------------------------
/AdsExampleProject/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/j1and1/GodotUnityAdsInterface/d9a57e2a245263ea9633553d0a31ec2cb7a0eb69/AdsExampleProject/.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex
--------------------------------------------------------------------------------
/AdsExampleProject/AdExample.gd:
--------------------------------------------------------------------------------
1 | extends Node2D
2 |
3 | var addsEngine = null
4 |
5 | # Called when the node enters the scene tree for the first time.
6 | func _ready():
7 | if Engine.has_singleton("UnityAdsGodot"):
8 | addsEngine = Engine.get_singleton("UnityAdsGodot")
9 | addsEngine.connect("UnityAdsReady", self, "_on_adsReady")
10 | addsEngine.connect("UnityAdsFinish", self, "_on_adsFinished")
11 | addsEngine.connect("UnityAdsError", self, "_on_adsError")
12 | addsEngine.connect("UnityBannerLoaded", self, "_on_bannerLoaded")
13 | addsEngine.connect("UnityBannerError", self, "_on_bannerError")
14 | addsEngine.initialise("1687685", false) # project id and TestMode enabled
15 | else:
16 | print("Couldn't find HelloSignals singleton")
17 |
18 | func _on_adsReady():
19 | print("video adds should be ready.")
20 |
21 | func _on_adsFinished(placement, reason):
22 | print(reason)
23 | reason = int(reason)
24 | print(reason)
25 | if reason == 2:
26 | print("Completed")
27 | elif reason == 1:
28 | print("User skiped ad")
29 | else:
30 | print("Something went wrong")
31 |
32 | func _on_adsError(reasonString):
33 | print(reasonString)
34 |
35 | func _on_bannerLoaded():
36 | print("Banner loaded")
37 |
38 | func _on_bannerError(reasonString):
39 | print(reasonString)
40 |
41 | func _on_VideoAd_pressed():
42 | if addsEngine != null:
43 | addsEngine.loadAd("video")
44 | while !addsEngine.isReady("video"):
45 | pass # There should be another way to do this!
46 |
47 | addsEngine.show("video")
48 |
49 | func _on_RewardedVideo_pressed():
50 | if addsEngine != null:
51 | addsEngine.loadAd("rewardedVideo")
52 | while !addsEngine.isReady("rewardedVideo"):
53 | pass # There should be another way to do this!
54 |
55 | addsEngine.show("rewardedVideo")
56 |
57 |
58 | func _on_BannerAd_pressed():
59 | if addsEngine != null:
60 | addsEngine.showBanner("banners")
61 |
--------------------------------------------------------------------------------
/AdsExampleProject/MainScene.tscn:
--------------------------------------------------------------------------------
1 | [gd_scene load_steps=2 format=2]
2 |
3 | [ext_resource path="res://AdExample.gd" type="Script" id=1]
4 |
5 | [node name="Node2D" type="Node2D"]
6 | script = ExtResource( 1 )
7 |
8 | [node name="VideoAd" type="Button" parent="."]
9 | margin_left = 62.0
10 | margin_top = 61.0
11 | margin_right = 967.0
12 | margin_bottom = 175.0
13 | text = "Show video ad"
14 | __meta__ = {
15 | "_edit_use_anchors_": false
16 | }
17 |
18 | [node name="RewardedVideo" type="Button" parent="."]
19 | margin_left = 61.0
20 | margin_top = 198.0
21 | margin_right = 966.0
22 | margin_bottom = 312.0
23 | text = "Show rewarded video ad"
24 | __meta__ = {
25 | "_edit_use_anchors_": false
26 | }
27 |
28 | [node name="BannerAd" type="Button" parent="."]
29 | margin_left = 60.0
30 | margin_top = 335.0
31 | margin_right = 965.0
32 | margin_bottom = 449.0
33 | text = "Show Banner ad"
34 | __meta__ = {
35 | "_edit_use_anchors_": false
36 | }
37 | [connection signal="pressed" from="VideoAd" to="." method="_on_VideoAd_pressed"]
38 | [connection signal="pressed" from="RewardedVideo" to="." method="_on_RewardedVideo_pressed"]
39 | [connection signal="pressed" from="BannerAd" to="." method="_on_BannerAd_pressed"]
40 |
--------------------------------------------------------------------------------
/AdsExampleProject/default_env.tres:
--------------------------------------------------------------------------------
1 | [gd_resource type="Environment" load_steps=2 format=2]
2 |
3 | [sub_resource type="ProceduralSky" id=1]
4 |
5 | [resource]
6 | background_mode = 2
7 | background_sky = SubResource( 1 )
8 |
--------------------------------------------------------------------------------
/AdsExampleProject/export_presets.cfg:
--------------------------------------------------------------------------------
1 | [preset.0]
2 |
3 | name="Android"
4 | platform="Android"
5 | runnable=true
6 | custom_features=""
7 | export_filter="all_resources"
8 | include_filter=""
9 | exclude_filter=""
10 | export_path=""
11 | patch_list=PoolStringArray( )
12 | script_export_mode=1
13 | script_encryption_key=""
14 |
15 | [preset.0.options]
16 |
17 | graphics/32_bits_framebuffer=true
18 | xr_features/xr_mode=0
19 | xr_features/degrees_of_freedom=0
20 | xr_features/hand_tracking=0
21 | xr_features/focus_awareness=false
22 | one_click_deploy/clear_previous_install=false
23 | custom_template/debug=""
24 | custom_template/release=""
25 | custom_template/use_custom_build=true
26 | plugins/UnityAdsGodot=true
27 | command_line/extra_args=""
28 | version/code=1
29 | version/name="1.0"
30 | package/unique_name="org.godotengine.$genname"
31 | package/name=""
32 | package/signed=true
33 | screen/immersive_mode=true
34 | screen/orientation=0
35 | screen/support_small=true
36 | screen/support_normal=true
37 | screen/support_large=true
38 | screen/support_xlarge=true
39 | screen/opengl_debug=false
40 | launcher_icons/main_192x192=""
41 | launcher_icons/adaptive_foreground_432x432=""
42 | launcher_icons/adaptive_background_432x432=""
43 | keystore/debug=""
44 | keystore/debug_user=""
45 | keystore/debug_password=""
46 | keystore/release=""
47 | keystore/release_user=""
48 | keystore/release_password=""
49 | apk_expansion/enable=false
50 | apk_expansion/SALT=""
51 | apk_expansion/public_key=""
52 | architectures/armeabi-v7a=true
53 | architectures/arm64-v8a=true
54 | architectures/x86=false
55 | architectures/x86_64=false
56 | permissions/custom_permissions=PoolStringArray( )
57 | permissions/access_checkin_properties=false
58 | permissions/access_coarse_location=false
59 | permissions/access_fine_location=false
60 | permissions/access_location_extra_commands=false
61 | permissions/access_mock_location=false
62 | permissions/access_network_state=false
63 | permissions/access_surface_flinger=false
64 | permissions/access_wifi_state=false
65 | permissions/account_manager=false
66 | permissions/add_voicemail=false
67 | permissions/authenticate_accounts=false
68 | permissions/battery_stats=false
69 | permissions/bind_accessibility_service=false
70 | permissions/bind_appwidget=false
71 | permissions/bind_device_admin=false
72 | permissions/bind_input_method=false
73 | permissions/bind_nfc_service=false
74 | permissions/bind_notification_listener_service=false
75 | permissions/bind_print_service=false
76 | permissions/bind_remoteviews=false
77 | permissions/bind_text_service=false
78 | permissions/bind_vpn_service=false
79 | permissions/bind_wallpaper=false
80 | permissions/bluetooth=false
81 | permissions/bluetooth_admin=false
82 | permissions/bluetooth_privileged=false
83 | permissions/brick=false
84 | permissions/broadcast_package_removed=false
85 | permissions/broadcast_sms=false
86 | permissions/broadcast_sticky=false
87 | permissions/broadcast_wap_push=false
88 | permissions/call_phone=false
89 | permissions/call_privileged=false
90 | permissions/camera=false
91 | permissions/capture_audio_output=false
92 | permissions/capture_secure_video_output=false
93 | permissions/capture_video_output=false
94 | permissions/change_component_enabled_state=false
95 | permissions/change_configuration=false
96 | permissions/change_network_state=false
97 | permissions/change_wifi_multicast_state=false
98 | permissions/change_wifi_state=false
99 | permissions/clear_app_cache=false
100 | permissions/clear_app_user_data=false
101 | permissions/control_location_updates=false
102 | permissions/delete_cache_files=false
103 | permissions/delete_packages=false
104 | permissions/device_power=false
105 | permissions/diagnostic=false
106 | permissions/disable_keyguard=false
107 | permissions/dump=false
108 | permissions/expand_status_bar=false
109 | permissions/factory_test=false
110 | permissions/flashlight=false
111 | permissions/force_back=false
112 | permissions/get_accounts=false
113 | permissions/get_package_size=false
114 | permissions/get_tasks=false
115 | permissions/get_top_activity_info=false
116 | permissions/global_search=false
117 | permissions/hardware_test=false
118 | permissions/inject_events=false
119 | permissions/install_location_provider=false
120 | permissions/install_packages=false
121 | permissions/install_shortcut=false
122 | permissions/internal_system_window=false
123 | permissions/internet=false
124 | permissions/kill_background_processes=false
125 | permissions/location_hardware=false
126 | permissions/manage_accounts=false
127 | permissions/manage_app_tokens=false
128 | permissions/manage_documents=false
129 | permissions/master_clear=false
130 | permissions/media_content_control=false
131 | permissions/modify_audio_settings=false
132 | permissions/modify_phone_state=false
133 | permissions/mount_format_filesystems=false
134 | permissions/mount_unmount_filesystems=false
135 | permissions/nfc=false
136 | permissions/persistent_activity=false
137 | permissions/process_outgoing_calls=false
138 | permissions/read_calendar=false
139 | permissions/read_call_log=false
140 | permissions/read_contacts=false
141 | permissions/read_external_storage=false
142 | permissions/read_frame_buffer=false
143 | permissions/read_history_bookmarks=false
144 | permissions/read_input_state=false
145 | permissions/read_logs=false
146 | permissions/read_phone_state=false
147 | permissions/read_profile=false
148 | permissions/read_sms=false
149 | permissions/read_social_stream=false
150 | permissions/read_sync_settings=false
151 | permissions/read_sync_stats=false
152 | permissions/read_user_dictionary=false
153 | permissions/reboot=false
154 | permissions/receive_boot_completed=false
155 | permissions/receive_mms=false
156 | permissions/receive_sms=false
157 | permissions/receive_wap_push=false
158 | permissions/record_audio=false
159 | permissions/reorder_tasks=false
160 | permissions/restart_packages=false
161 | permissions/send_respond_via_message=false
162 | permissions/send_sms=false
163 | permissions/set_activity_watcher=false
164 | permissions/set_alarm=false
165 | permissions/set_always_finish=false
166 | permissions/set_animation_scale=false
167 | permissions/set_debug_app=false
168 | permissions/set_orientation=false
169 | permissions/set_pointer_speed=false
170 | permissions/set_preferred_applications=false
171 | permissions/set_process_limit=false
172 | permissions/set_time=false
173 | permissions/set_time_zone=false
174 | permissions/set_wallpaper=false
175 | permissions/set_wallpaper_hints=false
176 | permissions/signal_persistent_processes=false
177 | permissions/status_bar=false
178 | permissions/subscribed_feeds_read=false
179 | permissions/subscribed_feeds_write=false
180 | permissions/system_alert_window=false
181 | permissions/transmit_ir=false
182 | permissions/uninstall_shortcut=false
183 | permissions/update_device_stats=false
184 | permissions/use_credentials=false
185 | permissions/use_sip=false
186 | permissions/vibrate=false
187 | permissions/wake_lock=false
188 | permissions/write_apn_settings=false
189 | permissions/write_calendar=false
190 | permissions/write_call_log=false
191 | permissions/write_contacts=false
192 | permissions/write_external_storage=false
193 | permissions/write_gservices=false
194 | permissions/write_history_bookmarks=false
195 | permissions/write_profile=false
196 | permissions/write_secure_settings=false
197 | permissions/write_settings=false
198 | permissions/write_sms=false
199 | permissions/write_social_stream=false
200 | permissions/write_sync_settings=false
201 | permissions/write_user_dictionary=false
202 |
--------------------------------------------------------------------------------
/AdsExampleProject/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/j1and1/GodotUnityAdsInterface/d9a57e2a245263ea9633553d0a31ec2cb7a0eb69/AdsExampleProject/icon.png
--------------------------------------------------------------------------------
/AdsExampleProject/icon.png.import:
--------------------------------------------------------------------------------
1 | [remap]
2 |
3 | importer="texture"
4 | type="StreamTexture"
5 | path="res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex"
6 | metadata={
7 | "vram_texture": false
8 | }
9 |
10 | [deps]
11 |
12 | source_file="res://icon.png"
13 | dest_files=[ "res://.import/icon.png-487276ed1e3a0c39cad0279d744ee560.stex" ]
14 |
15 | [params]
16 |
17 | compress/mode=0
18 | compress/lossy_quality=0.7
19 | compress/hdr_mode=0
20 | compress/bptc_ldr=0
21 | compress/normal_map=0
22 | flags/repeat=0
23 | flags/filter=true
24 | flags/mipmaps=false
25 | flags/anisotropic=false
26 | flags/srgb=2
27 | process/fix_alpha_border=true
28 | process/premult_alpha=false
29 | process/HDR_as_SRGB=false
30 | process/invert_color=false
31 | stream=false
32 | size_limit=0
33 | detect_3d=true
34 | svg/scale=1.0
35 |
--------------------------------------------------------------------------------
/AdsExampleProject/project.godot:
--------------------------------------------------------------------------------
1 | ; Engine configuration file.
2 | ; It's best edited using the editor UI and not directly,
3 | ; since the parameters that go here are not all obvious.
4 | ;
5 | ; Format:
6 | ; [section] ; section goes between []
7 | ; param=value ; assign values to parameters
8 |
9 | config_version=4
10 |
11 | _global_script_classes=[ ]
12 | _global_script_class_icons={
13 |
14 | }
15 |
16 | [application]
17 |
18 | config/name="AdsExampleProject"
19 | run/main_scene="res://MainScene.tscn"
20 | config/icon="res://icon.png"
21 |
22 | [rendering]
23 |
24 | environment/default_environment="res://default_env.tres"
25 |
--------------------------------------------------------------------------------
/Godot/UnityAdsGodot.gdap:
--------------------------------------------------------------------------------
1 | [config]
2 |
3 | name="UnityAdsGodot"
4 | binary_type="local"
5 | binary="unityadsgodot-release.aar"
6 |
7 | [dependencies]
8 |
9 | local=["unity-ads.aar"]
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Unity ads for godot using new export template system
2 |
3 | Current version of the `unityadsgodot-release.aar` is available for download under [Releases](https://github.com/j1and1/GodotUnityAdsInterface/releases)
4 |
5 | ## Requirements
6 |
7 | The new export templates for android was introduced in Godot 3.2.2. So Godot 3.2.2 and up is required
8 |
9 | ## Setup
10 |
11 | - In Godot open up the Android export template settings by going to `Project -> Export`.
12 | - Select `Android` and enable costom build.
13 | - Instal custom android build template.
14 | - Download UnityAds Android library from [here](https://github.com/Unity-Technologies/unity-ads-android/releases)
15 | - Open up the Godots projects `android` folder and create a folder called `plugins` if it isn't there.
16 | - Place the `unityadsgodot-release.aar` inside the freshly created plugins folder along with `unity-ads.aar` and `UnityAdsGodot.gdap`.
17 | - The min SDK version will need a update so open up the `android\build\config.gradle` and update `minSdkVersion` to 26
18 | - Last thing is to enable this plugin under `Project -> Export -> Android -> Plugins` and check the checkbox besides `Unity Ads Godot`
19 |
20 | ## Usage
21 |
22 | Usage example is availible in `AdsExampleProject` in this repository but basically the code below sums it up
23 |
24 | ```
25 | var addsEngine = null
26 |
27 | # Called when the node enters the scene tree for the first time.
28 | func _ready():
29 | if Engine.has_singleton("UnityAdsGodot"):
30 | addsEngine = Engine.get_singleton("UnityAdsGodot")
31 | addsEngine.connect("UnityAdsReady", self, "_on_adsReady")
32 | addsEngine.connect("UnityAdsFinish", self, "_on_adsFinished")
33 | addsEngine.connect("UnityAdsError", self, "_on_adsError")
34 | addsEngine.connect("UnityBannerLoaded", self, "_on_bannerLoaded")
35 | addsEngine.connect("UnityBannerError", self, "_on_bannerError")
36 | addsEngine.initialise("1687685", false) # project id and TestMode enabled
37 | else:
38 | print("Couldn't find HelloSignals singleton")
39 |
40 | func _on_adsReady():
41 | print("video adds should be ready.")
42 |
43 | func _on_adsFinished(placement, reason):
44 | reason = int(reason)
45 | if reason == 2:
46 | print("Completed")
47 | elif reason == 1:
48 | print("User skiped ad")
49 | else:
50 | print("Something went wrong")
51 |
52 | func _on_adsError(reasonString):
53 | print(reasonString)
54 |
55 | func _on_bannerLoaded():
56 | print("Banner loaded")
57 |
58 | func _on_bannerError(reasonString):
59 | print(reasonString)
60 |
61 | func _on_VideoAd_pressed():
62 | if addsEngine != null:
63 | addsEngine.loadAd("video")
64 | while !addsEngine.isReady("video"):
65 | pass # There should be another way to do this!
66 |
67 | addsEngine.show("video")
68 |
69 | func _on_RewardedVideo_pressed():
70 | if addsEngine != null:
71 | addsEngine.loadAd("rewardedVideo")
72 | while !addsEngine.isReady("rewardedVideo"):
73 | pass # There should be another way to do this!
74 |
75 | addsEngine.show("rewardedVideo")
76 |
77 |
78 | func _on_BannerAd_pressed():
79 | if addsEngine != null:
80 | addsEngine.showBanner("banners")
81 | ```
82 |
83 | ## Compiling from source
84 |
85 | - Clone out this repo
86 | - Download UnityAds Android library from [here](https://github.com/Unity-Technologies/unity-ads-android/releases) and place it inside `unityadsgodot\libs` folder
87 | - Download corresponding version of `godot-lib.3.2.2.stable.release` or `godot-lib.3.2.2.stable.mono.release` from [here](https://godotengine.org/download/) and place it again in `unityadsgodot\libs` folder
88 | - Open the project in android studio and run `gradlew build` from terminal to build the aar libs
89 | - Build results should be located inside `unityadsgodot\build\outputs\aar`
90 | - Build output (that includes plugin description file and `unityadsgodot-release.aar`) can be copied to Godot projects `android\plugins` alongside dependencies
91 |
92 | ## TODOs
93 |
94 | - [ ] Improve documentation
95 | - [ ] Code cleanup
96 | - [x] Project cleanup
97 | - [ ] Banner ads are not working and seems that api is deprecated. Need to investigate that
98 | - [ ] Improve setup (possibly create a script for that)
99 | - [ ] Update error code reporting to GDScript
100 |
101 | ## Known issues
102 |
103 | - Placement id always needs to be present for some reason
104 | - Banners are not working. Something about `UnityAds: com.unity3d.services.core.api.Sdk.logError() (line:70) :: No fill for placement banners` internet says that it is normal?
105 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 |
9 | }
10 | dependencies {
11 | classpath 'com.android.tools.build:gradle:3.6.1'
12 |
13 |
14 | // NOTE: Do not place your application dependencies here; they belong
15 | // in the individual module build.gradle files
16 | }
17 | }
18 |
19 | allprojects {
20 | repositories {
21 | google()
22 | jcenter()
23 |
24 | }
25 | }
26 |
27 | task clean(type: Delete) {
28 | delete rootProject.buildDir
29 | }
30 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 |
21 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/j1and1/GodotUnityAdsInterface/d9a57e2a245263ea9633553d0a31ec2cb7a0eb69/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Apr 20 16:35:20 EEST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name='UnityAddsGodot'
2 | include ':unityadsgodot'
3 |
--------------------------------------------------------------------------------
/unityadsgodot/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/unityadsgodot/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 28
5 | buildToolsVersion "29.0.3"
6 |
7 | defaultConfig {
8 | minSdkVersion 26
9 | targetSdkVersion 28
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | consumerProguardFiles 'consumer-rules.pro'
14 | }
15 |
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 |
23 | }
24 |
25 | dependencies {
26 | implementation fileTree(dir: 'libs', include: ['*.jar'])
27 |
28 | compileOnly fileTree(dir: 'libs', include: ['*.aar'])
29 | implementation 'androidx.annotation:annotation:1.1.0'
30 | }
31 |
32 | task copyResourceToOutput {
33 | doLast {
34 | copy {
35 | from "$projectDir/../Godot/UnityAdsGodot.gdap"
36 | into "$buildDir/outputs/aar/"
37 | }
38 | copy {
39 | from "$projectDir/libs/unity-ads.aar"
40 | into "$buildDir/outputs/aar/"
41 | }
42 | }
43 | }
44 |
45 | build.finalizedBy(copyResourceToOutput)
--------------------------------------------------------------------------------
/unityadsgodot/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/j1and1/GodotUnityAdsInterface/d9a57e2a245263ea9633553d0a31ec2cb7a0eb69/unityadsgodot/consumer-rules.pro
--------------------------------------------------------------------------------
/unityadsgodot/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/unityadsgodot/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/unityadsgodot/src/main/java/com/jandans/unityaddsgodot/UnityAdsInterface.java:
--------------------------------------------------------------------------------
1 | package com.jandans.unityaddsgodot;
2 |
3 | import android.app.Activity;
4 | import android.util.Log;
5 | import android.view.View;
6 |
7 | import androidx.annotation.NonNull;
8 | import androidx.annotation.Nullable;
9 |
10 | import com.unity3d.ads.IUnityAdsListener;
11 | import com.unity3d.ads.UnityAds;
12 | import com.unity3d.services.banners.IUnityBannerListener;
13 | import com.unity3d.services.banners.UnityBanners;
14 | import com.unity3d.services.banners.view.BannerPosition;
15 |
16 | import org.godotengine.godot.Godot;
17 | import org.godotengine.godot.plugin.GodotPlugin;
18 | import org.godotengine.godot.plugin.SignalInfo;
19 |
20 | import java.util.ArrayList;
21 | import java.util.HashSet;
22 | import java.util.List;
23 | import java.util.Set;
24 |
25 | public class UnityAdsInterface extends GodotPlugin implements IUnityAdsListener, IUnityBannerListener {
26 |
27 | private final String TAG = "UnityAdsInterface";
28 | private SignalInfo UnityAdsReady = new SignalInfo("UnityAdsReady");
29 | private SignalInfo UnityAdsStart = new SignalInfo("UnityAdsStart");
30 | private SignalInfo UnityAdsFinish = new SignalInfo("UnityAdsFinish", String.class, String.class);
31 | private SignalInfo UnityAdsError = new SignalInfo("UnityAdsError", String.class);
32 | private SignalInfo UnityBannerLoaded = new SignalInfo("UnityBannerLoaded");
33 | private SignalInfo UnityBannerUnloaded = new SignalInfo("UnityBannerUnloaded");
34 | private SignalInfo UnityBannerShow = new SignalInfo("UnityBannerShow");
35 | private SignalInfo UnityBannerClick = new SignalInfo("UnityBannerClick");
36 | private SignalInfo UnityBannerHide = new SignalInfo("UnityBannerHide");
37 | private SignalInfo UnityBannerError = new SignalInfo("UnityBannerError", String.class);
38 |
39 | public UnityAdsInterface(Godot godot) {
40 | super(godot);
41 | }
42 |
43 | @androidx.annotation.NonNull
44 | @Override
45 | public String getPluginName() {
46 | return "UnityAdsGodot";
47 | }
48 |
49 | @NonNull
50 | @Override
51 | public List getPluginMethods() {
52 | return new ArrayList() {
53 | {
54 | add("initialise");
55 | add("showBanner");
56 | add("loadAd");
57 | add("show");
58 | add("hideBanner");
59 | add("isReady");
60 | }
61 | };
62 | }
63 |
64 | @NonNull
65 | @Override
66 | public Set getPluginSignals() {
67 | return new HashSet() {
68 | {
69 | add(UnityAdsReady);
70 | add(UnityAdsStart);
71 | add(UnityAdsFinish);
72 | add(UnityAdsError);
73 | add(UnityBannerLoaded);
74 | add(UnityBannerUnloaded);
75 | add(UnityBannerShow);
76 | add(UnityBannerHide);
77 | add(UnityBannerError);
78 | }
79 | };
80 | }
81 |
82 | public void initialise(String appId, boolean testMode)
83 | {
84 | try
85 | {
86 | UnityAds.initialize(getActivity(), appId, testMode);
87 | UnityAds.addListener(this);
88 | }
89 | catch (Exception ex)
90 | {
91 | Log.e(TAG, ex.getMessage());
92 | }
93 | }
94 |
95 | public boolean isReady(String placementId) {
96 | return UnityAds.isReady(placementId);
97 | }
98 |
99 | public void loadAd(String placementId)
100 | {
101 | UnityAds.load(placementId);
102 | }
103 |
104 | public boolean show(String placementId)
105 | {
106 | if (UnityAds.isReady())
107 | {
108 | try
109 | {
110 | UnityAds.show(getActivity(), placementId);
111 | }
112 | catch (Exception ex)
113 | {
114 | Log.e(TAG, ex.getMessage());
115 | return false;
116 | }
117 | return true;
118 | }
119 | else
120 | {
121 | Log.i(TAG, "Adds not ready");
122 | return false;
123 | }
124 | }
125 |
126 | public void showBanner(final String placementID) {
127 | final IUnityBannerListener Listener = this;
128 | getActivity().runOnUiThread(new Runnable() {
129 | @Override
130 | public void run() {
131 | try
132 | {
133 | UnityBanners.setBannerPosition(BannerPosition.BOTTOM_CENTER);
134 | UnityBanners.setBannerListener(Listener);
135 | UnityBanners.loadBanner(getActivity(), placementID);
136 | }
137 | catch (Exception ex)
138 | {
139 | Log.e(TAG, ex.getMessage());
140 | }
141 | }
142 | });
143 | }
144 |
145 | public void hideBanner() {
146 | try
147 | {
148 | UnityBanners.destroy();
149 | }
150 | catch (Exception ex)
151 | {
152 | Log.e(TAG, ex.getMessage());
153 | }
154 | }
155 |
156 | @Override
157 | public void onUnityAdsReady(String s) {
158 | emitSignal(UnityAdsReady.getName());
159 | }
160 |
161 | @Override
162 | public void onUnityAdsStart(String s) {
163 | emitSignal(UnityAdsStart.getName());
164 | }
165 |
166 | @Override
167 | public void onUnityAdsFinish(String placement, UnityAds.FinishState finishState) {
168 | int state = -1;
169 |
170 | // Implement conditional logic for each ad completion status:
171 | if (finishState == UnityAds.FinishState.COMPLETED) {
172 | // Reward the user for watching the ad to completion.
173 | state = 2;
174 | } else if (finishState == UnityAds.FinishState.SKIPPED) {
175 | // user skipped the ad.
176 | state = 1;
177 | } else if (finishState == UnityAds.FinishState.ERROR) {
178 | // Log an error.
179 | Log.e(TAG, placement);
180 | state = 0;
181 | }
182 |
183 | emitSignal(UnityAdsFinish.getName(), placement, String.format("%d", state));
184 | }
185 |
186 | @Override
187 | public void onUnityAdsError(UnityAds.UnityAdsError unityAdsError, String s) {
188 | emitSignal(UnityAdsError.getName(), s);
189 | Log.e(TAG, s);
190 | }
191 | //Banner stuff goes here
192 | @Override
193 | public void onUnityBannerLoaded(String s, View view) {
194 | emitSignal(UnityBannerLoaded.getName());
195 | }
196 |
197 | @Override
198 | public void onUnityBannerUnloaded(String s) {
199 | emitSignal(UnityBannerUnloaded.getName());
200 | }
201 |
202 | @Override
203 | public void onUnityBannerShow(String s) {
204 | emitSignal(UnityBannerShow.getName());
205 | }
206 |
207 | @Override
208 | public void onUnityBannerClick(String s) {
209 | emitSignal(UnityBannerClick.getName());
210 | }
211 |
212 | @Override
213 | public void onUnityBannerHide(String s) {
214 | emitSignal(UnityBannerHide.getName(), s);
215 | }
216 |
217 | @Override
218 | public void onUnityBannerError(String s) {
219 | emitSignal(UnityBannerError.getName(), s);
220 | Log.e(TAG, s);
221 | hideBanner();
222 | }
223 | }
224 |
--------------------------------------------------------------------------------