增加sdk

This commit is contained in:
2026-07-14 10:20:45 +08:00
parent 20d09e4ebb
commit 57709d109d
1165 changed files with 59941 additions and 4485 deletions
@@ -3,119 +3,18 @@ using UnityEngine;
using AppsFlyerSDK;
using System.Collections.Generic;
#if UNITY_IOS && !UNITY_EDITOR
using Unity.Advertisement.IosSupport;
#endif
namespace ScrewsMaster
{
internal class AppsFlyerObjectScript1 : MonoBehaviour, IAppsFlyerConversionData
internal class AppsFlyerObjectScript1 : MonoBehaviour
{
public string appID = null;
public bool is_init = false;
void Start()
{
AppsFlyer.setIsDebug(true);
#if UNITY_IOS && !UNITY_EDITOR
appID = "6723880120";
StartCoroutine("loopWaitInitAf");
#endif
#if UNITY_EDITOR
NetworkDispatcher.Instance.Dispatch(NetworkMsg.Login);
#endif
}
#if UNITY_IOS && !UNITY_EDITOR
public IEnumerator loopWaitInitAf()
{
var reqData = new RespLoginFunnelData
{
type = "afSend",
payload = ""
};
NetworkKit.PostFunnelLogin(reqData);
float a = 0;
if (ATTrackingStatusBinding.GetAuthorizationTrackingStatus() ==
ATTrackingStatusBinding.AuthorizationTrackingStatus.NOT_DETERMINED)
{
ATTrackingStatusBinding.RequestAuthorizationTracking();
}
while ((ATTrackingStatusBinding.GetAuthorizationTrackingStatus() ==
ATTrackingStatusBinding.AuthorizationTrackingStatus.NOT_DETERMINED) && (a < 5.0f))
{
a += 0.5f;
yield return new WaitForSeconds(0.5f);
}
AppsFlyer.initSDK("Qrv4wCq6shkTP6x5SBtuZT", appID, this);
AppsFlyer.startSDK();
AppsFlyer.AFLog("8888888888888888888", ATTrackingStatusBinding.GetAuthorizationTrackingStatus().ToString());
//yield return new WaitForSeconds(0.5f);
}
#endif
public void onConversionDataSuccess(string conversionData)
{
if (is_init) return;
is_init = true;
AppsFlyer.AFLog("onConversionDataSuccess", conversionData);
Debug.Log("hunxiao0000000000000000000000-1");
var conversionDataDictionary = AppsFlyer.CallbackStringToDictionary(conversionData);
var json = SerializeUtil.ToJsonIndented(conversionDataDictionary);
Debug.Log("hunxiao0000000000000000000000-2");
SuperApplication.Instance.attribution =
conversionDataDictionary.TryGetValue("af_status", out var afStatus1)
? afStatus1.ToString().ToLower()
: "organic";
// Debug.Log("hunxiao0000000000000000000000");
NetworkDispatcher.Instance.Dispatch(NetworkMsg.Login);
var reqData = new RespLoginFunnelData
{
type = "afRecv",
payload = "true"
};
NetworkKit.PostFunnelLogin(reqData);
}
public void onConversionDataFail(string error)
{
if (is_init) return;
is_init = true;
AppsFlyer.AFLog("onConversionDataFail", error);
NetworkDispatcher.Instance.Dispatch(NetworkMsg.Login);
var reqData = new RespLoginFunnelData
{
type = "afRecv",
payload = "false"
};
NetworkKit.PostFunnelLogin(reqData);
}
public void onAppOpenAttribution(string attributionData)
{
AppsFlyer.AFLog("onAppOpenAttribution", attributionData);
Dictionary<string, object> attributionDataDictionary =
AppsFlyer.CallbackStringToDictionary(attributionData);
}
public void onAppOpenAttributionFailure(string error)
{
AppsFlyer.AFLog("onAppOpenAttributionFailure", error);
}
}
}
@@ -1,368 +1,109 @@
using System;
using System.Collections.Generic;
using AppsFlyerSDK;
using UnityEngine;
using UnityEngine.Events;
using static ScrewsMaster.NetworkKit;
using System.Collections.Generic;
using AppsFlyerSDK;
using MYp0ZVTT2QSDK;
using DG.Tweening;
namespace ScrewsMaster
{
public class MaxADKit
{
public static string SDKKey =
"oXM0CzVDi7P1HstOpKvFMInPMOzpQ9uA6t3x75q5f5wQvsEy9vuiiiM94ZJCJSV7PcZGroSSInQCTGsu04QEiE";
public static string interstitialADUnitID = "c1d96170d3f02c0e";
public static string rewardedADUnitID = "f9cf204de101065b";
private const float RevenueThreshold = 0.1f;
public static Dictionary<string, string> adCallbackInfo;
private static UnityAction<bool> _rewardedAdPlayCallback;
private static UnityAction<bool> _interstitialAdPlayCallback;
public static string user_id = "";
public static void Init()
{
MaxSdkCallbacks.OnSdkInitializedEvent += sdkConfiguration =>
#if !UNITY_EDITOR
// 注册 ab事件,0或1,0为自然量版本,1为激励版本
MYp0ZVTT2QSDKHelper.Instance.RegistIosParam((i =>
{
InitializeRewardedAds();
InitializeInterstitialAds();
};
SuperApplication.Instance.attribution = i == 0 ? "organic" : "non_organic";
// Debug.Log($"ios ab param : {i} attribution=== {BingoBea.Instance.attribution}");
NetworkDispatcher.Instance.Dispatch(NetworkMsg.Login);
}));
MaxSdk.SetSdkKey(SDKKey);
var loginModel = GameHelper.GetLoginModel();
user_id = loginModel.uid.ToString();
MaxSdk.SetUserId(user_id);
// MaxSdk.SetIsAgeRestrictedUser(false);
MaxSdk.SetHasUserConsent(true);
MaxSdk.SetDoNotSell(false);
MaxSdk.InitializeSdk();
#if !JarvisRelease
MaxSdk.ShowMediationDebugger();
#endif
adCallbackInfo = new Dictionary<string, string>();
}
#region 广
public static void ShowInterstitial(string placement = "DefaultInterstitial",
UnityAction<bool> onCompleted = null)
{
_interstitialAdPlayCallback = onCompleted;
if (MaxSdk.IsInterstitialReady(interstitialADUnitID))
void GameConfig(bool result, string config)
{
// Debug.Log($"广告已经准备好,播放");
MaxSdk.ShowInterstitial(interstitialADUnitID, placement);
// onCompleted?.Invoke(true);
Debug.Log($"************* game config result : {result}, config : {config}");
}
else
// SDK初始化方法
MYp0ZVTT2QSDKHelper.Instance.Init(null, null, GameConfig);
#endif
}
public static bool CheckInterstitialReady()
{
return MYp0ZVTT2QSDKHelper.Instance.IsInterReady();
}
public static void ShowInterstitial(string placement = "DefaultInterstitial", UnityAction<bool> onCompleted = null)
{
if (CheckInterstitialReady())
{
// Debug.Log($"广告准备好,播放");
_interstitialAdPlayCallback?.Invoke(false);
}
}
static int retryAttemptInterstitial;
public static void InitializeInterstitialAds()
{
MaxSdkCallbacks.Interstitial.OnAdLoadedEvent += OnInterstitialLoadedEvent;
MaxSdkCallbacks.Interstitial.OnAdLoadFailedEvent += OnInterstitialLoadFailedEvent;
MaxSdkCallbacks.Interstitial.OnAdDisplayedEvent += OnInterstitialDisplayedEvent;
MaxSdkCallbacks.Interstitial.OnAdClickedEvent += OnInterstitialClickedEvent;
MaxSdkCallbacks.Interstitial.OnAdHiddenEvent += OnInterstitialHiddenEvent;
MaxSdkCallbacks.Interstitial.OnAdDisplayFailedEvent += OnInterstitialAdFailedToDisplayEvent;
MaxSdkCallbacks.Interstitial.OnAdRevenuePaidEvent += OnAdRevenuePaidEvent;
LoadInterstitial();
}
private static void LoadInterstitial()
{
MaxSdk.LoadInterstitial(interstitialADUnitID);
}
private static void OnInterstitialLoadedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
{
retryAttemptInterstitial = 0;
}
private static void OnInterstitialLoadFailedEvent(string adUnitId, MaxSdkBase.ErrorInfo errorInfo)
{
retryAttemptInterstitial++;
double retryDelay = Math.Pow(2, Math.Min(6, retryAttemptInterstitial));
CrazyAsyKit.StartAction("LoadInterstitial", LoadInterstitial, (float)retryDelay);
}
private static void OnInterstitialDisplayedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
{
}
private static void OnInterstitialAdFailedToDisplayEvent(string adUnitId, MaxSdkBase.ErrorInfo errorInfo,
MaxSdkBase.AdInfo adInfo)
{
_interstitialAdPlayCallback?.Invoke(false);
LoadInterstitial();
}
private static void OnInterstitialClickedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
{
}
private static void OnInterstitialHiddenEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
{
_interstitialAdPlayCallback?.Invoke(true);
OnInterstitialAdRevenuePaidEvent(adUnitId, adInfo);
LoadInterstitial();
}
private static void OnInterstitialAdRevenuePaidEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
{
string countryCode = "USD";//MaxSdk.GetSdkConfiguration().CountryCode; // "US" for the United States, etc - Note: Do not confuse this with currency code which is "USD"
// //string networkName = adInfo.NetworkName; // Display name of the network that showed the ad
// // string adUnitIdentifier = adInfo.AdUnitIdentifier; // The MAX Ad Unit ID
// //string placement = adInfo.Placement; // The placement this ad's postbacks are tied to
// // string networkPlacement = adInfo.NetworkPlacement; // The placement ID from the network that showed the ad
adCallbackInfo.Clear();
var loginModel = GameHelper.GetLoginModel();
adCallbackInfo.Add("customer_user_id", loginModel.uid.ToString());
adCallbackInfo.Add("af_revenue", adInfo.Revenue.ToString());
adCallbackInfo.Add("af_currency", countryCode);
adCallbackInfo.Add("eventValue", "");
// //AppsFlyer.sendEvent("af_pay", adCallbackInfo);
double revenue = Convert.ToDouble(PlayerPrefs.GetString($"adInfoRevenue_{loginModel.uid}", "0")); revenue += adInfo.Revenue;
if (revenue >= RevenueThreshold)
{
adCallbackInfo["af_revenue"] = revenue.ToString();
//AppsFlyer.sendEvent("af_revenue", adCallbackInfo);
PlayerPrefs.SetString($"adInfoRevenue_{loginModel.uid}", "0");
bool isToday = CommonHelper.IsToday(loginModel.reg_time);
if (isToday)
Debug.Log($"广告已经准备好,播放");
MYp0ZVTT2QSDKHelper.Instance.ShowInter(placement, () =>
{
adCallbackInfo["af_new_revenue"] = revenue.ToString();
//AppsFlyer.sendEvent("af_purchase", adCallbackInfo);
}
DOVirtual.DelayedCall(0.1f, () =>
{
onCompleted?.Invoke(true);
});
});
}
else
{
PlayerPrefs.SetString($"adInfoRevenue_{loginModel.uid}", revenue.ToString());
Debug.Log($"广告未准备好,不播放");
onCompleted?.Invoke(false);
}
}
public static UnityAction<bool> onVideoAdCompleted = null;
private static string _placement = "";
private static Coroutine _waitForVideoAd = null;
#endregion
#region 广
public static bool CheckRewardedReady()
{
return MYp0ZVTT2QSDKHelper.Instance.IsVideoReady();
}
public static void ShowVideo(string placement = "DefaultVideo", UnityAction<bool> onCompleted = null)
{
_rewardedAdPlayCallback = onCompleted;
onVideoAdCompleted = onCompleted;
_placement = placement;
#if UNITY_EDITOR
_rewardedAdPlayCallback?.Invoke(true);
onVideoAdCompleted?.Invoke(true);
#else
if (MaxSdk.IsRewardedAdReady(rewardedADUnitID))
// TrackKit.SendEvent(VideoBehaviorTrack.Event, VideoBehaviorTrack.Property.watch_ad_people);
// TrackKit.SendEvent(VideoBehaviorTrack.Event, VideoBehaviorTrack.Property.Rewarded_videos_trigger_number);
if (CheckRewardedReady())
{
MaxSdk.ShowRewardedAd(rewardedADUnitID, placement);
// onCompleted?.Invoke(true);
MYp0ZVTT2QSDKHelper.Instance.ShowRewardVideo(_placement, b =>
{
DOVirtual.DelayedCall(0.1f, () =>
{
onVideoAdCompleted?.Invoke(b);
});
}, ()=>
{
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");
}
});
});
}
else
{
_rewardedAdPlayCallback?.Invoke(false);
onVideoAdCompleted?.Invoke(false);
}
#endif
}
static int retryAttempt;
public static void InitializeRewardedAds()
{
MaxSdkCallbacks.Rewarded.OnAdLoadedEvent += OnRewardedAdLoadedEvent;
MaxSdkCallbacks.Rewarded.OnAdLoadFailedEvent += OnRewardedAdLoadFailedEvent;
MaxSdkCallbacks.Rewarded.OnAdDisplayedEvent += OnRewardedAdDisplayedEvent;
MaxSdkCallbacks.Rewarded.OnAdClickedEvent += OnRewardedAdClickedEvent;
MaxSdkCallbacks.Rewarded.OnAdRevenuePaidEvent += OnRewardedAdRevenuePaidEvent;
MaxSdkCallbacks.Rewarded.OnAdHiddenEvent += OnRewardedAdHiddenEvent;
MaxSdkCallbacks.Rewarded.OnAdDisplayFailedEvent += OnRewardedAdFailedToDisplayEvent;
MaxSdkCallbacks.Rewarded.OnAdReceivedRewardEvent += OnRewardedAdReceivedRewardEvent;
MaxSdkCallbacks.Rewarded.OnAdRevenuePaidEvent += OnAdRevenuePaidEvent;
Debug.Log("InitializeRewardedAds");
LoadRewardedAd();
}
private static void LoadRewardedAd()
{
MaxSdk.LoadRewardedAd(rewardedADUnitID);
}
private static void OnAdRevenuePaidEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
{
string countryCode = "USD";
adCallbackInfo.Clear();
adCallbackInfo.Add("appsflyer_id", AppsFlyer.getAppsFlyerId());
adCallbackInfo.Add("customer_user_id", user_id);
adCallbackInfo.Add("af_currency", countryCode);
//广告收益上传(扣量)((用户累计收益大于0.1上报50%,50%可配置))
double revenue = Convert.ToDouble(PlayerPrefs.GetString($"adInfoRevenue_{user_id}", "0"));
revenue += adInfo.Revenue;
// Debug.Log($"revenue: {revenue} \n adInfo.Revenue: {adInfo.Revenue}");
if (revenue >= RevenueThreshold)
{
adCallbackInfo.Add("af_revenue", revenue.ToString());
AppsFlyer.sendEvent("af_ad_revenue", adCallbackInfo);
PlayerPrefs.SetString($"adInfoRevenue_{user_id}", "0");
int adrate = ConfigSystem.GetConfig<CommonModel>().adrate / 100;
double revenueAdrate = revenue * adrate;
adCallbackInfo["af_revenue"] = revenueAdrate.ToString();
AppsFlyer.sendEvent("Af_new_ad_revenue", adCallbackInfo);
}
else
{
PlayerPrefs.SetString($"adInfoRevenue_{user_id}", revenue.ToString());
}
int highSend;
if (!PlayerPrefs.HasKey($"sendHighRevenue_{user_id}"))
{
highSend = 0; // 如果不存在,则初始化为 0
}
else
{
highSend = PlayerPrefs.GetInt($"sendHighRevenue_{user_id}", 0); // 从 PlayerPrefs 中获取
}
// 判断是否需要发送高收入事件
// Debug.Log($"highSend=====: {highSend}");
if (highSend == 0)
{
float limitNum = GameHelper.GetCommonModel().afSendLimit;
var totalNum = Convert.ToDouble(PlayerPrefs.GetString($"adRevenueTotal_{user_id}", "0"));
totalNum += adInfo.Revenue;
// Debug.Log($"totalNum=====: {totalNum} {limitNum}");
if (totalNum >= limitNum)
{
GameHelper.sendHighRevenueToAF(); // 发送高收入事件
PlayerPrefs.SetInt($"sendHighRevenue_{user_id}", 1); // 标记已发送
}
else
{
PlayerPrefs.SetString($"adRevenueTotal_{user_id}", totalNum.ToString());
}
}
}
private static void OnRewardedAdLoadedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
{
retryAttempt = 0;
}
private static void OnRewardedAdLoadFailedEvent(string adUnitId, MaxSdkBase.ErrorInfo errorInfo)
{
retryAttempt++;
double retryDelay = Math.Pow(2, Math.Min(6, retryAttempt));
CrazyAsyKit.StartAction("LoadRewardedAd", LoadRewardedAd, (float)retryDelay);
}
private static void OnRewardedAdDisplayedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
{
}
private static void OnRewardedAdFailedToDisplayEvent(string adUnitId, MaxSdkBase.ErrorInfo errorInfo,
MaxSdkBase.AdInfo adInfo)
{
LoadRewardedAd();
}
private static void OnRewardedAdClickedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
{
}
private static void OnRewardedAdHiddenEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
{
LoadRewardedAd();
if (GameHelper.IsGiftSwitch() && !SaveData.GetSaveobject().is_get_removead && (UnityEngine.Random.Range(0, 100) < GameHelper.GetCommonModel().rewardinsertion))
{
NetworkKit.androidPointObject.@event = BuriedPointEvent.Apple_AD_event;
NetworkKit.androidPointObject.property = BuriedPointEvent.afterRewardAdShow;
NetworkKit.androidPointObject.n = 1;
NetworkKit.PostWithHeader<AndroidPointObject>("/event/incrN", androidPointObject, (isSuccess, obj) =>
{
});
GameHelper.ShowInterstitial("AfterReward");
}
}
private static void OnRewardedAdReceivedRewardEvent(string adUnitId, MaxSdk.Reward reward,
MaxSdkBase.AdInfo adInfo)
{
_rewardedAdPlayCallback?.Invoke(true);
_rewardedAdPlayCallback = null;
string countryCode = "USD";//MaxSdk.GetSdkConfiguration().CountryCode; // "US" for the United States, etc - Note: Do not confuse this with currency code which is "USD"
// //string networkName = adInfo.NetworkName; // Display name of the network that showed the ad
// // string adUnitIdentifier = adInfo.AdUnitIdentifier; // The MAX Ad Unit ID
// //string placement = adInfo.Placement; // The placement this ad's postbacks are tied to
// // string networkPlacement = adInfo.NetworkPlacement; // The placement ID from the network that showed the ad
adCallbackInfo.Clear();
var loginModel = GameHelper.GetLoginModel();
adCallbackInfo.Add("customer_user_id", loginModel.uid.ToString());
adCallbackInfo.Add("af_revenue", adInfo.Revenue.ToString());
adCallbackInfo.Add("af_currency", countryCode);
adCallbackInfo.Add("eventValue", "");
// //AppsFlyer.sendEvent("af_pay", adCallbackInfo);
double revenue = Convert.ToDouble(PlayerPrefs.GetString($"adInfoRevenue_{loginModel.uid}", "0"));
revenue += adInfo.Revenue;
if (revenue >= RevenueThreshold)
{
adCallbackInfo["af_revenue"] = revenue.ToString();
//AppsFlyer.sendEvent("af_revenue", adCallbackInfo);
PlayerPrefs.SetString($"adInfoRevenue_{loginModel.uid}", "0");
bool isToday = CommonHelper.IsToday(loginModel.reg_time);
if (isToday)
{
adCallbackInfo["af_new_revenue"] = revenue.ToString();
//AppsFlyer.sendEvent("af_purchase", adCallbackInfo);
}
}
else
{
PlayerPrefs.SetString($"adInfoRevenue_{loginModel.uid}", revenue.ToString());
}
}
private static void OnRewardedAdRevenuePaidEvent(string adUnitId, MaxSdkBase.AdInfo adInfo)
{
}
#endregion
}
}
+1 -4
View File
@@ -34,9 +34,6 @@ namespace ScrewsMaster
{
CtrlDispatcher.Instance.AddListener(CtrlMsg.Login_Succeed, OnLoginSucceed);
var isAssetBundleLoad = false;
#if !UNITY_EDITOR && UNITY_ANDROID
// MaxADKit.Init();
#endif
#if UNITY_EDITOR
isAssetBundleLoad = false;
@@ -57,7 +54,7 @@ namespace ScrewsMaster
{
OnInitAsset();
}
MaxADKit.Init();
AppDispatcher.Instance.AddListener(AppMsg.UI_LoadingInitAsset, OnInitAsset);
}
@@ -128,7 +128,7 @@ namespace ScrewsMaster
RequestHeart();
TimerHelper.UnscaleGeneral.AddLoopTimer(60, (timer) => { RequestHeart(); });
NetworkDispatcher.Instance.Dispatch(NetworkMsg.GetPlayData);
MaxADKit.Init();
// MaxADKit.Init();
}
private void TrackLoginActivity(bool isSuccess)