423 lines
9.9 KiB
C#
423 lines
9.9 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using Touka;
|
|
|
|
public class TKGSDKManager : TKGSingleton<TKGSDKManager>, ITKGSDK
|
|
{
|
|
public bool IsNoAllAD = false;
|
|
public bool IsNoInterstitialAD = false;
|
|
|
|
private ITKGSDK m_sdkInterface;
|
|
|
|
protected override void OnInstanceCreate()
|
|
{
|
|
base.OnInstanceCreate();
|
|
#if UNITY_EDITOR
|
|
m_sdkInterface = new TKGSDKUnity();
|
|
#elif UNITY_IOS
|
|
m_sdkInterface = new TKGSDKUnity();
|
|
#elif UNITY_ANDROID
|
|
m_sdkInterface = new TKGSDKNative();
|
|
#else
|
|
m_sdkInterface = new TKGSDKUnity();
|
|
#endif
|
|
}
|
|
|
|
/// <summary>
|
|
/// init sdk
|
|
/// </summary>
|
|
/// <param name="_initCallback"></param>
|
|
public void InitSDK(Action _initCallback = null)
|
|
{
|
|
m_sdkInterface.InitSDK(_initCallback);
|
|
|
|
#if USE_IAP
|
|
IAPTool.Instance.Initialize();
|
|
#endif
|
|
|
|
#if USE_FIREBASE
|
|
FirebaseTool.Instance.Initialize();
|
|
#endif
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set game focus
|
|
/// </summary>
|
|
/// <param name="_gameFocusAction"></param>
|
|
public void SetGameFocusListener(Action<bool> _gameFocusAction)
|
|
{
|
|
m_sdkInterface.SetGameFocusListener(_gameFocusAction);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get channel
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public AppChannel GetChannel()
|
|
{
|
|
return m_sdkInterface.GetChannel();
|
|
}
|
|
|
|
#region Ads
|
|
/// <summary>
|
|
/// Show banner
|
|
/// </summary>
|
|
/// <param name="_pos">1:top,2:bottom</param>
|
|
public void ShowBanner(int _pos)
|
|
{
|
|
m_sdkInterface.ShowBanner(_pos);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Hide banner
|
|
/// </summary>
|
|
public void HideBanner()
|
|
{
|
|
m_sdkInterface.HideBanner();
|
|
}
|
|
|
|
/// <summary>
|
|
/// ShowNative
|
|
/// </summary>
|
|
/// <param name="pRect"></param>
|
|
/// <param name="pAdPos"></param>
|
|
/// <param name="pCam"></param>
|
|
public void ShowNative(RectTransform pRect, string pAdPos, Camera pCam = null)
|
|
{
|
|
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);
|
|
|
|
if (IsNativeReady())
|
|
{
|
|
ShowNative(pAdPos, tTopLeft.x, Screen.height - tTopLeft.y, tWidth, tHeight);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// ShowNative
|
|
/// </summary>
|
|
/// <param name="nativePos"></param>
|
|
/// <param name="x"></param>
|
|
/// <param name="y"></param>
|
|
/// <param name="width"></param>
|
|
/// <param name="height"></param>
|
|
public void ShowNative(string nativePos, float x, float y, float width, float height)
|
|
{
|
|
m_sdkInterface.ShowNative(nativePos, x, y, width, height);
|
|
}
|
|
|
|
/// <summary>
|
|
/// HideNative
|
|
/// </summary>
|
|
public void HideNative()
|
|
{
|
|
m_sdkInterface.HideNative();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Is Ready Native
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool IsNativeReady()
|
|
{
|
|
return m_sdkInterface.IsNativeReady();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Play Interstitial Ad
|
|
/// </summary>
|
|
/// <param name="_adPos"></param>
|
|
/// <param name="_callback"></param>
|
|
/// <param name="_IvType"></param>
|
|
public void PlayInterstitialAd(string _adPos, Action _callback = null, IVADType _IvType = IVADType.IV1)
|
|
{
|
|
#if UNITY_EDITOR
|
|
if (null != _callback)
|
|
{
|
|
_callback.Invoke();
|
|
}
|
|
#endif
|
|
if (IsNoAllAD || IsNoInterstitialAD)
|
|
{
|
|
_callback?.Invoke();
|
|
}
|
|
else
|
|
{
|
|
m_sdkInterface.PlayInterstitialAd(_adPos, _callback, _IvType);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Play Reward Ad
|
|
/// </summary>
|
|
/// <param name="_adPos"></param>
|
|
/// <param name="_rewardCallback"></param>
|
|
/// <param name="_playFailedCallback"></param>
|
|
public void PlayRewardAd(string _adPos, Action<bool> _rewardCallback = null, Action _playFailedCallback = null)
|
|
{
|
|
#if UNITY_EDITOR
|
|
if(null != _rewardCallback)
|
|
{
|
|
_rewardCallback.Invoke(true);
|
|
}
|
|
return;
|
|
#endif
|
|
|
|
if (IsNoAllAD)
|
|
{
|
|
_rewardCallback?.Invoke(true);
|
|
}
|
|
else
|
|
{
|
|
m_sdkInterface.PlayRewardAd(_adPos, _rewardCallback, _playFailedCallback);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Is Ready Interstitial
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool IsReadyInterstitialAd()
|
|
{
|
|
return m_sdkInterface.IsReadyInterstitialAd();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Is Ready Reward
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool IsReadyRewardAd()
|
|
{
|
|
return m_sdkInterface.IsReadyRewardAd();
|
|
}
|
|
#endregion
|
|
|
|
#region Log Event
|
|
|
|
#region Normal
|
|
|
|
/// <summary>
|
|
/// Log Event
|
|
/// </summary>
|
|
/// <param name="_eventSort"></param>
|
|
public void LogEvent(string _eventSort)
|
|
{
|
|
m_sdkInterface.LogEvent(_eventSort);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Log Event
|
|
/// </summary>
|
|
/// <param name="_eventSort"></param>
|
|
/// <param name="_key"></param>
|
|
/// <param name="_value"></param>
|
|
public void LogEvent(string _eventSort, string _key, string _value)
|
|
{
|
|
m_sdkInterface.LogEvent(_eventSort, _key, _value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Log Event
|
|
/// </summary>
|
|
/// <param name="_eventSort"></param>
|
|
/// <param name="_key01"></param>
|
|
/// <param name="_value01"></param>
|
|
/// <param name="_key02"></param>
|
|
/// <param name="_value02"></param>
|
|
public void LogEvent(string _eventSort, string _key01, string _value01, string _key02, string _value02)
|
|
{
|
|
m_sdkInterface.LogEvent(_eventSort, _key01, _value01, _key02, _value02);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Log Event
|
|
/// </summary>
|
|
/// <param name="_eventSort"></param>
|
|
/// <param name="_eventDic"></param>
|
|
public void LogEvent(string _eventSort, Dictionary<string, string> _eventDic = null)
|
|
{
|
|
m_sdkInterface.LogEvent(_eventSort, _eventDic);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Level Event
|
|
|
|
/// <summary>
|
|
/// Notify game start
|
|
/// </summary>
|
|
/// <param name="_level"></param>
|
|
public void NotifyGameStart(int _level)
|
|
{
|
|
m_sdkInterface.NotifyGameStart(_level);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Notify game start
|
|
/// </summary>
|
|
/// <param name="_level"></param>
|
|
public void NotifyGameStart(string _level)
|
|
{
|
|
m_sdkInterface.NotifyGameStart(_level);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Notify game end
|
|
/// </summary>
|
|
/// <param name="_level"></param>
|
|
/// <param name="_win"></param>
|
|
public bool NotifyGameEnd(int _level, bool _win)
|
|
{
|
|
return m_sdkInterface.NotifyGameEnd(_level, _win);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Notify game end
|
|
/// </summary>
|
|
/// <param name="_level"></param>
|
|
/// <param name="_win"></param>
|
|
public bool NotifyGameEnd(string _level, bool _win)
|
|
{
|
|
return m_sdkInterface.NotifyGameEnd(_level, _win);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Reward Ad Button Show
|
|
|
|
/// <summary>
|
|
/// Log Reward ad button show
|
|
/// </summary>
|
|
/// <param name="_pos"></param>
|
|
public void LogRewardAdBtnShow(string _pos)
|
|
{
|
|
m_sdkInterface.LogRewardAdBtnShow(_pos);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Tracking Event
|
|
|
|
/// <summary>
|
|
/// Log Tracking Event
|
|
/// </summary>
|
|
/// <param name="_eventType"></param>
|
|
public void LogTrackingEvent(TrackingEventType _eventType)
|
|
{
|
|
m_sdkInterface.LogTrackingEvent(_eventType);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region Online Config
|
|
|
|
/// <summary>
|
|
/// get config - string
|
|
/// </summary>
|
|
/// <param name="_key"></param>
|
|
/// <param name="_default"></param>
|
|
/// <returns></returns>
|
|
public string GetConfigStr(string _key, string _default = "")
|
|
{
|
|
#if USE_FIREBASE
|
|
return FirebaseTool.Instance.GetString(_key, _default);
|
|
#endif
|
|
|
|
return m_sdkInterface.GetConfigStr(_key, _default);
|
|
}
|
|
|
|
/// <summary>
|
|
/// get config - int
|
|
/// </summary>
|
|
/// <param name="_key"></param>
|
|
/// <param name="_default"></param>
|
|
/// <returns></returns>
|
|
public int GetConfigInt(string _key, int _default = 0)
|
|
{
|
|
#if USE_FIREBASE
|
|
return FirebaseTool.Instance.GetInt(_key, _default);
|
|
#endif
|
|
|
|
return m_sdkInterface.GetConfigInt(_key, _default);
|
|
}
|
|
|
|
/// <summary>
|
|
/// get config - bool
|
|
/// </summary>
|
|
/// <param name="_key"></param>
|
|
/// <param name="_default"></param>
|
|
/// <returns></returns>
|
|
public bool GetConfigBool(string _key, bool _default = false)
|
|
{
|
|
#if USE_FIREBASE
|
|
return FirebaseTool.Instance.GetInt(_key, _default ? 1 : 0) == 1;
|
|
#endif
|
|
|
|
return m_sdkInterface.GetConfigBool(_key, _default);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Others (common)
|
|
|
|
/// <summary>
|
|
/// review
|
|
/// </summary>
|
|
public void Review()
|
|
{
|
|
m_sdkInterface.Review();
|
|
}
|
|
|
|
/// <summary>
|
|
/// open privacy url
|
|
/// </summary>
|
|
public void OpenPrivacyURL()
|
|
{
|
|
m_sdkInterface.OpenPrivacyURL();
|
|
}
|
|
|
|
/// <summary>
|
|
/// open user agreement url
|
|
/// </summary>
|
|
public void OpenUserTermURL()
|
|
{
|
|
m_sdkInterface.OpenUserTermURL();
|
|
}
|
|
|
|
/// <summary>
|
|
/// open more game
|
|
/// </summary>
|
|
public void OpenMoreGame()
|
|
{
|
|
m_sdkInterface.OpenMoreGame();
|
|
}
|
|
|
|
/// <summary>
|
|
/// open url by browser
|
|
/// </summary>
|
|
/// <param name="_url"></param>
|
|
public void OpenUrlByBrowser(string _url)
|
|
{
|
|
m_sdkInterface.OpenUrlByBrowser(_url);
|
|
}
|
|
|
|
/// <summary>
|
|
/// shake
|
|
/// </summary>
|
|
/// <param name="_shakeType">0 light,1 medium,2 heavy</param>
|
|
/// <param name="_intensity">ios 0~1, android any num</param>
|
|
public void Shake(int _shakeType, float _intensity = 1)
|
|
{
|
|
m_sdkInterface.Shake(_shakeType, _intensity);
|
|
}
|
|
#endregion
|
|
} |