当前位置: 首页 > news >正文

[Unity] AppLovin Max接入Native 广告 Android篇

把下载下来的maxnativelibrary-release-文件放在Plugins/Android下
将这一行加入到mainTemplate.gradle文件中

 implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

添加下面的两个脚本

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class NativeSDKManager : MonoBehaviour
{public static NativeSDKManager Instance;#region IOSMethod#if UNITY_IOS[DllImport("__Internal")]internal extern static void IOSInitMax();[DllImport("__Internal")]internal extern static void IOSLoadNativeAd(string adId);[DllImport("__Internal")]internal extern static void IOSShowAd(string adId, int cd, bool hasRemoveAds);#endif#endregionAndroidJavaClass androidJava;AndroidJavaObject androidJavaObject;//public MaxPriceData NativePrice;//public MaxPriceData NativeNormalPrice;private MaxPriceData MaxInterPrice;private MaxPriceData MaxInterPrice2;private MaxPriceData MaxRewardPrice;private MaxPriceData NativePrice_1;private MaxPriceData NativePrice_2;private MaxPriceData NativePrice_3;private MaxPriceData NativePrice_4;private MaxPriceData NativePrice_5;private MaxPriceData NativePrice_6;private MaxPriceData NativePrice_7;private MaxPriceData NativePrice_8;private MaxPriceData NativePrice_9;private MaxPriceData NativePrice_10;#if UNITY_ANDROID//public const string adUnitId = "id";//public const string priceAdUnitId = "id";private const string priceADUnitId_1 = "id";private const string priceADUnitId_2 = "id";private const string priceADUnitId_3 = "id";private const string priceADUnitId_4 = "id";private const string priceADUnitId_5 = "id";private const string priceADUnitId_6 = "id";private const string priceADUnitId_7 = "id";private const string priceADUnitId_8 = "id";private const string priceADUnitId_9 = "id";private const string priceADUnitId_10 = "id";#elif UNITY_IOSpublic const string adUnitId = "id";public const string priceAdUnitId = "id";
#endifprivate bool m_useOnlyNative = false;void Awake(){DontDestroyOnLoad(gameObject);Instance = this;transform.name = "NativeSDK";
#if UNITY_ANDROIDandroidJava = new AndroidJavaClass("com.android.unityad.maxnativelibrary.AndroidUnityConnector");
#elif UNITY_IOS && !UNITY_EDITORIOSInitMax();
#endifMaxInterPrice = new MaxPriceData(AdMaxType.Interstitial_android, string.Empty, "Max插屏广告id");MaxInterPrice2 = new MaxPriceData(AdMaxType.Interstitial_android_new, string.Empty, "Max插屏广告2id");MaxRewardPrice = new MaxPriceData(AdMaxType.Reward_Android, string.Empty, "Max激励广告id");NativePrice_1 = new MaxPriceData(priceADUnitId_1, String.Empty, "原生比价id1", true);NativePrice_2 = new MaxPriceData(priceADUnitId_2, String.Empty, "原生比价id2", true);NativePrice_3 = new MaxPriceData(priceADUnitId_3, String.Empty, "原生比价id3", true);NativePrice_4 = new MaxPriceData(priceADUnitId_4, String.Empty, "原生比价id4", true);NativePrice_5 = new MaxPriceData(priceADUnitId_5, String.Empty, "原生比价id5", true);NativePrice_6 = new MaxPriceData(priceADUnitId_6, String.Empty, "原生比价id6", true);NativePrice_7 = new MaxPriceData(priceADUnitId_7, String.Empty, "原生比价id7", true);NativePrice_8 = new MaxPriceData(priceADUnitId_8, String.Empty, "原生比价id8", true);NativePrice_9 = new MaxPriceData(priceADUnitId_9, String.Empty, "原生比价id9", true);NativePrice_10 = new MaxPriceData(priceADUnitId_10, String.Empty, "原生比价id10", true);}void Start(){InitMax();}//ToAndroidpublic void InitMax(){
#if UNITY_ANDROIDDebug.Log(GlobalFunc.NativeFlag + "NativeSDKManager Call initNativeAd");androidJava.CallStatic("initMaxNativeAd");cacheNativeVideo();Debug.Log(GlobalFunc.NativeFlag + "NativeSDK Init Succeed");#endif}#region 请求广告public bool adRequest = false;public bool priceAdRequest = false;private void RequestPriceAd_1(){RequestPriceAd(priceADUnitId_1);}private void RequestPriceAd_2(){RequestPriceAd(priceADUnitId_2);}private void RequestPriceAd_3(){RequestPriceAd(priceADUnitId_3);}private void RequestPriceAd_4(){RequestPriceAd(priceADUnitId_4);}private void RequestPriceAd_5(){RequestPriceAd(priceADUnitId_5);}private void RequestPriceAd_6(){RequestPriceAd(priceADUnitId_6);}private void RequestPriceAd_7(){RequestPriceAd(priceADUnitId_7);}private void RequestPriceAd_8(){RequestPriceAd(priceADUnitId_8);}private void RequestPriceAd_9(){RequestPriceAd(priceADUnitId_9);}private void RequestPriceAd_10(){RequestPriceAd(priceADUnitId_10);}private void RequestPriceAd(string unitId){Debug.Log(GlobalFunc.NativeFlag + "RequestAdLoad Start" + unitId);AnalyticDataHelper.Track("native_request", new Dictionary<string, object>(){{"ad_unit_id", unitId},});
#if UNITY_ANDROIDandroidJava.CallStatic("loadNativeAd", unitId);
#elif UNITY_IOS && !UNITY_EDITORIOSLoadNativeAd(priceAdUnitId);
#endif}public void cacheNativeVideo(){BuryingPointMgr.Instance.SendShuShuAndFireBaseEvent(Event_DataType.ads_request,new Dictionary<string, object>(){{"ad_type","native"}});if (NativePrice_1.IsNullPrice()){RequestPriceAd_1();}if (NativePrice_2.IsNullPrice()){RequestPriceAd_2();}if (NativePrice_3.IsNullPrice()){RequestPriceAd_3();}if (NativePrice_4.IsNullPrice()){RequestPriceAd_4();}if (NativePrice_5.IsNullPrice()){RequestPriceAd_5();}if (NativePrice_6.IsNullPrice()){RequestPriceAd_6();}if (NativePrice_7.IsNullPrice()){RequestPriceAd_7();}if (NativePrice_8.IsNullPrice()){RequestPriceAd_8();}if (NativePrice_9.IsNullPrice()){RequestPriceAd_9();}if (NativePrice_10.IsNullPrice()){RequestPriceAd_10();}}#endregionenum AdLoadStatus{Idle,Loading,Done,}public enum AdType{Normal,Price,Price_1,Price_2,Price_3,Price_4,Price_5,Price_6,Price_7,Price_8,Price_9,Price_10,}private Action SuccCallback;private AdLoadStatus adLoadStatus = AdLoadStatus.Idle;public bool IsShow;public string NativeType = "native";/// <summary>/// 展示Native 唯一方法/// </summary>/// <param name="adUnitId"></param>/// <param name="nativeType"></param>/// <param name="failCallback"></param>/// <param name="succCallback"></param>public void ShowNativeAd(string adUnitId, string nativeType = "adi", Action failCallback = null,Action succCallback = null){GlobalFunc.SetOpenAdWaitTime(60);Debug.Log(GlobalFunc.NativeFlag + "RequestAdLoad Start is In" + adUnitId);if (IsShow) //如果正在展示还没关  就跳过{return;}adLoadStatus = AdLoadStatus.Loading;// if (adLoadStatus == AdLoadStatus.Loading)// {//     return;// }SuccCallback = succCallback;NativeType = nativeType;Debug.Log(GlobalFunc.NativeFlag + "ShowNativeAd Start");
#if UNITY_ANDROIDandroidJava.CallStatic("showAd", adUnitId, UIConstDataManger.Instance.NativeShowTime);
#elif UNITY_IOS && !UNITY_EDITORIOSShowAd(adUnitId,DataManager.NativeDisplayCD,false);
#endifDebug.Log(GlobalFunc.NativeFlag + "ShowNativeAd Succeed" + adUnitId);}#region 回调约定error string:  id*errorcode*error----------其他的:revenue*network*id------------------------------------------------------------------------------------public void AdRemoveCallBack(string str){Debug.Log(GlobalFunc.NativeFlag + "Receive Native AdRemoveCallBack" + str);string[] strs = str.Split('*');AnalyticDataHelper.Track("adremove_click", new Dictionary<string, object>(){{"page", "native"},});// UIRoot.Instance.RemoveAds();}public void AdClickedCallBack(string str){Debug.Log(GlobalFunc.NativeFlag + "Receive Native AdClickedCallBack" + str);string[] strs = str.Split('*');string ad_position = "";if (m_useOnlyNative){ad_position = "native";}else{if (m_useNativeInsteadAdv){ad_position = "adv";}else{ad_position = "adi";}}AnalyticDataHelper.Track("native_click", new Dictionary<string, object>(){{"page", WindowManager.ActiveWindow},{"event_situation", WindowManager.ActiveWindow},{"ad_position", ad_position},{"isNative", true},{"ad_unit_id", strs[2]},{"network", strs[1]}});}private int retryNative1Attempt = 0;private int retryNative2Attempt = 0;public void AdRequestErrorCallBack(string str){Debug.Log(GlobalFunc.NativeFlag + "Receive Native AdRequestErrorCallBack" + str);AdsManager.instance.mAdPlayState = AdPlayState.FAIL;string[] strs = str.Split('*');if (strs[0].Equals(priceADUnitId_1)){NativePrice_1.ResetPrice();}else if (strs[0].Equals(priceADUnitId_2)){NativePrice_2.ResetPrice();}else if (strs[0].Equals(priceADUnitId_3)){NativePrice_3.ResetPrice();}else if (strs[0].Equals(priceADUnitId_4)){NativePrice_4.ResetPrice();}else if (strs[0].Equals(priceADUnitId_5)){NativePrice_5.ResetPrice();}else if (strs[0].Equals(priceADUnitId_6)){NativePrice_6.ResetPrice();}else if (strs[0].Equals(priceADUnitId_7)){NativePrice_7.ResetPrice();}else if (strs[0].Equals(priceADUnitId_8)){NativePrice_8.ResetPrice();}else if (strs[0].Equals(priceADUnitId_9)){NativePrice_9.ResetPrice();}else if (strs[0].Equals(priceADUnitId_10)){NativePrice_10.ResetPrice();}else{//NativePrice.ResetPrice();double retryDelay = Mathf.Pow(2, retryNative2Attempt);retryNative2Attempt++;if (retryDelay > 64){retryDelay = 0;retryNative2Attempt = 0;}priceAdRequest = false;// Invoke("RequestPriceAdLoad", (float) retryDelay);}}//FromAndroidprivate int loadCount = 0;private int showCount = 0;private int requestCount = 0;public void AdRequestLoadedCallBack(string str){Debug.Log(GlobalFunc.NativeFlag + "Receive Native AdRequestLoadedCallBack CallBack" + str);string[] strs = str.Split('*');if (!string.IsNullOrEmpty(strs[0])){AdType adType = AdType.Normal;if (!string.IsNullOrEmpty(strs[2])){if (strs[2].Equals(priceADUnitId_1)){adType = AdType.Price_1;}else if (strs[2].Equals(priceADUnitId_2)){adType = AdType.Price_2;}else if (strs[2].Equals(priceADUnitId_3)){adType = AdType.Price_3;}else if (strs[2].Equals(priceADUnitId_4)){adType = AdType.Price_4;}else if (strs[2].Equals(priceADUnitId_5)){adType = AdType.Price_5;}else if (strs[2].Equals(priceADUnitId_6)){adType = AdType.Price_6;}else if (strs[2].Equals(priceADUnitId_7)){adType = AdType.Price_7;}else if (strs[2].Equals(priceADUnitId_8)){adType = AdType.Price_8;}else if (strs[2].Equals(priceADUnitId_9)){adType = AdType.Price_9;}else if (strs[2].Equals(priceADUnitId_10)){adType = AdType.Price_10;}}AnalyticDataHelper.Track("native_loaded", new Dictionary<string, object>(){{"ad_unit_id", strs[2]},});if (adType == AdType.Price_1){NativePrice_1.Price = strs[0];priceAdRequest = false;}else if (adType == AdType.Price_2){NativePrice_2.Price = strs[0];priceAdRequest = false;}else if (adType == AdType.Price_3){NativePrice_3.Price = strs[0];priceAdRequest = false;}else if (adType == AdType.Price_4){NativePrice_4.Price = strs[0];priceAdRequest = false;}else if (adType == AdType.Price_5){NativePrice_5.Price = strs[0];priceAdRequest = false;}else if (adType == AdType.Price_6){NativePrice_6.Price = strs[0];priceAdRequest = false;}else if (adType == AdType.Price_7){NativePrice_7.Price = strs[0];priceAdRequest = false;}else if (adType == AdType.Price_8){NativePrice_8.Price = strs[0];priceAdRequest = false;}else if (adType == AdType.Price_9){NativePrice_9.Price = strs[0];priceAdRequest = false;}else if (adType == AdType.Price_10){NativePrice_10.Price = strs[0];priceAdRequest = false;}BuryingPointMgr.Instance.SendShuShuAndFireBaseEvent(Event_DataType.ads_load_success,new Dictionary<string, object>(){{"ad_type","native"}});Debug.Log($"{GlobalFunc.NativeFlag} 拿到: {adType},价格:{strs[0]}");}}private System.DateTime mLastNativeTime;public void AdShowCallBack(string str){IsShow = true;
// #if UNITY_ANDROID//NativeSDK AdShowCallBack priceDebug.Log(GlobalFunc.NativeFlag + "Receive Native AdShowCallBack CallBack" + str);// (AdsManager.instance.mAdNetwork as AdMax).NativeDisplay();AdsManager.instance.mAdPlayState = AdPlayState.Load;string[] strs = str.Split('*');ADRevenue adRevenue = new ADRevenue{AdFormat = "native",Revenue = double.Parse(strs[0]),NetworkName = strs[1],AdUnitIdentifier = strs[2]};(AdsManager.instance.mAdNetwork as AdMax).OnNativeAdPaidEvent("", adRevenue);// AnalyticHelper.FireEvent(Event_Type.adi_show_success, new Dictionary<string, object>() {//         {"ad_position",WindowManager.ActiveWindow }//     });GlobalFunc.SetOpenAdWaitTime(60);string ad_position = "";if (m_useOnlyNative){ad_position = "native";}else{if (m_useNativeInsteadAdv){ad_position = "adv";}else{ad_position = "adi";}}BuryingPointMgr.Instance.SendShuShuAndFireBaseEvent(Event_DataType.ads_show_success,new Dictionary<string, object>(){{"ad_type","native"},{"source",AdsManager.instance.SourceType.ToString()},{"net_work",strs[1]},{"position", ad_position},{"isNative", true},{"ad_unit_id", strs[2]},{"type", NativeType}});AnalyticDataHelper.Track("native_show_success", new Dictionary<string, object>(){{"page", WindowManager.ActiveWindow},{"event_situation", WindowManager.ActiveWindow},{"ad_position", ad_position},{"position", ad_position},{"isNative", true},{"ad_unit_id", strs[2]},{"type", NativeType},{"network", strs[1]}});showCount++;Debug.Log(GlobalFunc.NativeFlag + "Times Show:" + showCount);
// #endif}public void AdCloseCallBack(string str){IsShow = false;
// #if UNITY_ANDROIDDebug.Log(GlobalFunc.NativeFlag + "Receive Native AdCloseCallBack" + str);adLoadStatus = AdLoadStatus.Done;AdsManager.instance.mAdPlayState = AdPlayState.CLOSE;if (NativeType.Equals("adi")){AdsManager.instance.m_LastIntersTime = System.DateTime.Now;}else if (NativeType.Equals("native")){mLastNativeTime = System.DateTime.Now;}SuccCallback?.Invoke();Debug.Log(GlobalFunc.NativeFlag + "mLastIntersTime=" + AdsManager.instance.m_LastIntersTime);GlobalFunc.SetOpenAdWaitTime(0);string[] strs = str.Split('*');Debug.Log(strs);if (strs[1].Equals(priceADUnitId_1)){NativePrice_1.ResetPrice();RequestPriceAd_1();}else if (strs[1].Equals(priceADUnitId_2)){NativePrice_2.ResetPrice();RequestPriceAd_2();}else if (strs[1].Equals(priceADUnitId_3)){NativePrice_3.ResetPrice();RequestPriceAd_3();}else if (strs[1].Equals(priceADUnitId_4)){NativePrice_4.ResetPrice();RequestPriceAd_4();}else if (strs[1].Equals(priceADUnitId_5)){NativePrice_5.ResetPrice();RequestPriceAd_5();}else if (strs[1].Equals(priceADUnitId_6)){NativePrice_6.ResetPrice();RequestPriceAd_6();}else if (strs[1].Equals(priceADUnitId_7)){NativePrice_7.ResetPrice();RequestPriceAd_7();}else if (strs[1].Equals(priceADUnitId_8)){NativePrice_8.ResetPrice();RequestPriceAd_8();}else if (strs[1].Equals(priceADUnitId_9)){NativePrice_9.ResetPrice();RequestPriceAd_9();}else if (strs[1].Equals(priceADUnitId_10)){NativePrice_10.ResetPrice();RequestPriceAd_10();}BuryingPointMgr.Instance.SendShuShuAndFireBaseEvent(Event_DataType.ads_request,new Dictionary<string, object>(){{"ad_type","native"}});Debug.LogError(GlobalFunc.NativeFlag + "广告关闭获取奖励" + m_useNativeInsteadAdv);if (m_useNativeInsteadAdv){// AdsManager.instance.RewardedVideoAdDidClose();// AdsManager.instance.RewardedVideoAdDidGiven(strs[1]);m_useNativeInsteadAdv = false;}else{// AdsManager.instance.InterstitialAdClosedEvent();}//GlobalFunc.OnNativeClose(strs[1]);}#endregionprivate List<MaxPriceData> ComparePrice = new List<MaxPriceData>(12);public MaxPriceDataNativeSDKPriceHigh(bool useInter = false, bool useReward = false) //useInter:插屏,useReward激励//都为False为native{m_useNativeInsteadAdv = useReward;ComparePrice.Clear();//bool isHigh = false;if (!useInter && !useReward){m_useOnlyNative = true;}else{m_useOnlyNative = false;}if (CheckRuByIp()) //‒ RU地区 adi双ID+Native10条ID 12个ID比价,展示最高价ID(这个ID是adi就播adi,是Naitve就播Naitve)‒ adv同理{if (useInter){if (!MaxInterPrice.IsNullPrice()){ComparePrice.Add(MaxInterPrice);Debug.Log($"{GlobalFunc.NativeFlag} 添加比价: {MaxInterPrice.Flag},价格:{MaxInterPrice.Price}");}if (!MaxInterPrice2.IsNullPrice()){ComparePrice.Add(MaxInterPrice2);Debug.Log($"{GlobalFunc.NativeFlag} 添加比价: {MaxInterPrice2.Flag},价格:{MaxInterPrice2.Price}");}}if (useReward){if (!MaxRewardPrice.IsNullPrice()){ComparePrice.Add(MaxRewardPrice);Debug.Log($"{GlobalFunc.NativeFlag} 添加比价: {MaxRewardPrice.Flag},价格:{MaxRewardPrice.Price}");}}}if (!this.NativePrice_1.IsNullPrice()){ComparePrice.Add(this.NativePrice_1);Debug.Log($"{GlobalFunc.NativeFlag} 添加比价: {NativePrice_1.Flag},价格:{NativePrice_1.Price}");}if (!this.NativePrice_2.IsNullPrice()){ComparePrice.Add(this.NativePrice_2);Debug.Log($"{GlobalFunc.NativeFlag} 添加比价: {NativePrice_2.Flag},价格:{NativePrice_2.Price}");}if (!this.NativePrice_3.IsNullPrice()){ComparePrice.Add(this.NativePrice_3);Debug.Log($"{GlobalFunc.NativeFlag} 添加比价: {NativePrice_3.Flag},价格:{NativePrice_3.Price}");}if (!this.NativePrice_4.IsNullPrice()){ComparePrice.Add(this.NativePrice_4);Debug.Log($"{GlobalFunc.NativeFlag} 添加比价: {NativePrice_4.Flag},价格:{NativePrice_4.Price}");}if (!this.NativePrice_5.IsNullPrice()){ComparePrice.Add(this.NativePrice_5);Debug.Log($"{GlobalFunc.NativeFlag} 添加比价: {NativePrice_5.Flag},价格:{NativePrice_5.Price}");}if (!this.NativePrice_6.IsNullPrice()){ComparePrice.Add(this.NativePrice_6);Debug.Log($"{GlobalFunc.NativeFlag} 添加比价: {NativePrice_6.Flag},价格:{NativePrice_6.Price}");}if (!this.NativePrice_7.IsNullPrice()){ComparePrice.Add(this.NativePrice_7);Debug.Log($"{GlobalFunc.NativeFlag} 添加比价: {NativePrice_7.Flag},价格:{NativePrice_7.Price}");}if (!this.NativePrice_8.IsNullPrice()){ComparePrice.Add(this.NativePrice_8);Debug.Log($"{GlobalFunc.NativeFlag} 添加比价: {NativePrice_8.Flag},价格:{NativePrice_8.Price}");}if (!this.NativePrice_9.IsNullPrice()){ComparePrice.Add(this.NativePrice_9);Debug.Log($"{GlobalFunc.NativeFlag} 添加比价: {NativePrice_9.Flag},价格:{NativePrice_9.Price}");}if (!this.NativePrice_10.IsNullPrice()){ComparePrice.Add(this.NativePrice_10);Debug.Log($"{GlobalFunc.NativeFlag} 添加比价: {NativePrice_10.Flag},价格:{NativePrice_10.Price}");}MaxPriceData data = null;if (ComparePrice.Count > 0){ComparePrice.Sort((x, y) => x.CompareTo(y));data = ComparePrice[0];}if (data != null){if (data.Native){string ad_position = "";if (m_useOnlyNative){ad_position = "native";}else{if (m_useNativeInsteadAdv){ad_position = "adv";}else{ad_position = "adi";}}AnalyticDataHelper.Track("native_shouldshow", new Dictionary<string, object>(){{"event_situation", WindowManager.ActiveWindow},{"ad_unit_id", data.adUnitId},{"type", NativeType},{"ad_position", ad_position}});}}else{if (!CheckRuByIp()){if (useInter){if (!MaxInterPrice.IsNullPrice()){data = MaxInterPrice;}else if (!MaxInterPrice2.IsNullPrice()){data = MaxInterPrice2;}}else if (useReward){if (!MaxRewardPrice.IsNullPrice()){data = MaxRewardPrice;}}}}Debug.Log($"  拿到最后比价获胜的是:{(data == null ? "无" : data.Flag)} {(data != null ? data.adUnitId : "kong")}");return data;}public bool CanShowNative(){return !NativePrice_1.IsNullPrice() ||!NativePrice_2.IsNullPrice() ||!NativePrice_3.IsNullPrice() ||!NativePrice_4.IsNullPrice() ||!NativePrice_5.IsNullPrice() ||!NativePrice_6.IsNullPrice() ||!NativePrice_7.IsNullPrice() ||!NativePrice_8.IsNullPrice() ||!NativePrice_9.IsNullPrice() ||!NativePrice_10.IsNullPrice();}public void SetMaxInterPrice(MaxSdkBase.AdInfo adInfo){if (adInfo.AdUnitIdentifier.Equals(MaxInterPrice.adUnitId)){MaxInterPrice.Price = adInfo.Revenue.ToString();}}public void SetMaxInterPrice2(MaxSdkBase.AdInfo adInfo){if (adInfo.AdUnitIdentifier.Equals(MaxInterPrice2.adUnitId)){MaxInterPrice2.Price = adInfo.Revenue.ToString();}}public void SetMaxRewardPrice(MaxSdkBase.AdInfo adInfo){if (adInfo.AdUnitIdentifier.Equals(MaxRewardPrice.adUnitId)){MaxRewardPrice.Price = adInfo.Revenue.ToString();}}private bool m_useNativeInsteadAdv = false;// public MaxPriceData MaxPrice2;public void SetMaxInterClosed(MaxSdkBase.AdInfo adInfo){if (adInfo.AdUnitIdentifier.Equals(MaxInterPrice.adUnitId)){MaxInterPrice.ResetPrice();}}public void SetMaxInter2Closed(MaxSdkBase.AdInfo adInfo){if (adInfo.AdUnitIdentifier.Equals(MaxInterPrice2.adUnitId)){MaxInterPrice2.ResetPrice();}}public void SetMaxRewardClosed(MaxSdkBase.AdInfo adInfo){if (adInfo.AdUnitIdentifier.Equals(MaxRewardPrice.adUnitId)){MaxRewardPrice.ResetPrice();}}public  bool ChechAdiTime(float interval=10){float time = GetShowIntersPastTime();Debug.Log(GlobalFunc.NativeFlag+"Nativeinterval="+time);return time >= interval|| time==0;}private float GetShowIntersPastTime(){return (float) (System.DateTime.Now - mLastNativeTime).TotalSeconds;}bool CheckRuByIp(){Debug.Log($"{GlobalFunc.NativeFlag}+IP:{DataManager.CountryCodeByIp}---NativePriority:{UIConstDataManger.Instance.NativePriority}");return DataManager.CountryCodeByIp.ToUpper().Equals("RU")||DataManager.CountryCodeByIp.ToUpper().Equals("IN") || UIConstDataManger.Instance.NativePriority == 0;}
}
using System;public class MaxPriceData:IComparable
{public string adUnitId;public string Price;public bool Native;public string Flag;public MaxPriceData(string adUnitId,string price,string flag,bool _native = false){this.adUnitId = adUnitId;this.Price = price;this.Native = _native;this.Flag = flag;}public bool IsNullPrice(){return string.IsNullOrEmpty(Price);}public void ResetPrice(){Price = string.Empty;}public void SetPrice(MaxSdkBase.AdInfo adInfo){if (adInfo.AdUnitIdentifier.Equals(MaxPrice1.adUnitId)){MaxPrice1.Price = adInfo.Revenue.ToString();}// if (adInfo.AdUnitIdentifier.Equals(MaxPrice2.adUnitId))// {//     MaxPrice2.Price = adInfo.Revenue.ToString();// }}public MaxPriceData MaxPrice1;// public MaxPriceData MaxPrice2;public void SetMaxClosed(MaxSdkBase.AdInfo adInfo){if (adInfo.AdUnitIdentifier.Equals(MaxPrice1.adUnitId)){MaxPrice1.ResetPrice();}// if (adInfo.AdUnitIdentifier.Equals(MaxPrice2.adUnitId))// {//     MaxPrice2.ResetPrice();// }}public int CompareTo(object obj){if (obj == null) return 1; // 当前对象总是比 null 大if (obj is not MaxPriceData other){return 1;}// Null 价格的处理:认为 Null 价格比非 Null 价格大if (this.IsNullPrice() && !other.IsNullPrice()){return 1; // 当前对象的 NullPrice 排在后面}if (!this.IsNullPrice() && other.IsNullPrice()){return -1; // 当前对象的非 NullPrice 排在前面}// 非 Null 价格比较if (!this.IsNullPrice() && !other.IsNullPrice()){// 使用 double.TryParse 保护解析if (double.TryParse(this.Price, out double thisPrice) && double.TryParse(other.Price, out double otherPrice)){// 降序比较:价格大的排前面return otherPrice.CompareTo(thisPrice);}else{// 如果解析失败,可根据需求定义逻辑,这里假设解析失败的价格最小if (!double.TryParse(this.Price, out _))return 1; // 当前对象解析失败,排后面if (!double.TryParse(other.Price, out _))return -1; // 对比对象解析失败,排后面}}// 如果两个价格都是 Null,则相等return 0;}}

展示最高价格的native

 public void ShowOnlyNative(string pos, System.Action succeessCallback = null,System.Action failCallback = null,int CD=-1){if (DataManager.hasRemoveAds || DataManager.IsVIP){failCallback?.Invoke();return;}if (CD>=0){if (!NativeSDKManager.Instance. ChechAdiTime(CD)){failCallback?.Invoke();return;}    }MaxPriceData maxPriceData;maxPriceData = NativeSDKManager.Instance.NativeSDKPriceHigh(false,false);if (maxPriceData!=null&&maxPriceData.Native){AnalyticDataHelper.Track("native_ready", new Dictionary<string, object>(){{"event_situation", pos},{"ad_unit_id", maxPriceData.adUnitId},});AnalyticDataHelper.Track("native_fill", new Dictionary<string, object>(){{"is_fill", 1},{"position", "native"}});AnalyticDataHelper.Track("should_show", new Dictionary<string, object>(){{"position", "native"},});NativeSDKManager.Instance.ShowNativeAd(maxPriceData.adUnitId,"native", failCallback,succeessCallback);return;}failCallback?.Invoke();AnalyticDataHelper.Track("native_fill", new Dictionary<string, object>(){{"is_fill", NativeSDKManager.Instance.CanShowNative()?1:0 },{"position", "native" },});AnalyticDataHelper.Track("should_show", new Dictionary<string, object>(){{"position", "native"},});}

加入adi adv native比价逻辑

在adi的OnAdLoadedEvent里设置adi的价格

if (adInfo.AdUnitIdentifier.Equals(AdMaxType.Interstitial_android_new)){NativeSDKManager.Instance.SetMaxInterPrice2(adInfo);Debug.Log(GlobalFunc.NativeFlag+"拿到MaxPrice2广告的价格" + adInfo.Revenue);//DataManager.networkNameAdi = adInfo.NetworkName;}else if (adInfo.AdUnitIdentifier.Equals(AdMaxType.Interstitial_android)){NativeSDKManager.Instance.SetMaxInterPrice(adInfo);Debug.Log(GlobalFunc.NativeFlag+"拿到MaxPrice广告的价格" +adInfo.Revenue);//DataManager.networkNameAdi = adinfo.NetworkName;}

在adi的OnAdHiddenEvent重置adi价格

if (adInfo.AdUnitIdentifier.Equals(AdMaxType.Interstitial_android_new)){NativeSDKManager.Instance.SetMaxInter2Closed(adInfo);}else{NativeSDKManager.Instance.SetMaxInterClosed(adInfo);}

在adv的OnAdLoadedEvent里设置adv的价格

NativeSDKManager.Instance.SetMaxRewardPrice(adInfo);

在adv的OnAdHiddenEvent重置adv价格

	NativeSDKManager.Instance.SetMaxRewardClosed(adInfo);

处理展示adi的方法

 maxPriceData = NativeSDKManager.Instance.NativeSDKPriceHigh(true,false);if (maxPriceData!=null&&maxPriceData.Native){AnalyticDataHelper.Track("native_fill", new Dictionary<string, object>(){{"is_fill", 1},{"position", "adi"}});AnalyticDataHelper.Track("should_show", new Dictionary<string, object>(){{"position", "adi"},});NativeSDKManager.Instance.ShowNativeAd(maxPriceData.adUnitId,"adi", failCallback,succeessCallback);return;}else if (maxPriceData!=null&&!maxPriceData.Native){//这里可以处理双adi}AnalyticDataHelper.Track("native_fill", new Dictionary<string, object>(){{"is_fill", NativeSDKManager.Instance.CanShowNative()?1:0 },{"position", "adi" },});AnalyticDataHelper.Track("should_show", new Dictionary<string, object>(){{"position", "adi"},});//走之前的adi逻辑

同理adv也是

 var data = NativeSDKManager.Instance.NativeSDKPriceHigh(false, true);if (data!=null && data.Native){AnalyticDataHelper.Track("native_fill", new Dictionary<string, object>(){{"is_fill", 1 },{"position", "adv"}});AnalyticDataHelper.Track("should_show", new Dictionary<string, object>(){{"position", "adv"},});NativeSDKManager.Instance.ShowNativeAd(data.adUnitId,"adv", () => { failCallback?.Invoke("");}, () =>{m_onRewardAdDidClose?.Invoke();});}else{AnalyticDataHelper.Track("native_fill", new Dictionary<string, object>(){{"is_fill", NativeSDKManager.Instance.CanShowNative()?1:0 },{"position", "adv"}});AnalyticDataHelper.Track("should_show", new Dictionary<string, object>(){{"position", "adv"},});//走之前的展示adv逻辑StartCoroutine(ShowADV(type, failCallback, source, wait));}

最后选择合适的时机加载Native 现在代码里只有初始化和关闭native才会加载

加入混淆

-keep class com.android.unityad.maxnativelibrary.** {*;}

相关文章:

[Unity] AppLovin Max接入Native 广告 Android篇

把下载下来的maxnativelibrary-release-文件放在Plugins/Android下 将这一行加入到mainTemplate.gradle文件中 implementation androidx.constraintlayout:constraintlayout:2.1.4添加下面的两个脚本 using System; using System.Collections; using System.Collections.Gener…...

Source Insight 4.0的安装

一、安装与破解 1、下载Source Insight 4.0安装包 https://pan.baidu.com/s/1t0u1RM19am0lyzhlNTqK9Q?pwdnvmk 2、下载程序破解补丁包 https://pan.baidu.com/s/1irvH-Kfwjf4zCCtWJByqJQ 其中包含文件si4.pediy.lic 和 sourceinsight4.exe。 3、安装下载的Source Insight …...

远程调试软件对比与使用推荐

远程调试软件对比与使用推荐 远程调试是现代软件开发中不可或缺的一部分&#xff0c;尤其是在处理分布式系统、云端服务或远程服务器上的问题时。以下是对几种常见远程调试工具的详细对比和推荐使用场景。 1. GDB (GNU Debugger) 特点 开源&#xff1a;完全免费且开源&…...

鸿蒙项目云捐助第二讲鸿蒙图文互动基本程序实现

鸿蒙项目云捐助第二讲鸿蒙图文互动基本程序实现 结合第一讲建立的“Hello World”程序&#xff0c;得到如下图所示的界面。 这里的“Hello World”是通过“Priview”显示出来的。在这个界面中进行开发的前奏曲&#xff0c;可以通过点击更换图片的案例来体会一下鸿蒙Next的开发…...

求解球面的一组正交标架

目录 求解球面的一组正交标架 求解球面的一组正交标架 球面 r ( u , v ) ( a cos ⁡ u cos ⁡ v , a cos ⁡ u sin ⁡ v , a sin ⁡ u ) \mathbf{r}(u,v)\left(a\cos u\cos v,a\cos u\sin v,a\sin u\right) r(u,v)(acosucosv,acosusinv,asinu), 求得 r u ( − a sin ⁡ u c…...

php.ini 文件上传/执行时间/部分配置新手教程

1、上传文件大小配置 一般需要同时配置“upload_max_filesize”、“post_max_size”&#xff0c;配置格式如下&#xff1a; file_uploads On ;是否允许HTTP文件上传 upload_max_filesize 2M ;设置单个文件上传的最大尺寸 post_max_size 8M ;设置 POST 请求体的最大尺寸&am…...

【Leetcode Top 100】102. 二叉树的层序遍历

问题背景 给你二叉树的根节点 r o o t root root&#xff0c;返回其节点值的 层序遍历 。 &#xff08;即逐层地&#xff0c;从左到右访问所有节点&#xff09;。 数据约束 树中节点数目在范围 [ 0 , 2000 ] [0, 2000] [0,2000] 内 − 1000 ≤ N o d e . v a l ≤ 1000 -1…...

【C++笔记】AVL树

前言 各位读者朋友们大家好&#xff0c;上期我们讲解了map和set这两大容器的使用&#xff0c;这一期我们讲解最早的平衡二叉搜索树——AVL树。 目录 前言一. AVL树的概念二. AVL树的实现2.1 AVL树的结构2.2 AVL树的插入2.2.1 AVL树插入一个值的大致过程2.2.2 平衡因子的更新2…...

【竞技宝】LOL:JDG官宣yagao离队

北京时间2024年12月13日,在英雄联盟S14全球总决赛结束之后,各大赛区都已经进入了休赛期,目前休赛期也快进入尾声,LPL大部分队伍都开始陆续官宣转会期的动向,其中JDG就在近期正式官宣中单选手yagao离队,而后者大概率将直接选择退役。 近日,JDG战队在官方微博上连续发布阵容变动消…...

双目摄像头标定方法

打开matlab 找到这个标定 将双目左右目拍的图像上传&#xff08;左右目最好不少于20张&#xff09; 等待即可 此时已经完成标定&#xff0c;左下角为反投影误差&#xff0c;右边为外参可视化 把这些误差大的删除即可。 点击导出 此时回到主页面&#xff0c;即可看到成功导出 Ca…...

相差不超过k的最多数,最长公共子序列(一),排序子序列,体操队形,青蛙过河

相差不超过k的最多数 链接:相差不超过k的最多数 来源&#xff1a;牛客网 题目描述&#xff1a; 给定一个数组&#xff0c;选择一些数&#xff0c;要求选择的数中任意两数差的绝对值不超过 &#x1d458; 。问最多能选择多少个数&#xff1f; 输入描述: 第一行输入两个正整…...

【自然语言处理与大模型】使用llama.cpp将HF格式大模型转换为GGUF格式

llama.cpp的主要目标是在本地和云端的各种硬件上以最小的设置和最先进的性能实现LLM推理。是一个专为大型语言模型&#xff08;LLM&#xff09;设计的高性能推理框架&#xff0c;完全使用C和C编写&#xff0c;没有外部依赖&#xff0c;这使得它可以很容易地被移植到不同的操作系…...

MongoDB存储照片和文件存储照片的区别在那里?

一、维度对比 比较维度MongoDB存储照片文件系统存储照片数据模型使用文档存储数据&#xff0c;可以存储不同结构的照片。以文件的形式存储照片&#xff0c;每个文件独立存在。性能高效的数据检索&#xff0c;适用于大规模应用程序中的高效检索和访问。但在处理大量高分辨率图片…...

协变量的概念

协变量的概念 协变量的概念 协变量(Covariate)是在统计分析和研究中,与因变量(被研究的主要变量)相关,并且可能对因变量产生影响的其他变量。它不是研究的主要关注对象,但需要在分析过程中被考虑进去,因为它可能会混淆或改变自变量与因变量之间的关系。举例说明 教育研…...

【[LeetCode每日一题】Leetcode 1768.交替合并字符串

Leetcode 1768.交替合并字符串 题目描述&#xff1a; 给定两个字符串 word1 和 word2&#xff0c;以交替的方式将它们合并成一个新的字符串。即&#xff0c;第一个字符来自 word1&#xff0c;第二个字符来自 word2&#xff0c;第三个字符来自 word1&#xff0c;依此类推。如果…...

SRT协议学习

SRT(Secure Reliable Transport)协议是一种开源的视频传输协议&#xff0c;旨在提供安全&#xff0c;可靠&#xff0c;低延迟的视频流传输。以下是SRT协议的一些关键的工作原理。 1 安全传输&#xff0c;SRT通过使用AES加密和数据完整性验证来确保数据的安全传输。它可以在不信…...

南昌大学《2024年837自动控制原理真题》 (完整版)

本文内容&#xff0c;全部选自自动化考研联盟的&#xff1a;《南昌大学873自控考研资料》的真题篇。后续会持续更新更多学校&#xff0c;更多年份的真题&#xff0c;记得关注哦~ 目录 2024年真题 Part1&#xff1a;2024年完整版真题 2024年真题...

ASP.NET Core 应用程序的启动与配置:Program.cs 文件的全面解析

ASP.NET Core 应用程序的启动与配置&#xff1a;Program.cs 文件的全面解析 Program.cs 是 ASP.NET Core 应用程序的入口点&#xff0c;负责应用程序的启动和配置。以下是 Program.cs 文件中完成的主要工作&#xff0c;按逻辑步骤进行总结&#xff1a; 1. 创建和配置主机环境…...

2020-12-02 数字过滤

缘由 C语言 数组&#xff1a;数字过滤-CSDN问答 void chuli(int n15236) {int aa[47]{0},j0,m0;while(n)aa[j]n%10,n/10;while(j)if(aa[--j]%2)m*10,maa[j];cout << m << ends; ​​​​​​​} void 数字过滤(int n 15236) {int aa[47]{0}, j 0, m 0;while (…...

长短期记忆神经网络(LSTM)介绍

1、应用现状 长短期记忆神经网络&#xff08;LSTM&#xff09;是一种特殊的循环神经网络(RNN)。原始的RNN在训练中&#xff0c;随着训练时间的加长以及网络层数的增多&#xff0c;很容易出现梯度爆炸或者梯度消失的问题&#xff0c;导致无法处理较长序列数据&#xff0c;从而无…...

XML Group端口详解

在XML数据映射过程中&#xff0c;经常需要对数据进行分组聚合操作。例如&#xff0c;当处理包含多个物料明细的XML文件时&#xff0c;可能需要将相同物料号的明细归为一组&#xff0c;或对相同物料号的数量进行求和计算。传统实现方式通常需要编写脚本代码&#xff0c;增加了开…...

未来机器人的大脑:如何用神经网络模拟器实现更智能的决策?

编辑&#xff1a;陈萍萍的公主一点人工一点智能 未来机器人的大脑&#xff1a;如何用神经网络模拟器实现更智能的决策&#xff1f;RWM通过双自回归机制有效解决了复合误差、部分可观测性和随机动力学等关键挑战&#xff0c;在不依赖领域特定归纳偏见的条件下实现了卓越的预测准…...

React 第五十五节 Router 中 useAsyncError的使用详解

前言 useAsyncError 是 React Router v6.4 引入的一个钩子&#xff0c;用于处理异步操作&#xff08;如数据加载&#xff09;中的错误。下面我将详细解释其用途并提供代码示例。 一、useAsyncError 用途 处理异步错误&#xff1a;捕获在 loader 或 action 中发生的异步错误替…...

进程地址空间(比特课总结)

一、进程地址空间 1. 环境变量 1 &#xff09;⽤户级环境变量与系统级环境变量 全局属性&#xff1a;环境变量具有全局属性&#xff0c;会被⼦进程继承。例如当bash启动⼦进程时&#xff0c;环 境变量会⾃动传递给⼦进程。 本地变量限制&#xff1a;本地变量只在当前进程(ba…...

简易版抽奖活动的设计技术方案

1.前言 本技术方案旨在设计一套完整且可靠的抽奖活动逻辑,确保抽奖活动能够公平、公正、公开地进行,同时满足高并发访问、数据安全存储与高效处理等需求,为用户提供流畅的抽奖体验,助力业务顺利开展。本方案将涵盖抽奖活动的整体架构设计、核心流程逻辑、关键功能实现以及…...

深入浅出:JavaScript 中的 `window.crypto.getRandomValues()` 方法

深入浅出&#xff1a;JavaScript 中的 window.crypto.getRandomValues() 方法 在现代 Web 开发中&#xff0c;随机数的生成看似简单&#xff0c;却隐藏着许多玄机。无论是生成密码、加密密钥&#xff0c;还是创建安全令牌&#xff0c;随机数的质量直接关系到系统的安全性。Jav…...

【网络安全产品大调研系列】2. 体验漏洞扫描

前言 2023 年漏洞扫描服务市场规模预计为 3.06&#xff08;十亿美元&#xff09;。漏洞扫描服务市场行业预计将从 2024 年的 3.48&#xff08;十亿美元&#xff09;增长到 2032 年的 9.54&#xff08;十亿美元&#xff09;。预测期内漏洞扫描服务市场 CAGR&#xff08;增长率&…...

STM32标准库-DMA直接存储器存取

文章目录 一、DMA1.1简介1.2存储器映像1.3DMA框图1.4DMA基本结构1.5DMA请求1.6数据宽度与对齐1.7数据转运DMA1.8ADC扫描模式DMA 二、数据转运DMA2.1接线图2.2代码2.3相关API 一、DMA 1.1简介 DMA&#xff08;Direct Memory Access&#xff09;直接存储器存取 DMA可以提供外设…...

LLM基础1_语言模型如何处理文本

基于GitHub项目&#xff1a;https://github.com/datawhalechina/llms-from-scratch-cn 工具介绍 tiktoken&#xff1a;OpenAI开发的专业"分词器" torch&#xff1a;Facebook开发的强力计算引擎&#xff0c;相当于超级计算器 理解词嵌入&#xff1a;给词语画"…...

tree 树组件大数据卡顿问题优化

问题背景 项目中有用到树组件用来做文件目录&#xff0c;但是由于这个树组件的节点越来越多&#xff0c;导致页面在滚动这个树组件的时候浏览器就很容易卡死。这种问题基本上都是因为dom节点太多&#xff0c;导致的浏览器卡顿&#xff0c;这里很明显就需要用到虚拟列表的技术&…...