using System; using System.Collections.Generic; using UnityEngine; namespace Touka { public class TKGSDKNative : ITKGSDK { private Dictionary mDefaultDic = new Dictionary(); /// /// init sdk /// /// public void InitSDK(Action _initCallback = null) { TKGNativeInterface.Instance.Init(_initCallback); SetOnlineConfigInit(); } private void SetOnlineConfigInit() { //加入自定义参数列表 foreach (string tKey in TKGParams.OnlineParamDic.Keys) { mDefaultDic.Add(tKey, TKGParams.OnlineParamDic[tKey]); } } /// /// Set game focus /// /// public void SetGameFocusListener(Action _gameFocusAction) { TKGNativeInterface.Instance.SetGameFocusListener(_gameFocusAction); } public void SetRewardClickListener(Action _rewardClickAction) { TKGNativeInterface.Instance.SetRewardClickListener(_rewardClickAction); } /// /// Get channel /// /// public AppChannel GetChannel() { Debug.Log("android back getchannel : " + TKGNativeInterface.Instance.GetChannel()); string channelStr = TKGNativeInterface.Instance.GetChannel(); channelStr = channelStr.Equals("default") ? AppChannel.AndroidRoot.ToString() : channelStr; AppChannel tChannel = AppChannel.None; if (Enum.TryParse(channelStr, out tChannel)) { return tChannel; } return AppChannel.None; } #region Ads public void SetUnitySDKVersion(string sdkVersion) { TKGNativeInterface.Instance.SetUnitySDKVersion(sdkVersion); } public void PurchasedRemoveAds() { TKGNativeInterface.Instance.PurchasedRemoveAds(); } public void RemoveNativeAd() { TKGNativeInterface.Instance.RemoveNativeAd(); } public bool IsReadyNativeAd() { return TKGNativeInterface.Instance.IsReadyNativeAd(); } public void ShowNativeAd(RectTransform pRect, Camera pCam = null, string pAdPos = "") { TKGNativeInterface.Instance.ShowNativeAd(pRect,pCam,pAdPos); } /// /// Show banner /// /// bannerAlign public void ShowBanner(TKGBannerAlign _pos) { #if UNITY_EDITOR return; #endif TKGNativeInterface.Instance.showBannerAd(_pos); } /// /// Hide banner /// public void HideBanner() { #if UNITY_EDITOR return; #endif TKGNativeInterface.Instance.hideBannerAd(); } /// /// Show Interstitial Ad /// /// Name of interstitial ad placement. /// Callback of interstitial ad close and show interstitial failed /// IVADType for distinguish interstitial ads frequency, default use iv1 public void ShowInterstitialAd(TKGIVAdPositionName _adPos, Action _callback = null, IVADType _IvType = IVADType.IV1) { #if UNITY_EDITOR TKGDebugger.LogDebug("[TKGSDKNative] Show Interstitial call, _adPos : " + _adPos); if (_callback != null) _callback(); return; #endif TKGSDKCallback.mInterAdCallback = _callback; TKGNativeInterface.Instance.showInterstitialAd(_adPos.ToString(), _IvType); } /// /// Show Reward Ad /// /// Name of reward ad placement /// true:reward succ, false: reward failed /// Callback of reward ad show fail public void ShowRewardAd(TKGRVPositionName _adPos, Action _rewardCallback = null, Action _showFailedCallback = null) { #if UNITY_EDITOR TKGDebugger.LogDebug("[TKGSDKNative] Show reward call, _adPos : " + _adPos); if (_rewardCallback != null) _rewardCallback(true); return; #endif TKGSDKCallback.mRewardCallback = _rewardCallback; TKGSDKCallback.mRewardShowFailedCallback = _showFailedCallback; TKGNativeInterface.Instance.showRewardAd(_adPos.ToString(), -1); } /// /// Is Ready Interstitial /// /// public bool IsReadyInterstitialAd() { #if UNITY_EDITOR return true; #endif return TKGNativeInterface.Instance.isInterstitialAdReady(); } /// /// Is Ready Reward /// /// public bool IsReadyRewardAd() { #if UNITY_EDITOR return true; #endif return TKGNativeInterface.Instance.isRewardAdReady(); } #endregion #region Log Event #region Normal /// /// log event /// /// public void LogEvent(string _eventSort) { TKGDebugger.LogDebug("[TKGSDKNative] logEvent : " + _eventSort); #if UNITY_EDITOR return; #endif TKGNativeInterface.Instance.onEvent(_eventSort); } /// /// log event /// /// /// /// public void LogEvent(string _eventSort, string _key, string _value) { TKGDebugger.LogDebug("[TKGSDKNative] logEvent : " + _eventSort + " , _key : " + _key + " , _value : " + _value); #if UNITY_EDITOR return; #endif TKGNativeInterface.Instance.onEvent(_eventSort, _key, _value); } /// /// log event /// /// /// /// /// /// public void LogEvent(string _eventSort, string _key01, string _value01, string _key02, string _value02) { TKGDebugger.LogDebug("[TKGSDKNative] logEvent : " + _eventSort + " , _key01 : " + _key01 + " , _value01 : " + _value01 + " , _key2 : " + _key02 + " , _value02 : " + _value02); #if UNITY_EDITOR return; #endif TKGNativeInterface.Instance.onEvent(_eventSort, _key01, _value01, _key02, _value02); } /// /// log event /// /// /// public void LogEvent(string _eventSort, Dictionary _eventDic = null) { TKGDebugger.LogDebug("[TKGSDKNative] logEvent : " + _eventSort + " , _eventDic.count : " + _eventDic.Count); #if UNITY_EDITOR return; #endif TKGNativeInterface.Instance.onEvent(_eventSort, _eventDic); } #endregion #region Level Event /// /// Notify game start /// /// public void LevelStart(int _level) { TKGDebugger.LogDebug("[TKGSDKNative] LevelStart _level : " + _level); #if UNITY_EDITOR return; #endif TKGNativeInterface.Instance.LevelStart(_level.ToString()); } /// /// Notify game start /// /// public void LevelStart(string _level) { TKGDebugger.LogDebug("[TKGSDKNative] LevelStart _level : " + _level); #if UNITY_EDITOR return; #endif TKGNativeInterface.Instance.LevelStart(_level); } /// /// Notify game end /// /// /// public bool LevelEnd(int _level, StageResult _stageResult) { TKGDebugger.LogDebug("[TKGSDKNative] LevelEnd _level : " + _level + " , _stageResult : " + _stageResult); #if UNITY_EDITOR return true; #endif TKGNativeInterface.Instance.LevelEnd(_level.ToString(), _stageResult); return true; } /// /// Notify game end /// /// /// public bool LevelEnd(string _level, StageResult _stageResult) { TKGDebugger.LogDebug("[TKGSDKNative] LevelEnd _level : " + _level + " , _win : " + _stageResult); #if UNITY_EDITOR return true; #endif TKGNativeInterface.Instance.LevelEnd(_level, _stageResult); return true; } #endregion #region Reward Ad Button Show /// /// Log Reward ad button show /// /// public void LogRewardAdBtnShow(string _pos) { TKGDebugger.LogDebug("[TKGSDKNative] LogRewardAdBtnShow _pos : " + _pos); #if UNITY_EDITOR return; #endif TKGNativeInterface.Instance.onEvent(TKGStringEvent.Event_Sort_TKGInner_ad_button_show, TKGStringEvent.Event_Type_TKGInner_ad_position, _pos); } #endregion #region Tracking Event /// /// Log Tracking Event /// /// public void LogTrackingEvent(TrackingEventType _eventType) { TKGDebugger.LogDebug("[TKGSDKNative] LogTrackingEvent _eventType : " + _eventType); #if UNITY_EDITOR return; #endif TKGNativeInterface.Instance.LogTrackingEvent(_eventType); } #endregion #endregion #region Online Config /// /// get config - string /// /// /// public string GetConfigStr(string _key) { #if UNITY_EDITOR return GetConfigDefaultValue(_key); #endif string tempOnline = TKGNativeInterface.Instance.GetConfigString(_key, GetConfigDefaultValue(_key)); TKGDebugger.LogDebug("[TKGSDKNative] tempOnline , _key : " + _key + " , tempOnline : " + tempOnline); return tempOnline; } /// /// get config - int /// /// /// public int GetConfigInt(string _key) { string tDefaultValue = GetConfigDefaultValue(_key); #if UNITY_EDITOR if (int.TryParse(tDefaultValue, out int tIntVal)) { return tIntVal; } TKGDebugger.LogDebug("[TKGSDKNative]"); return 0; #endif int defaultInt = 0; int.TryParse(tDefaultValue, out defaultInt); int tempInt = TKGNativeInterface.Instance.GetConfigInt(_key, defaultInt); TKGDebugger.LogDebug("[TKGSDKNative] GetConfigInt , _key : " + _key + " , tempInt : " + tempInt); return tempInt; } /// /// get config - bool /// /// /// public bool GetConfigBool(string _key) { string tDefaultValue = GetConfigDefaultValue(_key); #if UNITY_EDITOR if (int.TryParse(tDefaultValue, out int tIntVal)) { return tIntVal != 0; } TKGDebugger.LogDebug("[TKGSDKNative]"); return false; #endif int defaultInt = 0; int.TryParse(tDefaultValue, out defaultInt); bool tBoolValue = TKGNativeInterface.Instance.GetConfigBool(_key, defaultInt != 0); TKGDebugger.LogDebug("[TKGSDKNative] GetConfigBool , _key : " + _key + " , tBoolValue : " + tBoolValue); return tBoolValue; } /// /// get default config value /// /// /// private string GetConfigDefaultValue(string _key) { string tDefault = ""; if (mDefaultDic.ContainsKey(_key)) { tDefault = mDefaultDic[_key].ToString(); } Debug.Log("getConfigDefaultValue, _key : " + _key + " , tDefault : " + tDefault); return tDefault; } #endregion #region Others (common) /// /// review /// public void Review() { TKGDebugger.LogDebug("[TKGSDKNative] Review"); #if UNITY_EDITOR #if AppStore_GB TKGDebugger.LogDebug("[TKGSDKNative] Review cannot be opened in editor, please open it in real machine"); #else TKGDebugger.LogDebug("[TKGSDKNative] 编辑器中无法打开评价页面,请在真机中打开"); #endif return; #endif TKGNativeInterface.Instance.Review(); } /// /// open privacy url /// public void OpenPrivacyURL() { TKGDebugger.LogDebug("[TKGSDKNative] OpenPrivacyURL"); #if UNITY_EDITOR #if AppStore_GB TKGDebugger.LogDebug("[TKGSDKNative] Web page cannot be opened in editor, please open it in real machine"); #else TKGDebugger.LogDebug("[TKGSDKNative] 编辑器中无法打开网页,请在真机中打开"); #endif return; #endif TKGNativeInterface.Instance.OpenPrivacyURL(); } /// /// open user term url /// public void OpenUserTermURL() { TKGDebugger.LogDebug("[TKGSDKNative] OpenUserTermURL"); #if UNITY_EDITOR #if AppStore_GB TKGDebugger.LogDebug("[TKGSDKNative] Web page cannot be opened in editor, please open it in real machine"); #else TKGDebugger.LogDebug("[TKGSDKNative] 编辑器中无法打开网页,请在真机中打开"); #endif return; #endif TKGNativeInterface.Instance.OpenUserTermURL(); } /// /// open policy pop /// public void OpenPolicyPop() { TKGDebugger.LogDebug("[TKGSDKNative] OpenPolicyPop"); #if UNITY_EDITOR #if AppStore_GB TKGDebugger.LogDebug("[TKGSDKNative] Web page cannot be opened in editor, please open it in real machine"); #else TKGDebugger.LogDebug("[TKGSDKNative] 编辑器中无法打开网页,请在真机中打开"); #endif return; #endif TKGNativeInterface.Instance.OpenPolicyPop(); } /// /// open more game /// public void OpenMoreGame() { TKGDebugger.LogDebug("[TKGSDKNative] OpenMoreGame"); #if UNITY_EDITOR #if AppStore_GB TKGDebugger.LogDebug("[TKGSDKNative] App Store cannot be opened in editor, please open it in real machine"); #else TKGDebugger.LogDebug("[TKGSDKNative] 编辑器中无法打开App Store,请在真机中打开"); #endif return; #endif TKGNativeInterface.Instance.OpenMoreGame(); } /// /// open url browser /// /// public void OpenUrlByBrowser(string _url) { TKGDebugger.LogDebug("[TKGSDKNative] OpenUrlByBrowser"); #if UNITY_EDITOR return; #endif TKGUtils.OpenBrowserUrl(_url); } /// /// shake /// /// 0 light,1 medium,2 heavy /// ios 0~1, android any num public void Shake(int _shakeType, float _intensity = 1) { #if UNITY_EDITOR return; #endif TKGNativeInterface.Instance.shake(_shakeType, _intensity); } #endregion #region others(uncommon) /// /// SetUserSourceListener /// /// public void SetUserSourceListener(Action _userSourceAction) { #if UNITY_EDITOR return; #endif TKGSDKCallback.mTKGUserSourceCallback = _userSourceAction; TKGNativeInterface.Instance.SetUserSourceCallback(new AndroidTKGUserSourceCalllback()); } /// /// Set TKG Common callback /// /// public void SetTKGCommonCallback(Action _commonCallback) { #if UNITY_EDITOR return; #endif TKGSDKCallback.mTKGCommonCallback = _commonCallback; TKGNativeInterface.Instance.SetSDKCommonCallback(new AndroidTKGCommonCalllback()); } /// /// Set log enable /// public void SetLogEnable(bool _enable) { #if UNITY_EDITOR return; #endif TKGNativeInterface.Instance.SetLogEnable(_enable); } /// /// share txt /// public void ShareTxt(string _shareTxt) { #if UNITY_EDITOR return; #endif #if UNITY_ANDROID TKGNativeInterface.Instance.ShareTxt(_shareTxt); #endif } /// /// regist APNS /// public void RegistAPNS() { #if UNITY_EDITOR return; #else TKGNativeInterface.Instance.RegistAPNS(); #endif } /// /// shake /// /// notification identifier /// The body of the notification. /// notify after the time interval. format: yyyy-MM-dd HH:mm:ss /// The application badge number. /// The title of the notification. /// The subtitle of the notification. public void RegistNotification(string notiId, string body, string fireDate, int badge, string title, string subTitle) { #if UNITY_EDITOR return; #else TKGNativeInterface.Instance.RegistNotification(notiId,body,fireDate,badge,title,subTitle); #endif } /// /// remove all notification /// public void RemoveAllNotifications() { #if UNITY_EDITOR return; #else TKGNativeInterface.Instance.RemoveAllNotifications(); #endif } /// /// remove notification by notification identifier /// /// notification identifier public void RemoveNotification(string notiId) { #if UNITY_EDITOR return; #else TKGNativeInterface.Instance.RemoveNotification(notiId); #endif } #endregion } }