Files
BingoGrassland/Assets/BingoSun/Scripts/SDK/MaxADKit.cs
T

110 lines
3.6 KiB
C#
Raw Normal View History

2026-04-20 13:49:36 +08:00
using System;
using UnityEngine;
using UnityEngine.Events;
using BingoBrain.Core;
using System.Collections.Generic;
using AppsFlyerSDK;
2026-06-05 15:02:47 +08:00
using MYp0ZVTT2QSDK;
using DG.Tweening;
2026-04-20 13:49:36 +08:00
namespace BingoBrain.Core
{
public class MaxADKit
{
public static void Init()
{
2026-06-05 15:02:47 +08:00
#if !UNITY_EDITOR
// 注册 ab事件,0或1,0为自然量版本,1为激励版本
MYp0ZVTT2QSDKHelper.Instance.RegistIosParam((i =>
2026-04-20 13:49:36 +08:00
{
2026-06-05 15:02:47 +08:00
BingoBea.Instance.attribution = i == 0 ? "organic" : "non_organic";
Debug.Log($"ios ab param : {i} attribution=== {BingoBea.Instance.attribution}");
NetworkDispatcher.Instance.Dispatch(NetworkMsg.Login);
2026-04-20 13:49:36 +08:00
2026-06-05 15:02:47 +08:00
}));
2026-04-20 13:49:36 +08:00
2026-06-05 15:02:47 +08:00
void GameConfig(bool result, string config)
2026-04-20 13:49:36 +08:00
{
2026-06-05 15:02:47 +08:00
Debug.Log($"************* game config result : {result}, config : {config}");
2026-04-20 13:49:36 +08:00
}
2026-06-05 15:02:47 +08:00
// SDK初始化方法
MYp0ZVTT2QSDKHelper.Instance.Init(null, null, GameConfig);
#endif
2026-04-20 13:49:36 +08:00
}
2026-06-05 15:02:47 +08:00
public static bool CheckInterstitialReady()
2026-04-20 13:49:36 +08:00
{
2026-06-05 15:02:47 +08:00
return MYp0ZVTT2QSDKHelper.Instance.IsInterReady();
2026-04-20 13:49:36 +08:00
}
2026-06-05 15:02:47 +08:00
public static void ShowInterstitial(string placement = "DefaultInterstitial", UnityAction<bool> onCompleted = null)
2026-04-20 13:49:36 +08:00
{
2026-06-05 15:02:47 +08:00
if (CheckInterstitialReady())
2026-04-20 13:49:36 +08:00
{
2026-06-05 15:02:47 +08:00
Debug.Log($"广告已经准备好,播放");
MYp0ZVTT2QSDKHelper.Instance.ShowInter(placement, () =>
{
DOVirtual.DelayedCall(0.1f, () =>
{
onCompleted?.Invoke(true);
});
});
2026-04-20 13:49:36 +08:00
}
else
{
2026-06-05 15:02:47 +08:00
Debug.Log($"广告未准备好,不播放");
2026-04-20 13:49:36 +08:00
onCompleted?.Invoke(false);
}
}
2026-06-05 15:02:47 +08:00
public static UnityAction<bool> onVideoAdCompleted = null;
private static string _placement = "";
private static Coroutine _waitForVideoAd = null;
2026-04-20 13:49:36 +08:00
2026-06-05 15:02:47 +08:00
public static bool CheckRewardedReady()
2026-04-20 13:49:36 +08:00
{
2026-06-05 15:02:47 +08:00
return MYp0ZVTT2QSDKHelper.Instance.IsVideoReady();
2026-04-20 13:49:36 +08:00
}
2026-06-05 15:02:47 +08:00
public static void ShowVideo(string placement = "DefaultVideo", UnityAction<bool> onCompleted = null)
2026-04-20 13:49:36 +08:00
{
2026-06-05 15:02:47 +08:00
onVideoAdCompleted = onCompleted;
_placement = placement;
#if UNITY_EDITOR
onVideoAdCompleted?.Invoke(true);
#else
// TrackKit.SendEvent(VideoBehaviorTrack.Event, VideoBehaviorTrack.Property.watch_ad_people);
// TrackKit.SendEvent(VideoBehaviorTrack.Event, VideoBehaviorTrack.Property.Rewarded_videos_trigger_number);
2026-04-20 13:49:36 +08:00
2026-06-05 15:02:47 +08:00
if (CheckRewardedReady())
2026-04-20 13:49:36 +08:00
{
2026-06-05 15:02:47 +08:00
MYp0ZVTT2QSDKHelper.Instance.ShowRewardVideo(_placement, b =>
2026-04-20 13:49:36 +08:00
{
2026-06-05 15:02:47 +08:00
DOVirtual.DelayedCall(0.1f, () =>
{
onVideoAdCompleted?.Invoke(b);
});
}, ()=>
2026-04-20 13:49:36 +08:00
{
2026-06-05 15:02:47 +08:00
DOVirtual.DelayedCall(0.2f, () =>
{
Debug.Log($"激励广告关闭");
if (GameHelper.IsGiftSwitch() && !SaveData.GetSaveobject().is_get_removead && (UnityEngine.Random.Range(0, 100) < GameHelper.GetCommonModel().rewardinsertion))
{
// TrackKit.SendEvent(ADEventTrack.Event, ADEventTrack.Property.afterRewardAdShow);
GameHelper.ShowInterstitial("AfterReward");
}
});
});
2026-04-20 13:49:36 +08:00
}
2026-06-05 15:02:47 +08:00
else
2026-04-20 13:49:36 +08:00
{
2026-06-05 15:02:47 +08:00
onVideoAdCompleted?.Invoke(false);
2026-04-20 13:49:36 +08:00
}
2026-06-05 15:02:47 +08:00
#endif
2026-04-20 13:49:36 +08:00
}
}
2026-06-05 15:02:47 +08:00
2026-04-20 13:49:36 +08:00
}