mergemilitary/Assets/TKGSDK/UnitySDK/Scripts/ADSScripts/SDKInnerScripts/iOS/TGiOSAdmanager.cs

537 lines
13 KiB
C#
Raw Normal View History

2022-05-23 13:39:59 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.InteropServices;
using System;
public class TGiOSAdManager : MonoBehaviour
{
private static TGiOSAdManager s_instance;
public Action onAntiSuccessHander;
2022-05-27 16:06:04 +00:00
private System.Action<bool> m_userSourceCallback;
2022-05-23 13:39:59 +00:00
public static TGiOSAdManager Instance
{
get
{
if (s_instance == null)
{
GameObject TGGameObject = new GameObject
{
name = "AdObject"
};
s_instance = TGGameObject.AddComponent<TGiOSAdManager>();
DontDestroyOnLoad(TGGameObject);
}
return s_instance;
}
}
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK
[DllImport("__Internal")]
private static extern void initSDK(string appID, string appKey);
[DllImport("__Internal")]
private static extern void loadNativeBannerWithUnitId(string unitId);
[DllImport("__Internal")]
private static extern bool isReadyNativeBannerWithUnitId(string unitId);
[DllImport("__Internal")]
private static extern void showNativeBannerWithUnitId(string unitId);
[DllImport("__Internal")]
private static extern void setNativeBannerAlign(string align);
[DllImport("__Internal")]
private static extern void hideNativeBanner();
[DllImport("__Internal")]
private static extern void removeNativeBanner();
[DllImport("__Internal")]
private static extern void loadBannerWithUnitId(string unitId);
[DllImport("__Internal")]
private static extern bool isReadyBannerWithUnitId(string unitId);
[DllImport("__Internal")]
private static extern void showBannerWithUnitId(string unitId);
[DllImport("__Internal")]
private static extern void setBannerAlign(string align);
[DllImport("__Internal")]
private static extern void hideBanner();
[DllImport("__Internal")]
private static extern void removeBanner();
[DllImport("__Internal")]
private static extern void loadInterstitialWithUnitId(string unitId);
[DllImport("__Internal")]
private static extern bool isReadyInterstitialWithUnitId(string unitId);
[DllImport("__Internal")]
private static extern void showInterstitialWithUnitId(string unitId);
[DllImport("__Internal")]
private static extern void loadNativeWithUnitId(string unitId, float width, float height);
[DllImport("__Internal")]
private static extern bool isReadyNativeWithUnitId(string unitId);
2022-05-27 16:06:04 +00:00
#if IOS_CN
2022-05-23 13:39:59 +00:00
[DllImport("__Internal")]
private static extern void layoutNativeWithFrame(float x, float y, float width, float height);
2022-05-27 16:06:04 +00:00
#else
[DllImport("__Internal")]
private static extern void layoutNativeWithFrame(float x, float y, float width, float height,string adpos);
#endif
2022-05-23 13:39:59 +00:00
[DllImport("__Internal")]
private static extern void showNativeWithUnitId(string unitId);
[DllImport("__Internal")]
private static extern void removeNative();
[DllImport("__Internal")]
private static extern void loadRewardVideoWithUnitId(string unitId);
[DllImport("__Internal")]
private static extern bool isReadyRewardVideoWithUnitId(string unitId);
[DllImport("__Internal")]
private static extern void showRewardVideoWithUnitId(string unitId);
[DllImport("__Internal")]
private static extern void setLogEnable(bool enable);
[DllImport("__Internal")]
private static extern void updateConversionValue(string value);
#if IOS_CN
[DllImport("__Internal")]
private static extern void showAntiView();
[DllImport("__Internal")]
private static extern void newUserPassLevel();
#endif
2022-05-27 16:06:04 +00:00
#if !IOS_CN
[DllImport("__Internal")]
private static extern void getUserSource();
#endif
#endif
public void GetUserSource(System.Action<bool> _callback)
{
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK && !IOS_CN
m_userSourceCallback = _callback;
getUserSource();
2022-05-23 13:39:59 +00:00
#endif
2022-05-27 16:06:04 +00:00
}
/*
* 0
* 1
*/
public void onUserSource(string obj)
{
bool isTrue = obj == "0";
if (m_userSourceCallback != null) m_userSourceCallback(isTrue);
}
2022-05-23 13:39:59 +00:00
//新用户打点上报
public void NewUserPassLevel()
{
#if UNITY_IPHONE && !UNITY_EDITOR && IOS_CN
newUserPassLevel();
#endif
}
//实名认证弹框
public void ShowAntiView()
{
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK && IOS_CN
showAntiView();
#endif
}
//实名认证回调
// 用户授权回调
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void antiSuccessDelegate();
[AOT.MonoPInvokeCallback(typeof(antiSuccessDelegate))]
static void antiSuccessHandle()
{
Instance.onAntiSuccessHander?.Invoke();
}
//设置log开关
public void SetLogEnable(bool enable)
{
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK
setLogEnable(enable);
#endif
}
public void InitSDK(string appID, string appKey)
{
2022-05-27 16:06:04 +00:00
2022-05-23 13:39:59 +00:00
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK
2022-05-27 16:06:04 +00:00
TGUniversalFunc.onSetUserSourceListener_onSuccess += onUserSource;
2022-05-23 13:39:59 +00:00
initSDK(appID, appKey);
2022-05-27 16:06:04 +00:00
2022-05-23 13:39:59 +00:00
#endif
}
2022-05-27 16:06:04 +00:00
#region native banner
2022-05-23 13:39:59 +00:00
public void LoadNativeBannerWithUnitId(string unitId)
{
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK
loadNativeBannerWithUnitId(unitId);
#endif
}
public bool IsReadyNativeBannerWithUnitId(string unitId)
{
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK
return isReadyNativeBannerWithUnitId(unitId);
#else
return false;
#endif
}
public void SetNativeBannerAlign(string align)
{
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK
setNativeBannerAlign(align);
#endif
}
public void ShowNativeBannerWithUnitId(string unitId)
{
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK
showNativeBannerWithUnitId(unitId);
#endif
}
public void HideNativeBanner()
{
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK
hideNativeBanner();
#endif
}
public void RemoveNativeBanner()
{
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK
removeNativeBanner();
#endif
}
2022-05-27 16:06:04 +00:00
#endregion
2022-05-23 13:39:59 +00:00
2022-05-27 16:06:04 +00:00
#region banner
2022-05-23 13:39:59 +00:00
public void LoadBannerWithUnitId(string unitId)
{
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK
loadBannerWithUnitId(unitId);
#endif
}
public bool IsReadyBannerWithUnitId(string unitId)
{
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK
return isReadyBannerWithUnitId(unitId);
#else
return false;
#endif
}
public void SetBannerAlign(string align)
{
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK
setBannerAlign(align);
#endif
}
public void ShowBannerWithUnitId(string unitId)
{
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK
showBannerWithUnitId(unitId);
#endif
}
public void HideBanner()
{
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK
hideNativeBanner();
#endif
}
public void RemoveBanner()
{
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK
removeNativeBanner();
#endif
}
2022-05-27 16:06:04 +00:00
#endregion
2022-05-23 13:39:59 +00:00
2022-05-27 16:06:04 +00:00
#region interstitial
2022-05-23 13:39:59 +00:00
public void Loadinterstitial(string unitId)
{
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK
loadInterstitialWithUnitId(unitId);
#endif
}
public bool IsReadyinterstitial(string unitId)
{
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK
return isReadyInterstitialWithUnitId(unitId);
#else
return false;
#endif
}
public void Showinterstitial(string unitId)
{
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK
showInterstitialWithUnitId(unitId);
#endif
}
2022-05-27 16:06:04 +00:00
#endregion
2022-05-23 13:39:59 +00:00
2022-05-27 16:06:04 +00:00
#region native
2022-05-23 13:39:59 +00:00
public void LoadNative(string unitId, float width, float height)
{
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK
loadNativeWithUnitId(unitId, width, height);
#endif
2022-05-27 16:06:04 +00:00
2022-05-23 13:39:59 +00:00
}
2022-05-27 16:06:04 +00:00
public bool IsReadNative(string unitId)
2022-05-23 13:39:59 +00:00
{
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK
return isReadyNativeWithUnitId(unitId);
#else
return false;
#endif
2022-05-27 16:06:04 +00:00
2022-05-23 13:39:59 +00:00
}
2022-05-27 16:06:04 +00:00
public void ShowNative(float x, float y, float width, float height, string unitId, string adpos)
2022-05-23 13:39:59 +00:00
{
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK
2022-06-08 13:23:44 +00:00
#if IOS_CN
layoutNativeWithFrame(x, y, width, height);
#else
2022-05-27 16:06:04 +00:00
layoutNativeWithFrame(x, y, width, height,adpos);
2022-06-08 13:23:44 +00:00
#endif
2022-05-23 13:39:59 +00:00
showNativeWithUnitId(unitId);
#endif
}
public void RemoveNative()
{
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK
removeNative();
#endif
}
2022-05-27 16:06:04 +00:00
#endregion
2022-05-23 13:39:59 +00:00
2022-05-27 16:06:04 +00:00
#region rewardVideo
2022-05-23 13:39:59 +00:00
public void LoadVideo(string unitId)
{
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK
loadRewardVideoWithUnitId(unitId);
#endif
}
public bool IsReadyVideo(string unitId)
{
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK
return isReadyRewardVideoWithUnitId(unitId);
#else
return false;
#endif
}
public void ShowVideo(string unitId)
{
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK
showRewardVideoWithUnitId(unitId);
#endif
}
2022-05-27 16:06:04 +00:00
#endregion
2022-05-23 13:39:59 +00:00
2022-05-27 16:06:04 +00:00
#region
2022-05-23 13:39:59 +00:00
public void UpdateConversionValue(string value)
{
#if UNITY_IPHONE && !UNITY_EDITOR && !NO_SDK
updateConversionValue(value);
#endif
}
2022-05-27 16:06:04 +00:00
#endregion
2022-05-23 13:39:59 +00:00
2022-05-27 16:06:04 +00:00
#region
2022-05-23 13:39:59 +00:00
public void AntiSuccessCallback()
{
onAntiSuccessHander?.Invoke();
}
2022-05-27 16:06:04 +00:00
#endregion
public void TGGetUserSource(string obj)
{
TGUniversalFunc.onSetUserSourceListener_onSuccess?.Invoke(obj);
}
2022-05-23 13:39:59 +00:00
2022-05-27 16:06:04 +00:00
#region interstitialCallback
2022-05-23 13:39:59 +00:00
public void TGInterstitialAdLoad(string obj)
{
TGUniversalFunc.onSetInterstitialListener_onAdLoaded?.Invoke();
}
public void TGInterstitialAdLoadFail(string obj)
{
TGUniversalFunc.onSetInterstitialListener_onAdFailedToLoad?.Invoke();
}
public void TGInterstitialAdShow(string obj)
{
TGUniversalFunc.onSetInterstitialListener_onShowSuccess?.Invoke();
}
public void TGInterstitialAdsShowFail(string obj)
{
TGUniversalFunc.onSetInterstitialListener_onShowFailed?.Invoke();
}
public void TGInterstitialAdClose(string obj)
{
TGUniversalFunc.onSetInterstitialListener_onAdClosed?.Invoke();
}
public void TGInterstitialAdClick(string obj)
{
TGUniversalFunc.onSetInterstitialListener_onClick?.Invoke();
}
public void TGInterstitialAdsEndPlaying(string obj)
{
TGUniversalFunc.onSetInterstitialListener_onEndPlaying?.Invoke();
}
public void TGInterstitialAdFailedToPlay(string obj)
{
TGUniversalFunc.onSetInterstitialListener_onFailedToPlay?.Invoke();
}
public void TGInterstitialAdsStartPlayVideo(string obj)
{
TGUniversalFunc.onSetInterstitialListener_onStartPlayVideo?.Invoke();
}
2022-05-27 16:06:04 +00:00
#endregion
2022-05-23 13:39:59 +00:00
2022-05-27 16:06:04 +00:00
#region videoCallback
2022-05-23 13:39:59 +00:00
public void TGVideoAdLoaded(string obj)
{
TGUniversalFunc.onSetRewardListener_onRewardedVideoAdLoaded?.Invoke();
}
public void TGVideoAdLoadFail(string obj)
{
TGUniversalFunc.onSetRewardListener_onRewardedVideoAdFailedToLoad?.Invoke();
}
public void TGVideoAdPlayStart(string obj)
{
TGUniversalFunc.onSetRewardListener_onRewardedVideoStarted?.Invoke();
}
public void TGVideoAdPlayEnd(string obj)
{
TGUniversalFunc.onSetRewardListener_onRewardedVideoAdEnd?.Invoke();
}
public void TGVideoAdPlayFail(string obj)
{
TGUniversalFunc.onSetRewardListener_onRewardedVideoAdPlayFail?.Invoke();
}
public void TGVideoAdPlayClosed(string isRewardStr)
{
TGUniversalFunc.onSetRewardListener_onRewardedVideoAdClosed?.Invoke(isRewardStr);
}
public void TGVideoAdPlayClicked(string obj)
{
TGUniversalFunc.onSetRewardListener_onRewardedVideoClickAd?.Invoke();
}
public void TGVideoAdDidRewardedSuccess(string obj)
{
TGUniversalFunc.onSetRewardListener_onRewarded?.Invoke();
}
2022-05-27 16:06:04 +00:00
#endregion
2022-05-23 13:39:59 +00:00
2022-05-27 16:06:04 +00:00
#region bannerCallback
2022-05-23 13:39:59 +00:00
public void TGBannerAdLoad(string obj)
{
TGUniversalFunc.onSetBannerListener_onAdLoaded?.Invoke();
}
public void TGBannerAdLoadFail(string obj)
{
TGUniversalFunc.onSetBannerListener_onAdFailedToLoad?.Invoke();
}
public void TGBannerAdDidShow(string obj)
{
TGUniversalFunc.onSetBannerListener_onShowSuccess?.Invoke();
}
public void TGBannerAdDidClick(string obj)
{
TGUniversalFunc.onSetBannerListener_onClick?.Invoke();
}
public void TGBannerAdDidClickCloseButton(string obj)
{
TGUniversalFunc.onSetBannerListener_onAdClosed?.Invoke();
}
2022-05-27 16:06:04 +00:00
#endregion
2022-05-23 13:39:59 +00:00
2022-05-27 16:06:04 +00:00
#region nativeCallback
2022-05-23 13:39:59 +00:00
public void TGNativeAdLoadFail(string obj)
{
TGUniversalFunc.onSetNativeListener_onAdFailedToLoad?.Invoke();
}
public void TGNativeAdLoaded(string obj)
{
TGUniversalFunc.onSetNativeListener_onAdLoaded?.Invoke();
}
public void TGNativeAdDidShow(string obj)
{
TGUniversalFunc.onSetNativeListener_onShowSuccess?.Invoke();
}
public void TGNativeAdDidClick(string obj)
{
TGUniversalFunc.onSetNativeListener_onClick?.Invoke();
}
2022-05-27 16:06:04 +00:00
#endregion
2022-05-23 13:39:59 +00:00
2022-05-27 16:06:04 +00:00
#region native banner
2022-05-23 13:39:59 +00:00
public void TGNativeBannerAdLoad(string obj)
{
TGUniversalFunc.onSetNativeBannerListener_onAdLoaded?.Invoke();
}
public void TGNativeBannerAdLoadFail(string obj)
{
TGUniversalFunc.onSetNativeBannerListener_onAdLoadFail?.Invoke();
}
2022-05-27 16:06:04 +00:00
#endregion
2022-05-23 13:39:59 +00:00
}