Files
RedHotRoast-ios/Assets/Scripts/ToolKit/SDK/MaxADKit.cs
T

115 lines
3.8 KiB
C#
Raw Normal View History

2026-04-22 09:52:55 +08:00
using DG.Tweening;
2026-05-27 10:41:05 +08:00
using TCJPLYRM1xJTSDK;
2026-04-22 09:52:55 +08:00
using UnityEngine;
using UnityEngine.Events;
namespace RedHotRoast
2026-04-22 09:52:55 +08:00
{
public class MaxADKit
{
public static void Init()
{
2026-05-20 14:29:11 +08:00
#if !UNITY_EDITOR
// 注册 ab事件,0或1,0为自然量版本,1为激励版本
2026-05-27 10:41:05 +08:00
TCJPLYRM1xJTSDKManager.Instance.RegistIosParam((i =>
2026-04-22 09:52:55 +08:00
{
2026-05-20 14:29:11 +08:00
SuperApplication.Instance.attribution = i == 0 ? "organic" : "non_organic";
Debug.Log($"ios ab param : {i} attribution=== {SuperApplication.Instance.attribution}");
NetworkDispatcher.Instance.Dispatch(NetworkMsg.Login);
}));
2026-04-22 09:52:55 +08:00
2026-05-20 14:29:11 +08:00
void GameConfig(bool result, string config)
{
Debug.Log($"************* game config result : {result}, config : {config}");
}
// SDK初始化方法
2026-05-27 10:41:05 +08:00
TCJPLYRM1xJTSDKManager.Instance.Init(null, null, GameConfig);
2026-05-20 14:29:11 +08:00
#endif
}
2026-05-20 14:29:11 +08:00
2026-05-27 10:41:05 +08:00
#region 插屏广告相关
2026-05-20 14:29:11 +08:00
public static bool CheckInterstitialReady()
{
2026-05-27 10:41:05 +08:00
return TCJPLYRM1xJTSDKManager.Instance.IsInterReady();
2026-05-20 14:29:11 +08:00
}
2026-05-27 10:41:05 +08:00
public static void ShowInterstitial(string placement = "DefaultInterstitial", UnityAction<bool> onCompleted = null)
2026-04-22 09:52:55 +08:00
{
2026-05-20 14:29:11 +08:00
if (CheckInterstitialReady())
2026-04-22 09:52:55 +08:00
{
2026-05-20 14:29:11 +08:00
Debug.Log($"广告已经准备好,播放");
2026-05-27 10:41:05 +08:00
TCJPLYRM1xJTSDKManager.Instance.ShowInter(placement, () =>
2026-05-20 14:29:11 +08:00
{
2026-05-27 10:41:05 +08:00
DOVirtual.DelayedCall(0.1f, () =>
{
onCompleted?.Invoke(true);
});
2026-05-20 14:29:11 +08:00
});
2026-04-22 09:52:55 +08:00
}
else
{
2026-05-20 14:29:11 +08:00
Debug.Log($"广告未准备好,不播放");
2026-04-22 09:52:55 +08:00
onCompleted?.Invoke(false);
}
}
2026-05-27 10:41:05 +08:00
2026-04-22 09:52:55 +08:00
#endregion
#region 激励视频广告相关
2026-04-22 09:52:55 +08:00
public static UnityAction<bool> onVideoAdCompleted = null;
private static string _placement = "";
private static Coroutine _waitForVideoAd = null;
2026-05-20 14:29:11 +08:00
public static bool CheckRewardedReady()
{
2026-05-27 10:41:05 +08:00
return TCJPLYRM1xJTSDKManager.Instance.IsVideoReady();
2026-05-20 14:29:11 +08:00
}
public static void ShowVideo(string placement = "DefaultVideo", UnityAction<bool> onCompleted = null)
2026-04-22 09:52:55 +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-22 09:52:55 +08:00
2026-05-20 14:29:11 +08:00
if (CheckRewardedReady())
{
2026-05-27 10:41:05 +08:00
TCJPLYRM1xJTSDKManager.Instance.ShowRewardVideo(_placement, b =>
2026-05-20 14:29:11 +08:00
{
2026-05-27 10:41:05 +08:00
DOVirtual.DelayedCall(0.1f, () =>
{
onVideoAdCompleted?.Invoke(b);
});
2026-05-20 14:29:11 +08:00
}, ()=>
{
2026-05-27 10:41:05 +08:00
DOVirtual.DelayedCall(0.2f, () =>
2026-05-20 14:29:11 +08:00
{
2026-05-27 10:41:05 +08:00
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-05-20 14:29:11 +08:00
});
2026-04-22 09:52:55 +08:00
}
else
{
2026-05-20 14:29:11 +08:00
onVideoAdCompleted?.Invoke(false);
2026-04-22 09:52:55 +08:00
}
#endif
2026-04-22 09:52:55 +08:00
}
#endregion
}
}