This is UnityAds native extension for Defold engine. Extension supported IOS and Android.
You can use the DefUnityAds extension in your own project by adding this project as a Defold library dependency. Open your game.project file and in the dependencies field under project add:
Set defunityads/AndroindManifest.xml
as default manifest for your project or add the next Activities to your manifest:
<!-- For DefUnityAds -->
<activity
android:name="com.unity3d.ads.adunit.AdUnitActivity"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
android:hardwareAccelerated="true"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
<activity
android:name="com.unity3d.ads.adunit.AdUnitSoftwareActivity"
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
android:hardwareAccelerated="false"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" />
- Extension do not support getPlacementState method.
See the example folder for understand how to use extension. Especially def_unity_ads.script file.
local function defunityads_callback(self, msg_type, message)
...
end
...
unityads.initialize("1401815", defunityads_callback) -- testMode is optional parameter
unityads.setDebugMode(true) -- set debug mod
unityads.getDebugMode() -- Returns true if current mod is debug
unityads.isReady() -- Returns true if default ad is ready
unityads.isReady("rewardedVideo") -- Returns true if rewardedVideo is ready
unityads.isInitialized() -- Returns true if Unity ADS initialized
unityads.isSupported() -- Returns true if Unity Ads is supported by the current device
unityads.getVersion() -- Returns the Unity Ads SDK version as a string.
unityads.show() -- show default ad
unityads.show("rewardedVideo") -- show rewardedVideo
local function defunityads_callback(self, msg_type, message)
...
end
--possible msg_type :
unityads.TYPE_IS_READY
unityads.TYPE_DID_START
unityads.TYPE_DID_ERROR
unityads.TYPE_DID_FINISH
local function defunityads_callback(self, msg_type, message)
if msg_type == unityads.TYPE_IS_READY then
pprint(message) -- message = {placementId = "string"}
end
end
local function defunityads_callback(self, msg_type, message)
if msg_type == unityads.TYPE_DID_START then
pprint(message) -- message = {placementId = "string"}
end
end
local function defunityads_callback(self, msg_type, message)
if msg_type == unityads.TYPE_DID_ERROR then
pprint(message) -- message = {state = ERROR_*, message = "string"}
end
end
local function defunityads_callback(self, msg_type, message)
if msg_type == unityads.TYPE_DID_FINISH then
pprint(message) -- message = {state = FINISH_STATE_*, placementId = "string"}
end
end
Original doc about error types
--possible message.error :
unityads.ERROR_NOT_INITIALIZED --kUnityAdsErrorNotInitialized
unityads.ERROR_INITIALIZED_FAILED --kUnityAdsErrorInitializedFailed
unityads.ERROR_INVALID_ARGUMENT --kUnityAdsErrorInvalidArgument
unityads.ERROR_VIDEO_PLAYER --kUnityAdsErrorVideoPlayerError
unityads.ERROR_INIT_SANITY_CHECK_FAIL --kUnityAdsErrorInitSanityCheckFail
unityads.ERROR_AD_BLOCKER_DETECTED --kUnityAdsErrorAdBlockerDetected
unityads.ERROR_FILE_IO --kUnityAdsErrorFileIoError
unityads.ERROR_DEVICE_ID --kUnityAdsErrorDeviceIdError
unityads.ERROR_SHOW --kUnityAdsErrorShowError
unityads.ERROR_INTERNAL --kUnityAdsErrorInternalError
local function defunityads_callback(self, msg_type, message)
if msg_type == unityads.TYPE_DID_ERROR then
if message.error == unityads.ERROR_NOT_INITIALIZED then
...
elseif message.error == unityads.ERROR_INITIALIZED_FAILED then
...
end
end
Original doc about finish states
--possible message.state :
unityads.FINISH_STATE_ERROR --kUnityAdsFinishStateError
unityads.FINISH_STATE_SKIPPED --kUnityAdsFinishStateSkipped
unityads.FINISH_STATE_COMPLETED --kUnityAdsFinishStateCompleted
local function defunityads_callback(self, msg_type, message)
if msg_type == unityads.TYPE_DID_FINISH then
if message.state == unityads.FINISH_STATE_ERROR then
...
elseif message.state == unityads.FINISH_STATE_SKIPPED then
...
end
end
If you have any questions or suggestions contact: [email protected]