using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using Touka; public class TKGSDKManager : TKGSingleton, 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 } /// /// init sdk /// /// public void InitSDK(Action _initCallback = null) { m_sdkInterface.InitSDK(_initCallback); #if USE_IAP IAPTool.Instance.Initialize(); #endif #if USE_FIREBASE FirebaseTool.Instance.Initialize(); #endif } /// /// Set game focus /// /// public void SetGameFocusListener(Action _gameFocusAction) { m_sdkInterface.SetGameFocusListener(_gameFocusAction); } /// /// Get channel /// /// public AppChannel GetChannel() { return m_sdkInterface.GetChannel(); } #region Ads /// /// Show banner /// /// 1:top,2:bottom public void ShowBanner(int _pos) { m_sdkInterface.ShowBanner(_pos); } /// /// Hide banner /// public void HideBanner() { m_sdkInterface.HideBanner(); } /// /// ShowNative /// /// /// /// 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); } } /// /// ShowNative /// /// /// /// /// /// public void ShowNative(string nativePos, float x, float y, float width, float height) { m_sdkInterface.ShowNative(nativePos, x, y, width, height); } /// /// HideNative /// public void HideNative() { m_sdkInterface.HideNative(); } /// /// Is Ready Native /// /// public bool IsNativeReady() { return m_sdkInterface.IsNativeReady(); } /// /// Play Interstitial Ad /// /// /// /// 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); } } /// /// Play Reward Ad /// /// /// /// public void PlayRewardAd(string _adPos, Action _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); } } /// /// Is Ready Interstitial /// /// public bool IsReadyInterstitialAd() { return m_sdkInterface.IsReadyInterstitialAd(); } /// /// Is Ready Reward /// /// public bool IsReadyRewardAd() { return m_sdkInterface.IsReadyRewardAd(); } #endregion #region Log Event #region Normal /// /// Log Event /// /// public void LogEvent(string _eventSort) { m_sdkInterface.LogEvent(_eventSort); } /// /// Log Event /// /// /// /// public void LogEvent(string _eventSort, string _key, string _value) { m_sdkInterface.LogEvent(_eventSort, _key, _value); } /// /// Log Event /// /// /// /// /// /// public void LogEvent(string _eventSort, string _key01, string _value01, string _key02, string _value02) { m_sdkInterface.LogEvent(_eventSort, _key01, _value01, _key02, _value02); } /// /// Log Event /// /// /// public void LogEvent(string _eventSort, Dictionary _eventDic = null) { m_sdkInterface.LogEvent(_eventSort, _eventDic); } #endregion #region Level Event /// /// Notify game start /// /// public void NotifyGameStart(int _level) { m_sdkInterface.NotifyGameStart(_level); } /// /// Notify game start /// /// public void NotifyGameStart(string _level) { m_sdkInterface.NotifyGameStart(_level); } /// /// Notify game end /// /// /// public bool NotifyGameEnd(int _level, bool _win) { return m_sdkInterface.NotifyGameEnd(_level, _win); } /// /// Notify game end /// /// /// public bool NotifyGameEnd(string _level, bool _win) { return m_sdkInterface.NotifyGameEnd(_level, _win); } #endregion #region Reward Ad Button Show /// /// Log Reward ad button show /// /// public void LogRewardAdBtnShow(string _pos) { m_sdkInterface.LogRewardAdBtnShow(_pos); } #endregion #region Tracking Event /// /// Log Tracking Event /// /// public void LogTrackingEvent(TrackingEventType _eventType) { m_sdkInterface.LogTrackingEvent(_eventType); } #endregion #endregion #region Online Config /// /// get config - string /// /// /// /// public string GetConfigStr(string _key, string _default = "") { #if USE_FIREBASE return FirebaseTool.Instance.GetString(_key, _default); #endif return m_sdkInterface.GetConfigStr(_key, _default); } /// /// get config - int /// /// /// /// public int GetConfigInt(string _key, int _default = 0) { #if USE_FIREBASE return FirebaseTool.Instance.GetInt(_key, _default); #endif return m_sdkInterface.GetConfigInt(_key, _default); } /// /// get config - bool /// /// /// /// 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) /// /// review /// public void Review() { m_sdkInterface.Review(); } /// /// open privacy url /// public void OpenPrivacyURL() { m_sdkInterface.OpenPrivacyURL(); } /// /// open user agreement url /// public void OpenUserTermURL() { m_sdkInterface.OpenUserTermURL(); } /// /// open more game /// public void OpenMoreGame() { m_sdkInterface.OpenMoreGame(); } /// /// open url by browser /// /// public void OpenUrlByBrowser(string _url) { m_sdkInterface.OpenUrlByBrowser(_url); } /// /// shake /// /// 0 light,1 medium,2 heavy /// ios 0~1, android any num public void Shake(int _shakeType, float _intensity = 1) { m_sdkInterface.Shake(_shakeType, _intensity); } #endregion }