262 lines
8.5 KiB
C#
262 lines
8.5 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System;
|
|
using com.adjust.sdk;
|
|
|
|
namespace BF
|
|
{
|
|
// Example for IronSource Unity.
|
|
public class BFIronSourceSDKManager : MonoBehaviour
|
|
{
|
|
public Action<int> luaShowCallback;
|
|
public Action<int> luaLoadedCallback;
|
|
public Action<int, string> luaEarnedRewardCallback;
|
|
public bool AdLoaded = false;
|
|
public bool AdInitialized = false;
|
|
|
|
public void Start()
|
|
{
|
|
|
|
#if UNITY_ANDROID
|
|
// string appKey = "85460dcd";
|
|
string appKey = "1a6aacc25";
|
|
|
|
BFLog.Log("unity-script: IronSource.Agent.validateIntegration");
|
|
IronSource.Agent.validateIntegration();
|
|
|
|
BFLog.Log("unity-script: unity version" + IronSource.unityVersion());
|
|
|
|
// SDK init
|
|
BFLog.Log("unity-script: IronSource.Agent.init");
|
|
IronSource.Agent.init(appKey);
|
|
IronSource.Agent.setManualLoadRewardedVideo(true);
|
|
#elif UNITY_IPHONE
|
|
// string appKey = "8545d445";
|
|
#else
|
|
// string appKey = "unexpected_platform";
|
|
#endif
|
|
// BFLog.Log("unity-script: IronSource.Agent.validateIntegration");
|
|
// IronSource.Agent.validateIntegration();
|
|
|
|
// BFLog.Log("unity-script: unity version" + IronSource.unityVersion());
|
|
|
|
// // SDK init
|
|
// BFLog.Log("unity-script: IronSource.Agent.init");
|
|
// IronSource.Agent.init(appKey);
|
|
// IronSource.Agent.setManualLoadRewardedVideo(true);
|
|
}
|
|
|
|
void OnEnable()
|
|
{
|
|
|
|
//Add Init Event
|
|
IronSourceEvents.onSdkInitializationCompletedEvent += SdkInitializationCompletedEvent;
|
|
|
|
//Add Rewarded Video Events
|
|
// IronSourceEvents.onRewardedVideoAdOpenedEvent += RewardedVideoAdOpenedEvent;
|
|
// IronSourceEvents.onRewardedVideoAdClosedEvent += RewardedVideoAdClosedEvent;
|
|
// IronSourceEvents.onRewardedVideoAvailabilityChangedEvent += RewardedVideoAvailabilityChangedEvent;
|
|
// IronSourceEvents.onRewardedVideoAdStartedEvent += RewardedVideoAdStartedEvent;
|
|
// IronSourceEvents.onRewardedVideoAdEndedEvent += RewardedVideoAdEndedEvent;
|
|
// IronSourceEvents.onRewardedVideoAdRewardedEvent += RewardedVideoAdRewardedEvent;
|
|
// IronSourceEvents.onRewardedVideoAdShowFailedEvent += RewardedVideoAdShowFailedEvent;
|
|
// IronSourceEvents.onRewardedVideoAdClickedEvent += RewardedVideoAdClickedEvent;
|
|
|
|
//Add ImpressionSuccess Event
|
|
IronSourceEvents.onImpressionSuccessEvent += ImpressionSuccessEvent;
|
|
IronSourceEvents.onImpressionDataReadyEvent += ImpressionDataReadyEvent;
|
|
|
|
|
|
//Add AdInfo Rewarded Video Events
|
|
IronSourceRewardedVideoEvents.onAdOpenedEvent += ReardedVideoOnAdOpenedEvent;
|
|
IronSourceRewardedVideoEvents.onAdClosedEvent += ReardedVideoOnAdClosedEvent;
|
|
IronSourceRewardedVideoEvents.onAdAvailableEvent += ReardedVideoOnAdAvailable;
|
|
IronSourceRewardedVideoEvents.onAdUnavailableEvent += ReardedVideoOnAdUnavailable;
|
|
IronSourceRewardedVideoEvents.onAdShowFailedEvent += ReardedVideoOnAdShowFailedEvent;
|
|
IronSourceRewardedVideoEvents.onAdRewardedEvent += ReardedVideoOnAdRewardedEvent;
|
|
IronSourceRewardedVideoEvents.onAdClickedEvent += ReardedVideoOnAdClickedEvent;
|
|
}
|
|
|
|
void OnApplicationPause(bool isPaused)
|
|
{
|
|
#if UNITY_ANDROID
|
|
BFLog.Log("unity-script: OnApplicationPause = " + isPaused);
|
|
IronSource.Agent.onApplicationPause(isPaused);
|
|
#endif
|
|
}
|
|
|
|
public void ShowFullScreenAds()
|
|
{
|
|
if(IronSource.Agent.isRewardedVideoAvailable())
|
|
{
|
|
IronSource.Agent.showRewardedVideo();
|
|
}
|
|
else
|
|
{
|
|
// TryLoadRewardedAd();
|
|
BFLog.Log("unity-script: IronSource.Agent.isRewardedVideoAvailable - False");
|
|
}
|
|
}
|
|
|
|
public void TryLoadRewardedAd()
|
|
{
|
|
IronSource.Agent.loadRewardedVideo();
|
|
}
|
|
|
|
public void SetAdPlacement(string placement)
|
|
{
|
|
// BFMain.Instance.SDKMgr.BFNativeSDKMgr.SetAdPlacement(placement);
|
|
}
|
|
|
|
public void SetAdShowCallback(Action<int> callback)
|
|
{
|
|
luaShowCallback = callback;
|
|
}
|
|
|
|
// 设置广告加载回调
|
|
public void SetAdLoadedCallback(Action<int> callback)
|
|
{
|
|
luaLoadedCallback = callback;
|
|
}
|
|
|
|
// 设置广告看完回调
|
|
public void SetAdEarnedRewardCallback(Action<int, string> callback)
|
|
{
|
|
luaEarnedRewardCallback = callback;
|
|
}
|
|
public void ShowFullScreenAdFinish(int code)
|
|
{
|
|
if (luaShowCallback != null)
|
|
{
|
|
luaShowCallback(code);
|
|
}
|
|
}
|
|
#region Init callback handlers
|
|
|
|
void SdkInitializationCompletedEvent()
|
|
{
|
|
BFLog.Log("unity-script: I got SdkInitializationCompletedEvent");
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region AdInfo Rewarded Video
|
|
void ReardedVideoOnAdOpenedEvent(IronSourceAdInfo adInfo) {
|
|
BFLog.Log("unity-script: I got ReardedVideoOnAdOpenedEvent With AdInfo " + adInfo.ToString());
|
|
ShowFullScreenAdFinish(0);
|
|
}
|
|
void ReardedVideoOnAdClosedEvent(IronSourceAdInfo adInfo)
|
|
{
|
|
BFLog.Log("unity-script: I got ReardedVideoOnAdClosedEvent With AdInfo " + adInfo.ToString());
|
|
}
|
|
void ReardedVideoOnAdAvailable(IronSourceAdInfo adInfo)
|
|
{
|
|
BFLog.Log("unity-script: I got ReardedVideoOnAdAvailable With AdInfo " + adInfo.ToString());
|
|
AdLoaded = true;
|
|
|
|
if (luaLoadedCallback != null)
|
|
{
|
|
luaLoadedCallback(0);
|
|
}
|
|
}
|
|
void ReardedVideoOnAdUnavailable()
|
|
{
|
|
BFLog.Log("unity-script: I got ReardedVideoOnAdUnavailable");
|
|
AdLoaded = false;
|
|
|
|
if (luaLoadedCallback != null)
|
|
{
|
|
luaLoadedCallback(1);
|
|
}
|
|
}
|
|
void ReardedVideoOnAdShowFailedEvent(IronSourceError ironSourceError,IronSourceAdInfo adInfo)
|
|
{
|
|
BFLog.Log("unity-script: I got RewardedVideoAdOpenedEvent With Error"+ironSourceError.ToString() + "And AdInfo " + adInfo.ToString());
|
|
ShowFullScreenAdFinish(1);
|
|
}
|
|
void ReardedVideoOnAdRewardedEvent(IronSourcePlacement ironSourcePlacement,IronSourceAdInfo adInfo)
|
|
{
|
|
BFLog.Log("unity-script: I got ReardedVideoOnAdRewardedEvent With Placement" + ironSourcePlacement.ToString()+ "And AdInfo " + adInfo.ToString());
|
|
if (luaEarnedRewardCallback != null)
|
|
{
|
|
luaEarnedRewardCallback(0, "");
|
|
}
|
|
}
|
|
void ReardedVideoOnAdClickedEvent(IronSourcePlacement ironSourcePlacement, IronSourceAdInfo adInfo)
|
|
{
|
|
BFLog.Log("unity-script: I got ReardedVideoOnAdClickedEvent With Placement" + ironSourcePlacement.ToString() + "And AdInfo " + adInfo.ToString());
|
|
}
|
|
|
|
#endregion
|
|
|
|
// #region RewardedAd callback handlers
|
|
|
|
// void RewardedVideoAvailabilityChangedEvent(bool canShowAd)
|
|
// {
|
|
// BFLog.Log("unity-script: I got RewardedVideoAvailabilityChangedEvent, value = " + canShowAd);
|
|
// }
|
|
|
|
// void RewardedVideoAdOpenedEvent()
|
|
// {
|
|
// BFLog.Log("unity-script: I got RewardedVideoAdOpenedEvent");
|
|
// }
|
|
|
|
// void RewardedVideoAdRewardedEvent(IronSourcePlacement ssp)
|
|
// {
|
|
// BFLog.Log("unity-script: I got RewardedVideoAdRewardedEvent, amount = " + ssp.getRewardAmount() + " name = " + ssp.getRewardName());
|
|
// }
|
|
|
|
// void RewardedVideoAdClosedEvent()
|
|
// {
|
|
// BFLog.Log("unity-script: I got RewardedVideoAdClosedEvent");
|
|
// }
|
|
|
|
// void RewardedVideoAdStartedEvent()
|
|
// {
|
|
// BFLog.Log("unity-script: I got RewardedVideoAdStartedEvent");
|
|
// }
|
|
|
|
// void RewardedVideoAdEndedEvent()
|
|
// {
|
|
// BFLog.Log("unity-script: I got RewardedVideoAdEndedEvent");
|
|
// }
|
|
|
|
// void RewardedVideoAdShowFailedEvent(IronSourceError error)
|
|
// {
|
|
// BFLog.Log("unity-script: I got RewardedVideoAdShowFailedEvent, code : " + error.getCode() + ", description : " + error.getDescription());
|
|
// }
|
|
|
|
// void RewardedVideoAdClickedEvent(IronSourcePlacement ssp)
|
|
// {
|
|
// BFLog.Log("unity-script: I got RewardedVideoAdClickedEvent, name = " + ssp.getRewardName());
|
|
// }
|
|
// #endregion
|
|
|
|
#region ImpressionSuccess callback handler
|
|
|
|
void ImpressionSuccessEvent(IronSourceImpressionData impressionData)
|
|
{
|
|
BFLog.Log("unity - script: I got ImpressionSuccessEvent ToString(): " + impressionData.ToString());
|
|
BFLog.Log("unity - script: I got ImpressionSuccessEvent allData: " + impressionData.allData);
|
|
}
|
|
|
|
void ImpressionDataReadyEvent(IronSourceImpressionData impressionData)
|
|
{
|
|
double revenue = (double)impressionData.revenue;
|
|
BFLog.Log("unity - script: I got ImpressionDataReadyEvent ToString(): " + impressionData.ToString());
|
|
BFLog.Log("unity - script: I got ImpressionDataReadyEvent revenue.ToString(): " + revenue.ToString());
|
|
BFLog.Log("unity - script: I got ImpressionDataReadyEvent allData: " + impressionData.allData);
|
|
AdjustAdRevenue adjustAdRevenue = new AdjustAdRevenue(AdjustConfig.AdjustAdRevenueSourceIronSource);
|
|
adjustAdRevenue.setRevenue(revenue, "USD");
|
|
// optional fields
|
|
adjustAdRevenue.setAdRevenueNetwork(impressionData.adNetwork);
|
|
adjustAdRevenue.setAdRevenueUnit(impressionData.adUnit);
|
|
adjustAdRevenue.setAdRevenuePlacement(impressionData.placement);
|
|
// track Adjust ad revenue
|
|
Adjust.trackAdRevenue(adjustAdRevenue);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |