[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.** {*;}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/64125.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Pytest测试用例使用小结

基础使用 Pytest 测试用例实现代码 import pytest from server.service import Servicepytest.fixture def service():return Service(logger)class TestService:classmethoddef setup_class(cls):"""初始化设置一次:return:"""logger.info(&q…

MyBatis-Plus 基础

教程 视频教程&#xff1a;https://www.bilibili.com/video/BV1Xu411A7tL 详细文档&#xff1a;https://b11et3un53m.feishu.cn/wiki/PsyawI04ei2FQykqfcPcmd7Dnsc 常见注解 MybatisPlus就是根据PO实体的信息来推断出表的信息&#xff0c;从而生成SQL的。默认情况下&#xf…

VMware Workstation Pro 17 下载 以及 安装 Ubuntu 20.04.6 Ubuntu 启用 root 登录

1、个人免费版本 VMware Workstation Pro 17 下载链接怎么找&#xff1f;直接咕咕 VMware 找到如下链接。链接如下&#xff1a;Workstation 和 Fusion 对个人使用完全免费&#xff0c;企业许可转向订阅 - VMware 中文博客 点进去链接之后你会看到如下&#xff0c;注意安装之后仍…

30、使用ESP8266跟SG90舵机制作四足蜘蛛机器人

目录 1、简介 2、使用例子 3、代码解析 4、资源下载 正文 1、简介 本篇使用ESP8266跟SG90舵机制作四足蜘蛛机器人,使用的180度舵机有8个,需要一块16路舵机控制板,也可以使用小一点的控制板8路也够了。下面开始今天的教程,源码在文章末尾自行下载,力求大家都能看懂。…

python 将数据保存到现有的Excel文件的新工作表

out_file ‘query.xlsx’ df1 pd.DataFrame(out_data) 若直接写入&#xff1a; df1.to_excel(out_file, indexFalse, sheet_name‘v5v7’) # 将第二个DataFrame保存到现有的Excel文件的新工作表 with pd.ExcelWriter(out_file, engine‘openpyxl’, mode‘a’) as writer:…

深度学习——激活函数、损失函数、优化器

深度学习——激活函数、损失函数、优化器 1、激活函数1.1、一些常见的激活函数1.1.1、sigmoid1.1.2、softmax1.1.3、tanh1.1.4、ReLU1.1.5、Leaky ReLU1.1.6、PReLU1.1.7、GeLU1.1.8、ELU 1.2、激活函数的特点1.2.1、非线性1.2.2、几乎处处可微1.2.3、计算简单1.2.4、非饱和性1…

智慧政务数据中台建设及运营解决方案

数据中台&#xff1a;政府数字化转型的引擎 数据中台作为政府数字化转型的核心驱动力&#xff0c;起源于美军的作战体系&#xff0c;强调高效、灵活与强大。它不仅促进了政府决策的科学性&#xff0c;还推动了政府服务的精细化与智能化。 数据中台的应用场景&#xff1a;数字…

webpack4 - 配置文件分离(详细教程)

webpack根据开发和生成环境一般可以将配置文件拆分&#xff0c;拆分dev和prod两种环境 |- package.json|- /build|- webpack.base.js|- webpack.dev.js|- webpack.prod.js在scripts里修改相应的命令 "dev": "webpack-dev-server --config build/webpack.dev.j…

单片机最小系统

若要系统正常运行&#xff0c;确保稳定工作&#xff0c;一个单片机系统最少需要四个部分&#xff1a;电源电路 单片机对工作电压是有要求的&#xff0c;如果电压过大&#xff0c;会烧坏&#xff0c;如果电压过小&#xff0c;无法运行。晶振电路 单片机的原子指令的执行依赖晶振…

计算机毕设-基于springboot的社区居民诊疗健康管理系统的设计与实现(附源码+lw+ppt+开题报告)

博主介绍&#xff1a;✌多个项目实战经验、多个大型网购商城开发经验、在某机构指导学员上千名、专注于本行业领域✌ 技术范围&#xff1a;Java实战项目、Python实战项目、微信小程序/安卓实战项目、爬虫大数据实战项目、Nodejs实战项目、PHP实战项目、.NET实战项目、Golang实战…

Pycharm访问MySQL数据库·上

1.MySQL驱动模块Connector #导入数据库的驱动工具 import mysql.connector #连接数据库必备的条件 config {"host": "localhost","port": 3306,"user": "root","password": "888888","database&…

【LLM】大模型领域相关博主博客

苏剑林 真神&#xff0c;无需多言 博客地址: https://spaces.ac.cn/ Lil’Log openai的大佬&#xff0c;涉及的领域非常广&#xff0c;擅长把某个方向系统地梳理出来 博客地址: https://lilianweng.github.io/tags/ Distill 通过生动的动图和可视化技术把技术细节解释清楚 博…

day11 性能测试(4)——Jmeter使用(黑马的完结,课程不全)直连数据库+逻辑控制器+定时器

【没有所谓的运气&#x1f36c;&#xff0c;只有绝对的努力✊】 目录 1、复习 1.1 断言&#xff08;3种&#xff09; 1.2 关联&#xff08;3种&#xff09; 1.3 录制脚本 2、Jmeter直连数据库 2.1 直连数据库——使用场景 2.2 直连数据库——操作步骤 2.2.1 案例1&…

React的状态管理库-Redux

核心思想&#xff1a;单一数据源、状态是只读的、以及使用纯函数更新状态。 组成部分 Store&#xff08;存储&#xff09; 应用的唯一状态容器&#xff0c;存储整个应用的状态树,使用 createStore() 创建。 getState()&#xff1a;获取当前状态。dispatch(action)&#xff…

解决MAC装win系统投屏失败问题(AMD显卡)

一、问题描述 电脑接上HDMI线后&#xff0c;电脑上能显示有外部显示器接入&#xff0c;但是外接显示器无投屏画面 二、已测试的方法 1 更改电脑分辨&#xff0c;结果无效 2 删除BootCamp&#xff0c;结果无效 3更新电脑系统&#xff0c;结果无效 4 在设备管理器中&#…

PWM调节DCDC参数计算原理

1、动态电压频率调整DVFS SOC芯片的核电压、GPU电压、NPU电压、GPU电压等&#xff0c;都会根据性能和实际应用场景来进行电压和频率的调整。 即动态电压频率调整DVFS&#xff08;Dynamic Voltage and Frequency scaling&#xff09;&#xff0c;优化性能和功耗。 比如某SOC在…

lc54螺旋矩阵——模拟

54. 螺旋矩阵 - 力扣&#xff08;LeetCode&#xff09; 就兜圈&#xff0c;先外层&#xff0c;再内层&#xff0c;每一圈&#xff0c;先上->右->下->左&#xff0c;要计算多少圈&#xff0c;观察规律就是行和列中更小的那个的二分之一&#xff0c;注意额外讨论下最后…

【C++】OOP(二):定义基类和派生类

15.2 定义基类和派生类 15.2.1 定义基类 我们首先完成 Quote 类的定义&#xff1a; #include <string>class Quote {public:Quote() default; // 默认构造函数Quote(const std::string &book, double sales_price):bookNo(book), price(sales_price) { }std::st…

面向对象设计规则和各类设计模式

面向对象设计&#xff08;Object-Oriented Design, OOD&#xff09;是一种软件设计方法论&#xff0c;它使用对象、类、继承、封装、多态等概念来组织代码。面向对象设计的核心目标是提高软件的可维护性、可扩展性和复用性。在面向对象设计中&#xff0c;遵循一定的设计原则和模…

做T和做T+0有什么区别

做T和做T0在股市中实际上有紧密的联系&#xff0c;但也有所区别。以下是对两者的详细比较&#xff1a; 一、定义与原理 做T&#xff1a; 广义上&#xff0c;做T指的是一种通过低买高卖或高卖低买来赚取差价的交易策略。这种策略可以应用于不同的交易周期&#xff0c;包括日内交…