Delegate Methods — Unity

Last Update:

 

 

 

The Chartboost SDK's delegate methods allow you to exercise a greater degree of control over your integration. For example, you can:

  • Log debug messages when your game attempts to load an interstitial.
  • Prevent ads from showing the first time a user plays your game.
  • Determine whether a user has clicked an ad or just closed it – and react accordingly.
  • Prevent an interstitial page appearing when and where it would interfere with your game.

You can view the Chartboost Unity SDK methods at your disposal in the Chartboost.cs file (found in the imported Unity plugin files (Chartboost > Scripts > Chartboost.cs). You can see a good example of how to implement many of these methods in the ChartboostExample.cs file (Chartboost > Examples > ChartboostExample.cs) within the sample scene included with your Unity SDK download.


▲ Back to top

 

Click here to view iOS SDK configuration methods.


▲ Back to top

 

The Chartboost Unity SDK implements its delegate functionality using C# style delegates and events. Before using any of the delegate methods, you should first subscribe to the relevant SDK events in your MonoBehaviour as demonstrated:

void OnEnable() {
  // Listen to all impression-related events
  Chartboost.didFailToLoadInterstitial += didFailToLoadInterstitial;
  Chartboost.didDismissInterstitial += didDismissInterstitial;
  Chartboost.didCloseInterstitial += didCloseInterstitial;
  Chartboost.didClickInterstitial += didClickInterstitial;
  Chartboost.didCacheInterstitial += didCacheInterstitial;
  Chartboost.shouldDisplayInterstitial += shouldDisplayInterstitial;
  Chartboost.didDisplayInterstitial += didDisplayInterstitial;
  Chartboost.didFailToRecordClick += didFailToRecordClick;
  Chartboost.didFailToLoadRewardedVideo += didFailToLoadRewardedVideo;
  Chartboost.didDismissRewardedVideo += didDismissRewardedVideo;
  Chartboost.didCloseRewardedVideo += didCloseRewardedVideo;
  Chartboost.didClickRewardedVideo += didClickRewardedVideo;
  Chartboost.didCacheRewardedVideo += didCacheRewardedVideo;
  Chartboost.shouldDisplayRewardedVideo += shouldDisplayRewardedVideo;
  Chartboost.didCompleteRewardedVideo += didCompleteRewardedVideo;
  Chartboost.didDisplayRewardedVideo += didDisplayRewardedVideo;
  Chartboost.didCacheInPlay += didCacheInPlay;
  Chartboost.didFailToLoadInPlay += didFailToLoadInPlay;
  Chartboost.didPauseClickForConfirmation += didPauseClickForConfirmation;
  Chartboost.willDisplayVideo += willDisplayVideo;
  #if UNITY_IPHONE
  Chartboost.didCompleteAppStoreSheetFlow += didCompleteAppStoreSheetFlow;
  #endif
}
Don't make cache or show calls inside didFailToLoad delegates or the universe will implode.

You should also make sure to unsubscribe to those same events when appropriate:

void OnDisable() {
  // Remove event handlers
  Chartboost.didFailToLoadInterstitial -= didFailToLoadInterstitial;
  Chartboost.didDismissInterstitial -= didDismissInterstitial;
  Chartboost.didCloseInterstitial -= didCloseInterstitial;
  Chartboost.didClickInterstitial -= didClickInterstitial;
  Chartboost.didCacheInterstitial -= didCacheInterstitial;
  Chartboost.shouldDisplayInterstitial -= shouldDisplayInterstitial;
  Chartboost.didDisplayInterstitial -= didDisplayInterstitial;
  Chartboost.didFailToRecordClick -= didFailToRecordClick;
  Chartboost.didFailToLoadRewardedVideo -= didFailToLoadRewardedVideo;
  Chartboost.didDismissRewardedVideo -= didDismissRewardedVideo;
  Chartboost.didCloseRewardedVideo -= didCloseRewardedVideo;
  Chartboost.didClickRewardedVideo -= didClickRewardedVideo;
  Chartboost.didCacheRewardedVideo -= didCacheRewardedVideo;
  Chartboost.shouldDisplayRewardedVideo -= shouldDisplayRewardedVideo;
  Chartboost.didCompleteRewardedVideo -= didCompleteRewardedVideo;
  Chartboost.didDisplayRewardedVideo -= didDisplayRewardedVideo;
  Chartboost.didCacheInPlay -= didCacheInPlay;
  Chartboost.didFailToLoadInPlay -= didFailToLoadInPlay;
  Chartboost.didPauseClickForConfirmation -= didPauseClickForConfirmation;
  Chartboost.willDisplayVideo -= willDisplayVideo;
  #if UNITY_IPHONE
  Chartboost.didCompleteAppStoreSheetFlow -= didCompleteAppStoreSheetFlow;
  #endif
}
Don't make cache or show calls inside didFailToLoad delegates or the universe will implode.

Feel free to subscribe to all events as above, or just the ones you need. Then proceed to implement the relevant delegate methods to handle responses to each event.

▲ Back to top

 

// Called before an interstitial will be displayed on the screen.
bool shouldDisplayInterstitial(CBLocation location)

// Called after an interstitial has been displayed on the screen.
void didDisplayInterstitial(CBLocation location)

// Called after an interstitial has been loaded from the Chartboost API
// servers and cached locally.
void didCacheInterstitial(CBLocation location)

// Called after an interstitial has attempted to load from the Chartboost API
// servers but failed.
void didFailToLoadInterstitial(CBLocation location, CBImpressionError error)

// Called after an interstitial has been dismissed.
void didDismissInterstitial(CBLocation location)

// Called after an interstitial has been closed.
void didCloseInterstitial(CBLocation location)

// Called after an interstitial has been clicked.
didClickInterstitial(CBLocation location)
Don't make cache or show calls inside didFailToLoad delegates or the universe will implode.

▲ Back to top

 

// Called before a rewarded video will be displayed on the screen.
bool shouldDisplayRewardedVideo(CBLocation location)

// Called after a rewarded video has been displayed on the screen.
void didDisplayRewardedVideo(CBLocation location)

// Called after a rewarded video has been loaded from the Chartboost API
// servers and cached locally.
void didCacheRewardedVideo(CBLocation location)

// Called after a rewarded video has attempted to load from the Chartboost API
// servers but failed.
void didFailToLoadRewardedVideo(CBLocation location, CBImpressionError error)

// Called after a rewarded video has been dismissed.
void didDismissRewardedVideo(CBLocation location)

// Called after a rewarded video has been closed.
void didCloseRewardedVideo(CBLocation location)

// Called after a rewarded video has been clicked.
void didClickRewardedVideo(CBLocation location)

// Called after a rewarded video has been viewed completely and user is eligible for reward.
void didCompleteRewardedVideo(CBLocation location, int reward)

// Implement to be notified of when a video will be displayed on the screen for
// a given CBLocation. You can then do things like mute effects and sounds.
void willDisplayVideo(CBLocation location)
Don't make cache or show calls inside didFailToLoad delegates or the universe will implode.

▲ Back to top

 

// Called after the App Store sheet is dismissed, when displaying the embedded app sheet.
// iOS only
void didCompleteAppStoreSheetFlow()

// Called after a click is registered, but the user is not forwarded to the App Store.
void didFailToRecordClick(CBLocation location, CBImpressionError error)

//Called after the SDK has been successfully initialized and video prefetching has been completed.
void didInitialize(bool status)
Don't make cache or show calls inside didFailToLoad delegates or the universe will implode.

▲ Back to top

 

// Called after a Native Ads object has been loaded from the Chartboost API
// servers and cached locally.
void didCacheInPlay(CBLocation location)

// Called after a Native Ad has attempted to load from the Chartboost API
// servers but failed.
void didFailToLoadInPlay(CBLocation location, CBImpressionError error)
Don't make cache or show calls inside didFailToLoad delegates or the universe will implode.

▲ Back to top

 

// Decide if Chartboost SDK should block for an age gate.
public static void setShouldPauseClickForConfirmation(bool shouldPause)

// Called if Chartboost SDK pauses click actions awaiting confirmation from the user. Use
// to implement an age gate in your game.
void didPauseClickForConfirmation()

// Confirm if an age gate passed or failed. When specified Chartboost will wait for
// this call before showing the IOS App Store.
public static void didPassAgeGate(bool pass)
      
Don't make cache or show calls inside didFailToLoad delegates or the universe will implode.

▲ Back to top