mergemilitary/Assets/TKGSDK/Common/internal/iOS/TGiOSAdmanager.cs

695 lines
19 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#if UNITY_IOS
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.InteropServices;
using System;
using Touka;
using System.Text;
public class TGiOSAdManager : MonoBehaviour
{
private static TGiOSAdManager s_instance;
public Action onAntiSuccessHander;
private System.Action<bool, string> m_userSourceCallback;
/// <summary>
/// show picture cross
/// </summary>
public bool showPictureCross()
{
return TKG_ShowPictureCross();
}
/// <summary>
/// remove picture cross
/// </summary>
public void removePictureCross()
{
TKG_RemovePictureCross();
}
/// <summary>
/// show more game icon
/// </summary>
public bool showMoreGameIcon()
{
return TKG_ShowMoreGameIcon();
}
/// <summary>
/// remove more game icon
/// </summary>
public void removeMoreGameIcon()
{
TKG_RemoveMoreGameIcon();
}
public void InitSDK()
{
// 暂停恢复声音
pauseGameDelegate handler = new pauseGameDelegate(pauseGameHandle);
IntPtr pauseGame = Marshal.GetFunctionPointerForDelegate(handler);
pauseGameCallback(pauseGame);
// 初始化设置
initSDKDelegate inithandler = new initSDKDelegate(initSDKHandle);
IntPtr initSdk = Marshal.GetFunctionPointerForDelegate(inithandler);
initSDKCallback(initSdk);
// 用户来源设置
TKG_UsersourceDelegate usHandler = new TKG_UsersourceDelegate(userSourceHandle);
IntPtr us = Marshal.GetFunctionPointerForDelegate(usHandler);
userSourceCallback(us);
// function Switch
TKG_FunctionSwitchDelegate funcHandler = new TKG_FunctionSwitchDelegate(functionSwitchHandle);
IntPtr func = Marshal.GetFunctionPointerForDelegate(funcHandler);
funcSwitchCallback(func);
// rv close
rewardCloseDelegate rvCloseHandler = new rewardCloseDelegate(rewardAdCloseHandle);
IntPtr rewardClose = Marshal.GetFunctionPointerForDelegate(rvCloseHandler);
rewardAdCloseCallback(rewardClose);
// show fail
rewardShowFailDelegate rvfailHandler = new rewardShowFailDelegate(rewardAdShowFailHandle);
IntPtr rewardShowFail = Marshal.GetFunctionPointerForDelegate(rvfailHandler);
rewardAdShowFailCallback(rewardShowFail);
// iv close
interCloseDelegate ivCloseHandler = new interCloseDelegate(interAdCloseHandle);
IntPtr interClose = Marshal.GetFunctionPointerForDelegate(ivCloseHandler);
interAdCloseCallback(interClose);
// rv click
rewardClickDelegate rvClickHandler = new rewardClickDelegate(rewardAdClickHandle);
IntPtr rvClick = Marshal.GetFunctionPointerForDelegate(rvClickHandler);
rewardAdClickCallback(rvClick);
TKG_InitSDK();
}
// 注册事件
public void setFunctions(string funcs)
{
TKG_SetFuncs(funcs);
}
// 通知
public void registAPNS()
{
TKG_RegistAPNS();
}
public void registNotification(string notiId, string body, string fireDate, int badge, string title, string subTitle)
{
TKG_RegistNotification(notiId,body,fireDate,badge,title,subTitle);
}
public void removeNotification(string notiId)
{
TKG_RemoveNotification(notiId);
}
public void removeAllNotifications()
{
TKG_RemoveAllNotification();
}
// 震动
public void shake(int mType, float mIntensity = 1)
{
TKG_Shake(mType,mIntensity);
}
public void share(string _shareText)
{
TKG_Share(_shareText);
}
// 获取渠道
public int getChannel()
{
return TKG_GetChannel();
}
// ads
public void RemoveAllAds()
{
TKG_RemoveAds();
}
//banner
public void LoadBanner()
{
TKG_LoadBanner();
}
public bool IsReadyBanner()
{
return TKG_IsReadyBanner();
}
public void ShowBanner(int align)
{
TKG_ShowBanner(align);
}
public void HideBanner()
{
TKG_HideBanner();
}
// iv
public void LoadIntersititial()
{
TKG_LoadIntersititial();
}
public bool IsReadyIntersititial()
{
return TKG_IsReadyIntersititial();
}
public void ShowIntersititial(string _adPos, int ivType)
{
TKG_ShowIntersititial(_adPos,ivType);
}
// rv
public void LoadRewardVideo()
{
TKG_LoadRewardVideo();
}
public bool IsReadyRewardVideo()
{
return TKG_IsReadyRewardVideo();
}
public void ShowRewardVideo(string adPos)
{
TKG_ShowRewardVideo(adPos);
}
public void ShowSDKToast(bool _show)
{
TKG_ShowSDKToast(_show);
}
// native
public void LoadNative(float width, float height)
{
TKG_LoadNative(width, height);
}
public bool IsReadyNative()
{
return TKG_IsReadyNative();
}
public void ShowNative(RectTransform pRect, Camera pCam = null, string pAdPos = "")
{
TKG_TurnNativePosition(pRect, pCam, pAdPos);
}
public void RemoveNative()
{
TKG_RemoveNative();
}
// other
public void Review()
{
TKG_Review();
}
public void OpenPrivacyURL()
{
TKG_OpenPrivacyURL();
}
public void OpenUserTermURL()
{
TKG_OpenUserTermURL();
}
public void OpenPolicyPop()
{
TKG_OpenPolicyPop();
}
public void OpenMoreGame()
{
TKG_OpenMoreGame();
}
public void Toast(string content)
{
TKG_Toast(content);
}
// 在线参数
public int GetConfigInt(string key, int defaultValue)
{
return TKG_GetConfigInt(key, defaultValue);
}
public string GetConfigString(string key, string defaultValue)
{
return TKG_GetConfigString(key, defaultValue);
}
public bool GetConfigBool(string key, bool defaultValue)
{
return TKG_GetConfigBool(key, defaultValue);
}
// 游戏事件上报
public void onEvent_GameStart(string levelId)
{
TKG_OnEvent_GameStart(levelId);
}
public void onEvent_GameEnd(string levelId, int result)
{
TKG_OnEvent_GameEnd(levelId,result);
}
// umeng 事件上报
public void onEvent_UMeng(string eventSort)
{
TKG_OnEvent_UMeng1(eventSort);
}
public void onEvent_UMeng(string eventSort, Dictionary<string, string> _keyValues)
{
TKG_OnEvent_UMeng2(eventSort, TKG_DictionaryToJson(_keyValues));
}
public void onEvent_UMeng(string eventSort,string key,string value)
{
TKG_OnEvent_UMeng3(eventSort,key,value);
}
public void onEvent_UMeng(string eventSort, string key1, string value1,string key2,string value2)
{
TKG_OnEvent_UMeng4(eventSort, key1, value1,key2,value2);
}
// tenjin事件上报
public void onEvent_Tenjin(int eventType)
{
TKG_OnEvent_Tenjin(eventType);
}
// unity 字典转 json string
static string TKG_DictionaryToJson(Dictionary<string, string> dict)
{
var builder = new StringBuilder("{");
foreach (KeyValuePair<string, string> kv in dict)
{
builder.AppendFormat("\"{0}\":\"{1}\",", kv.Key, kv.Value);
}
builder[builder.Length - 1] = '}';
return builder.ToString();
}
// 坐标转换
public void TKG_TurnNativePosition(RectTransform pRect, Camera pCam = null, string pAdPos = "")
{
Vector3[] tWorldCorners = new Vector3[4];
pRect.GetWorldCorners(tWorldCorners);
Vector2 tTopLeft = RectTransformUtility.WorldToScreenPoint(pCam, tWorldCorners[1]);
Vector2 tBottomRight = RectTransformUtility.WorldToScreenPoint(pCam, tWorldCorners[3]);
float tWidth = Mathf.Abs(tBottomRight.x - tTopLeft.x);
float tHeight = Mathf.Abs(tBottomRight.y - tTopLeft.y);
//Debug.Log("x:" + tTopLeft.x + "y:" + (Screen.height - tTopLeft.y) + "width" + tWidth + "hei:" + tHeight);
TKG_ShowNative(tTopLeft.x, Screen.height - tTopLeft.y, tWidth, tHeight, pAdPos);
}
// callback
// iv callback
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void interCloseDelegate();
[AOT.MonoPInvokeCallback(typeof(interCloseDelegate))]
static void interAdCloseHandle()
{
if (TKGSDKCallback.mInterAdCallback != null)
{
TKGSDKCallback.mInterAdCallback.Invoke();
TKGSDKCallback.mInterAdCallback = null;
}
}
// rv close-reward callback
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void rewardCloseDelegate(bool isReward);
[AOT.MonoPInvokeCallback(typeof(rewardCloseDelegate))]
static void rewardAdCloseHandle(bool isReward)
{
if (isReward)
{
if (TKGSDKCallback.mRewardCallback != null)
{
TKGSDKCallback.mRewardCallback.Invoke(true);
TKGSDKCallback.mRewardCallback = null;
}
}
else
{
if (TKGSDKCallback.mRewardCallback != null)
{
TKGSDKCallback.mRewardCallback.Invoke(false);
TKGSDKCallback.mRewardCallback = null;
}
}
}
// rv show fail callback
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void rewardShowFailDelegate();
[AOT.MonoPInvokeCallback(typeof(rewardShowFailDelegate))]
static void rewardAdShowFailHandle()
{
if (TKGSDKCallback.mRewardShowFailedCallback != null)
{
TKGSDKCallback.mRewardShowFailedCallback();
TKGSDKCallback.mRewardShowFailedCallback = null;
}
}
// rv click callback
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void rewardClickDelegate();
[AOT.MonoPInvokeCallback(typeof(rewardClickDelegate))]
static void rewardAdClickHandle()
{
if (TKGSDKCallback.mRewardClickCallback != null)
{
TKGSDKCallback.mRewardClickCallback();
}
}
// pause game
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void pauseGameDelegate(bool m_pause);
[AOT.MonoPInvokeCallback(typeof(pauseGameDelegate))]
static void pauseGameHandle(bool m_pause)
{
TKGSDKCallback.mGameFocusCallback?.Invoke(!m_pause);
}
// init sdk
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void initSDKDelegate();
[AOT.MonoPInvokeCallback(typeof(initSDKDelegate))]
static void initSDKHandle()
{
if (TKGSDKCallback.mInitCallback != null)
{
TKGSDKCallback.mInitCallback();
TKGSDKCallback.mInitCallback = null;
}
}
// user source
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void TKG_UsersourceDelegate(bool isOrganic,string source,string campaignName);
[AOT.MonoPInvokeCallback(typeof(TKG_UsersourceDelegate))]
static void userSourceHandle(bool isOrganic, string source,string campaignName)
{
if (TKGSDKCallback.mTKGUserSourceCallback != null)
{
TKGSDKCallback.mTKGUserSourceCallback(isOrganic,source);
TKGSDKCallback.mTKGUserSourceCallback = null;
}
if (TKGSDKCallback.mTKGUserSourceCallbackWithCampaignName != null)
{
TKGSDKCallback.mTKGUserSourceCallbackWithCampaignName(isOrganic,source, campaignName);
TKGSDKCallback.mTKGUserSourceCallbackWithCampaignName = null;
}
}
// set func
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void TKG_FunctionSwitchDelegate(string funcT, string funcS);
[AOT.MonoPInvokeCallback(typeof(TKG_FunctionSwitchDelegate))]
static void functionSwitchHandle(string funcType, string funcSwitch)
{
Debug.Log("yangwu unity log 回调到unity里"+funcType+"sw:"+funcSwitch);
if (TKGSDKCallback.mFunctionSwitchCalllback != null)
{
FunctionType enumType = (FunctionType)Enum.Parse(typeof(FunctionType), funcType);
if (TKGSDKCallback.mFunctionSwitchCalllback != null)
{
bool res = funcSwitch == "1" ? true : false;
TKGSDKCallback.mFunctionSwitchCalllback.Invoke(enumType, res);
}
}
}
// dll
[DllImport("__Internal")]
private static extern bool TKG_ShowPictureCross();
[DllImport("__Internal")]
private static extern void TKG_RemovePictureCross();
[DllImport("__Internal")]
private static extern bool TKG_ShowMoreGameIcon();
[DllImport("__Internal")]
private static extern void TKG_RemoveMoreGameIcon();
[DllImport("__Internal")]
private static extern void TKG_SetFuncs(string funcs);
[DllImport("__Internal")]
private static extern void TKG_Shake(int mType, float mIntensity);
[DllImport("__Internal")]
private static extern void TKG_Share(string text);
[DllImport("__Internal")]
private static extern int TKG_GetChannel();
[DllImport("__Internal")]
private static extern void TKG_InitSDK();
// event umeng
[DllImport("__Internal")]
private static extern void TKG_OnEvent_UMeng1(string s1);
[DllImport("__Internal")]
private static extern void TKG_OnEvent_UMeng2(string s1, string s2);
[DllImport("__Internal")]
private static extern void TKG_OnEvent_UMeng3(string s1, string key, string value);
[DllImport("__Internal")]
private static extern void TKG_OnEvent_UMeng4(string s1, string key1, string value1, string key2, string value2);
// event tenjin
[DllImport("__Internal")]
private static extern void TKG_OnEvent_Tenjin(int eventType);
// event game
[DllImport("__Internal")]
private static extern void TKG_OnEvent_GameStart(string levelId);
[DllImport("__Internal")]
private static extern void TKG_OnEvent_GameEnd(string levelId, int result);
// other
[DllImport("__Internal")]
private static extern void TKG_Review();
[DllImport("__Internal")]
private static extern void TKG_OpenPrivacyURL();
[DllImport("__Internal")]
private static extern void TKG_OpenUserTermURL();
[DllImport("__Internal")]
private static extern void TKG_OpenPolicyPop();
[DllImport("__Internal")]
private static extern void TKG_OpenMoreGame();
[DllImport("__Internal")]
private static extern void TKG_Toast(string str);
// ads
[DllImport("__Internal")]
private static extern void TKG_LoadBanner();
[DllImport("__Internal")]
private static extern bool TKG_IsReadyBanner();
[DllImport("__Internal")]
private static extern void TKG_ShowBanner(int align);
[DllImport("__Internal")]
private static extern void TKG_HideBanner();
[DllImport("__Internal")]
private static extern void TKG_LoadIntersititial();
[DllImport("__Internal")]
private static extern bool TKG_IsReadyIntersititial();
[DllImport("__Internal")]
private static extern void TKG_ShowIntersititial(string adPos,int ivType);
[DllImport("__Internal")]
private static extern void TKG_LoadRewardVideo();
[DllImport("__Internal")]
private static extern bool TKG_IsReadyRewardVideo();
[DllImport("__Internal")]
private static extern void TKG_ShowRewardVideo(string adPos);
[DllImport("__Internal")]
private static extern void TKG_ShowSDKToast(bool _show);
[DllImport("__Internal")]
private static extern void TKG_LoadNative(float width, float height);
[DllImport("__Internal")]
private static extern bool TKG_IsReadyNative();
[DllImport("__Internal")]
private static extern void TKG_ShowNative(float x, float y, float w, float h, string adPos);
[DllImport("__Internal")]
private static extern void TKG_RemoveNative();
// remote config
[DllImport("__Internal")]
private static extern int TKG_GetConfigInt(string key, int defaultValue);
[DllImport("__Internal")]
private static extern string TKG_GetConfigString(string key, string defaultValue);
[DllImport("__Internal")]
private static extern bool TKG_GetConfigBool(string key, bool defaultValue);
[DllImport("__Internal")]
private static extern bool TKG_SetLogged(bool enable);
[DllImport("__Internal")]
private static extern bool TKG_RemoveAds();
// callback
// iv close
[DllImport("__Internal")]
public static extern void interAdCloseCallback(
IntPtr interClose
);
// rv close
[DllImport("__Internal")]
public static extern void rewardAdCloseCallback(
IntPtr rewardClose
);
// rv click
[DllImport("__Internal")]
public static extern void rewardAdClickCallback(
IntPtr rewardClick
);
// rv show fail
[DllImport("__Internal")]
public static extern void rewardAdShowFailCallback(
IntPtr rewardShowFail
);
// pause game
[DllImport("__Internal")]
public static extern void pauseGameCallback(
IntPtr pauseGame
);
// init sdk
[DllImport("__Internal")]
public static extern void initSDKCallback(
IntPtr initSdk
);
// user source
[DllImport("__Internal")]
public static extern void userSourceCallback(
IntPtr userSource
);
// func callback
[DllImport("__Internal")]
public static extern void funcSwitchCallback(
IntPtr funcSwitch
);
// 设置unity版本
[DllImport("__Internal")]
private static extern void TKG_SetUnityVersion(string version);
// 通知
[DllImport("__Internal")]
private static extern void TKG_RegistAPNS();
[DllImport("__Internal")]
private static extern void TKG_RemoveAllNotification();
[DllImport("__Internal")]
private static extern void TKG_RemoveNotification(string notiId);
[DllImport("__Internal")]
private static extern void TKG_RegistNotification(string notiId, string body, string fireDate, int badge, string title, string subTitle);
// ============================ old sdk todo ========================
//设置log开关
public void SetLogEnable(bool enable)
{
TKG_SetLogged(enable);
}
public void SetUnitySDKVersion(string version)
{
TKG_SetUnityVersion(version);
}
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;
}
}
}
#endif