using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using Touka; using HC; #if H5_WX using WeChatWASM; #endif #if H5_DY using HC; #endif public class TKGSDKManager : TKGSingleton { #region webgl //static string cdnPath = "https://touka-pkg.oss-cn-beijing.aliyuncs.com/Temp/chicken_webgl/"; // Appid: wx1a9ad77bb8f3b66a static string cdnPath = "https://touka-artifacts.oss-cn-beijing.aliyuncs.com/WXResource/Chicken_WebGL/"; // Appid: wxb8f1bd49ef160a9a string[] shareTipsArr = new string[10] { "靠声音过关的游戏,有点意思~", "你对声音敏感吗?快来试试吧!", "高智商玩家的选择,能过20关的都不是一般人", "声音解谜,敢来测测你的游戏水平吗?", "这游戏脑洞太大,快来帮帮我~", "这游戏有点难度,敢不敢来跟我PK一下", "好友邀请你PK一局,点击加入", "这游戏笑的我肚子痛~", "这奇葩结局,必须要跟你分享一下!", "这声音,建议躲在被窝里玩"}; #endregion public bool IsNoAllAD { get => mIsNoAllAD; set { mIsNoAllAD = value; if (mIsNoAllAD) { PurchasedRemoveAds(); HideBanner(); } } } private bool mIsNoAllAD = false; public bool IsRemoveAds { get => mIsRemoveAds; set { mIsRemoveAds = value; if (mIsRemoveAds) { PurchasedRemoveAds(); HideBanner(); } } } private bool mIsRemoveAds = false; public bool IsIAPEnabled { get { AppChannel tChannel = GetChannel(); return (tChannel == AppChannel.AppStore_GB || tChannel == AppChannel.GooglePlay); } } private int mLoginCount { get => PlayerPrefs.GetInt(nameof(mLoginCount), 0); set => PlayerPrefs.SetInt(nameof(mLoginCount), value); } private int mPassCount { get => PlayerPrefs.GetInt(nameof(mPassCount), 0); set => PlayerPrefs.SetInt(nameof(mPassCount), value); } private bool mHasPoppedReview { get => PlayerPrefs.GetInt(nameof(mHasPoppedReview), 0) == 1; set => PlayerPrefs.SetInt(nameof(mHasPoppedReview), value ? 1 : 0); } private bool isInit = false; private ITKGSDK m_sdkInterface; protected override void OnInstanceCreate() { base.OnInstanceCreate(); m_sdkInterface = new TKGSDKNative(); } /// /// init sdk /// /// public void InitSDK(Action _initCallback = null) { if (isInit) return; HCSDKManager.Instance.InitializeSdk(); isInit = true; } /// /// Set game focus /// /// public void SetGameFocusListener(Action _gameFocusAction) { HCSDKManager.Instance.SetGameFocusListener = _gameFocusAction; } // reward click callback public void SetRewardClickListener(Action _clickCallback = null) { } /// /// Get channel /// /// public AppChannel GetChannel() { return AppChannel.None; } /// /// Set log enable /// public void SetLogEnable(bool _enable) { } #region Ads // 去广告接口调用 public void PurchasedRemoveAds() { } /// /// 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(HCIVPositionName _adPos, Action _callback = null, HCIVADType _IvType = HCIVADType.IV1) { HCSDKManager.Instance.ShowInterstitial(_adPos, _IvType, _callback); } /// /// Show Reward Ad /// /// Name of reward ad placement /// true:reward succ, false: reward failed /// Callback of reward ad show fail public void ShowRewardAd(HCRVPositionName _adPos, Action _rewardCallback = null, Action _showFailedCallback = null) { HCSDKManager.Instance.ShowRewardedAd(_adPos,_rewardCallback, _showFailedCallback); } public void ShowNative(RectTransform pRect, Camera pCam = null, string pAdPos = "") { } /// /// Is Ready Interstitial /// /// public bool IsReadyInterstitialAd() { return HCSDKManager.Instance.IsInterstitialReady(); } /// /// Is Ready Reward /// /// public bool IsReadyRewardAd() { return HCSDKManager.Instance.IsRewardedAdReady(); } /// /// Is Ready Native Ad /// /// public bool IsReadyNativeAd() { return false; } /// /// Show banner /// /// bannerAlign public void ShowBanner(TKGBannerAlign _bannerAlign) { HCSDKManager.Instance.ShowBanner(); } /// /// Hide banner /// public void HideBanner() { HCSDKManager.Instance.HideBanner(); } /// /// Remove Native /// public void RemoveNative() { } #endregion #region Log Event #region Normal /// /// Log Event /// /// public void LogEvent(string _eventSort) { HCSDKManager.Instance.LogEvent(_eventSort); } /// /// Log Event /// /// /// /// public void LogEvent(string _eventSort, string _key, string _value) { HCSDKManager.Instance.LogEvent(_eventSort,_key,_value); } /// /// Log Event /// /// /// /// /// /// public void LogEvent(string _eventSort, string _key01, string _value01, string _key02, string _value02) { HCSDKManager.Instance.LogEvent(_eventSort, _key01, _value01, _key02, _value02); } /// /// Log Event /// /// /// public void LogEvent(string _eventSort, Dictionary _eventDic = null) { HCSDKManager.Instance.LogEvent(_eventSort, _eventDic); } #endregion #region Level Event /// /// Level start /// /// public void LevelStart(int _level) { // todo } /// /// Level start /// /// public void LevelStart(string _level) { } /// /// Level end /// /// /// public void LevelEnd(int _level, StageResult _stageResult) { } /// /// Level end,if return false, it means review pops up. /// /// /// public void LevelEnd(string _level, StageResult _stageResult) { } private void CheckReviewPop(int pLevel) { HCSDKManager.Instance.Review(); } #endregion #region Reward Ad Button Show /// /// Log Reward ad button show /// /// public void LogRewardAdBtnShow(string _pos) { HCSDKManager.Instance.LogRewardBtnShow(_pos); } #endregion #region Tracking Event /// /// Log Tracking Event /// /// private void LogTrackingEvent(TrackingEventType _eventType) { } #endregion #endregion #region Online Config /// /// get config - string /// /// /// public string GetConfigStr(TKGParamKey _key) { return HCSDKManager.Instance.GetRemoteConfigStr(_key.ToString(),""); } /// /// get config - int /// /// /// public int GetConfigInt(TKGParamKey _key) { return HCSDKManager.Instance.GetRemoteConfigInt(_key.ToString(),0); } /// /// get config - bool /// /// /// public bool GetConfigBool(TKGParamKey _key) { return HCSDKManager.Instance.GetRemoteConfigBool(_key.ToString(),false); } #endregion #region Others (common) /// /// review /// public void Review() { HCSDKManager.Instance.Review(); } /// 使用 OpenPolicyPop 接口 === Use OpenPolicyPop /// 使用 OpenPolicyPop 接口 === Use OpenPolicyPop /// 使用 OpenPolicyPop 接口 === Use OpenPolicyPop /// /// open privacy url /// //public void OpenPrivacyURL() //{ // m_sdkInterface.OpenPrivacyURL(); //} /// 使用 OpenPolicyPop 接口 === Use OpenPolicyPop /// 使用 OpenPolicyPop 接口 === Use OpenPolicyPop /// 使用 OpenPolicyPop 接口 === Use OpenPolicyPop /// /// open user agreement url /// //public void OpenUserTermURL() //{ // m_sdkInterface.OpenUserTermURL(); //} /// /// open more game /// public void OpenMoreGame() { } /// /// open url by browser /// /// public void OpenUrlByBrowser(string _url) { } public void OpenPolicyPop() { } /// /// shake /// /// 0 light,1 medium,2 heavy /// ios 0~1, android any num public void Shake(int _shakeType, float _intensity = 1) { } /// /// share txt /// /// public void Share(string shareText) { } /// /// regist APNS /// public void RegistAPNS() { } /// /// 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 = 1, string title = "", string subTitle = "") { } /// /// remove all notification /// public void RemoveAllNotifications() { } /// /// remove notification by notification identifier /// /// notification identifier public void RemoveNotification(string notiId) { } #endregion #region others /// /// Set user source listener /// only call first can back source /// /// true : origin user,false : not origin user public void SetUserSourceListener(Action _userSourceAction) { } /// /// set common callback /// /// public void SetTKGCommonCallback(Action _commonCallbackAction) { } #endregion #region h5 public enum WayOfReward { None, Share, RewardAd, } public enum ShareType { None, ShareAppOriginImg, ShareAppFixedImg, } public WayOfReward GetRewardWay() { #if H5_DY return WayOfReward.RewardAd; #elif H5_WX return WayOfReward.Share; #endif return WayOfReward.RewardAd; } public void ShareShareAppMessageByType(ShareType _shareType = ShareType.ShareAppOriginImg) { HCDebugger.LogDebug("ShareShareAppMessageByType, type : " + _shareType); ShareNormalImg(); } public void ShowShareMenu() { #if H5_WX ShowShareMenuOption ssmo = new ShowShareMenuOption(); ssmo.menus = new string[] { "shareAppMessage", "shareTimeline" }; WX.ShowShareMenu(ssmo); #endif } public void HideShareMenu() { #if H5_WX HideShareMenuOption hsmo = new HideShareMenuOption(); hsmo.menus = new string[] { "shareAppMessage", "shareTimeline" }; WX.HideShareMenu(hsmo); #endif } /// /// 直接调用分享 分享当前界面截图 /// public void ShareAppMessageOriginImg() { #if H5_WX ShareAppMessageOption samo = new ShareAppMessageOption(); int tipIndex = GetRandomIndex(); samo.title = GetRandomShareTips(tipIndex); //samo.imageUrlId = "这是图片路径ID"; //samo.path ="独立分包路径"; WX.ShareAppMessage(samo); #endif } /// /// 分享随机大图 /// public void ShareAppMessageFixedImg() { #if H5_WX ShareAppMessageOption samo = new ShareAppMessageOption(); int tipIndex = GetRandomIndex(); samo.title = GetRandomShareTips(tipIndex); string img2 = string.Format("{0}ShareImg/ShareImg{1}.png", cdnPath, (tipIndex+1)); samo.imageUrl = img2; // string.Format("{0}/ShareImg/ShareImg{1}.png", cdnPath, (tipIndex+1)); //samo.imageUrlId = "这是图片路径ID"; //samo.path ="独立分包路径"; WX.ShareAppMessage(samo); #endif } /// /// 随机一个分享文本 /// /// private string GetRandomShareTips(int _index) { return shareTipsArr[_index]; } /// /// 随机一个数 0-9 /// /// private int GetRandomIndex() { int randomIndex = UnityEngine.Random.Range(0, shareTipsArr.Length); return randomIndex; } public void ShowShareImageMenu() { #if H5_WX ShowShareImageMenuOption ssimo = new ShowShareImageMenuOption(); ssimo.path = "Share.png"; WX.ShowShareImageMenu(ssimo); #endif } #region dy /// /// 录屏 只支持安卓 /// public void ScreenRecordingLogic(SCLCategory sCLCategory, string title, List topics, System.Action actA = null) { switch (sCLCategory) { case SCLCategory.开始: HCDebugger.LogDebug("call StartRecord"); HCSDKManager.Instance.StartRecord(true, 600, () => { HCDebugger.LogDebug("开始录制"); }, (errcode, errmsg) => { HCDebugger.LogDebug("录制错误:" + errcode + "," + errmsg); }, (_videoPath) => { HCDebugger.LogDebug("video path : " + _videoPath); }); break; case SCLCategory.结束: HCDebugger.LogDebug("call StopRecord"); HCSDKManager.Instance.StopRecord((videopath) => { HCDebugger.LogDebug("录制成功,存放路径为" + videopath); }, (err, errmsg) => { HCDebugger.LogDebug("录制错误:" + err + "," + errmsg); }); break; case SCLCategory.分享: HCDebugger.LogDebug("call GetVideoRecordState"); int tipIndex = GetRandomIndex(); string titleTemp = GetRandomShareTips(tipIndex); HCSDKManager.Instance.DyShareRecordVideo(titleTemp, topics.ToArray(), (_onShareVideoSuccessCallback,msg,resDic) => { if (_onShareVideoSuccessCallback) { HCDebugger.LogDebug("分享成功,获得奖励"); actA?.Invoke(); } else { if (msg.Equals("cancelled")) { HCDebugger.LogDebug("取消分享"); } else { if (msg.ToLower().Contains("short")) { HCDebugger.LogDebug("录制时间少于3s,请重新录制"); PopupTipsPanel.PopupTips("录制时间少于3s,请重新录制"); } else { HCDebugger.LogDebug("分享失败,请重新录制"); PopupTipsPanel.PopupTips("分享失败,请重新录制"); } } } }); break; default: break; } } public enum SCLCategory { 开始 = 0, 结束, 分享, None, } public void ShareNormalImg() { int tipIndex = GetRandomIndex(); string imgUrl = string.Format("{0}ShareImg/ShareImg{1}.png", cdnPath, (tipIndex + 1)); HCSDKManager.Instance.Share(GetRandomShareTips(tipIndex), imgUrl); } #endregion #endregion }