“This plugin is not endorsed or sponsored by Unity Technologies. This is an independent, unofficial plugin. UNITY and the Unity logo are Unity Technologies’ registered trademarks in the US and other countries--All rights reserved.“
This is UnityAds native extension for Defold engine. Extension supported IOS and Android.
You can use the DefVideoAds 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:
or point to the ZIP file of a specific release.
See the example folder for understand how to use extension. Especially ui.gui_script file.
local function defunityads_callback(self, msg_type, message)
...
end
...
unityads.initialize("1401815", defunityads_callback) -- testMode is optional parameter
unityads.initialize("1401815", defunityads_callback, true) -- testMode is optional parameter
unityads.setCallback(defunityads_callback) -- set callback
unityads.setCallback(nil) -- remove callback
unityads.setCallback() -- remove callback
unityads.setDebugMode(true) -- set debug mod
unityads.getDebugMode() -- Returns true if current mod is debug
unityads.getPlacementState() -- Returns a default ad state
unityads.getPlacementState("rewardedVideo") -- Returns rewardedVideo ad state
--possible states:
unityads.PLACEMENT_STATE_READY
unityads.PLACEMENT_STATE_NOT_AVAILABLE
unityads.PLACEMENT_STATE_DISABLED
unityads.PLACEMENT_STATE_WAITING
unityads.PLACEMENT_STATE_NO_FILL
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
unityads.loadBanner("banner") -- load banner
unityads.unloadBanner() -- unload banner
unityads.showBanner() -- show loaded banner
unityads.hideBanner() -- hide banner
unityads.setBannerPosition(position) -- set position of the banner
-- default value is unityads.BANNER_POSITION_TOP_CENTER
--possible positions:
unityads.BANNER_POSITION_TOP_LEFT
unityads.BANNER_POSITION_TOP_CENTER
unityads.BANNER_POSITION_TOP_RIGHT
unityads.BANNER_POSITION_BOTTOM_LEFT
unityads.BANNER_POSITION_BOTTOM_CENTER
unityads.BANNER_POSITION_BOTTOM_RIGHT
unityads.BANNER_POSITION_CENTER
unityads.BANNER_POSITION_NONE
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
unityads.TYPE_BANNER
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
local function defunityads_callback(self, msg_type, message)
if msg_type == unityads.TYPE_BANNER then
if message.event == BANNER_EVENT_DID_ERROR then
pprint(message) -- message = {event = BANNER_EVENT_DID_ERROR, error = "string"}
else
pprint(message) -- message = {event = BANNER_EVENT_*, placementId = "string"}
end
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
--possible banner events:
unityads.BANNER_EVENT_DID_LOAD
unityads.BANNER_EVENT_DID_UNLOAD
unityads.BANNER_EVENT_DID_SHOW
unityads.BANNER_EVENT_DID_HIDE
unityads.BANNER_EVENT_DID_CLICK
unityads.BANNER_EVENT_DID_ERROR
local function defunityads_callback(self, msg_type, message)
if msg_type == unityads.TYPE_BANNER then
if message.event == unityads.BANNER_EVENT_DID_LOAD then
...
elseif message.event == unityads.BANNER_EVENT_DID_UNLOAD then
...
end
end
If you have any issues, questions or suggestions please create an issue or contact me: me@agulev.com