Skip to content

GregorGullwi/DefUnityAds

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DefUnityAds

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

Installation

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:

https://github.com/AGulev/DefUnityAds/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 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" />

Known issues

Example

See the example folder for understand how to use extension. Especially def_unity_ads.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.setDebugMode(isDebug)

original doc

unityads.setDebugMode(true) -- set debug mod

unityads.getDebugMode()

original doc

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

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: [email protected]

About

UnityAds native extension for Defold engine.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 45.4%
  • Objective-C 33.5%
  • Java 7.5%
  • Objective-C++ 7.1%
  • C 6.5%