Skip to content

jhonnyking/DefVideoAds

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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

or point to the ZIP file of a specific release.

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

unityads.loadBanner(placementId)

unityads.loadBanner("banner") -- load banner

unityads.unloadBanner()

unityads.unloadBanner() -- unload banner

unityads.showBanner()

unityads.showBanner() -- show loaded banner

unityads.hideBanner()

unityads.hideBanner() -- hide banner

unityads.setBannerPosition(position)

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

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_BANNER
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
unityads.TYPE_BANNER
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

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

Banner events

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

About

UnityAds native extension for Defold engine.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 48.7%
  • C++ 29.5%
  • Java 9.4%
  • Objective-C++ 7.0%
  • C 5.4%