UnityAds native extension for Defold engine.
Switch branches/tags
Nothing to show
Clone or download
Latest commit 785276a Nov 9, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
defunityads new AndroidManifest #3 Nov 9, 2018
example Remove callback using unityads.setCallback() or unityads.setCallback(… May 23, 2018
input Remove callback using unityads.setCallback() or unityads.setCallback(… May 23, 2018
.gitignore first iteration of android unity ads May 22, 2017
README.md Update README.md Jun 4, 2018
game.project

README.md

“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.“

DefVideoAds (plugin for Unity ADS)

DefVideoAds (plugin for Unity ADS)

This is UnityAds native extension for Defold engine. Extension supported IOS and Android.

Installation

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:

https://github.com/AGulev/DefVideoAds/archive/master.zip

Android installation info

Set defunityads/AndroindManifest.xml as default manifest for your project or add the next Activities to your manifest:

<!-- For DefVideoAds -->
<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" />

Example

See the example folder for understand how to use extension. Especially ui.gui_script file.

Example screenshot

LUA Api

Methods

unityads.initialize(gameID, callback)

unityads.initialize(gameID, callback, testMode)

original doc

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(callback)

original doc

unityads.setCallback(defunityads_callback) -- set callback
unityads.setCallback(nil) -- remove callback
unityads.setCallback() -- remove callback

unityads.setDebugMode(isDebug)

original doc

unityads.setDebugMode(true) -- set debug mod

unityads.getDebugMode()

original doc

unityads.getDebugMode() -- Returns true if current mod is debug

unityads.getPlacementState()

unityads.getPlacementState(placementId)

original doc

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()

unityads.isReady(placementId)

original doc

unityads.isReady() -- Returns true if default ad is ready
unityads.isReady("rewardedVideo") -- Returns true if rewardedVideo is ready

unityads.isInitialized()

original doc

unityads.isInitialized() -- Returns true if Unity ADS initialized

unityads.isSupported()

original doc

unityads.isSupported() -- Returns true if Unity Ads is supported by the current device

unityads.getVersion()

original doc

unityads.getVersion() -- Returns the Unity Ads SDK version as a string.

unityads.show()

unityads.show(placementId)

original doc

unityads.show() -- show default ad
unityads.show("rewardedVideo") -- show rewardedVideo

Constants

local function defunityads_callback(self, msg_type, message)
...
end

Message types

--possible msg_type :
unityads.TYPE_IS_READY
unityads.TYPE_DID_START
unityads.TYPE_DID_ERROR
unityads.TYPE_DID_FINISH
unityads.TYPE_IS_READY
local function defunityads_callback(self, msg_type, message)
  if msg_type == unityads.TYPE_IS_READY then
    pprint(message) -- message = {placementId = "string"}
  end
end
unityads.TYPE_DID_START
local function defunityads_callback(self, msg_type, message)
  if msg_type == unityads.TYPE_DID_START then
    pprint(message) -- message = {placementId = "string"}
  end
end
unityads.TYPE_DID_ERROR
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
unityads.TYPE_DID_FINISH
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

Error types

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

Finish states

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: me@agulev.com