chicken_dy/Assets/TKGSDK/Common/GameInterface/TKGSDKManager.cs

722 lines
18 KiB
C#
Raw Permalink Normal View History

2022-08-02 05:18:13 +00:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Touka;
2024-03-07 12:12:48 +00:00
using HC;
2022-08-03 09:59:45 +00:00
#if H5_WX
2022-08-03 01:39:10 +00:00
using WeChatWASM;
2022-08-03 09:59:45 +00:00
#endif
2022-08-02 05:18:13 +00:00
2022-08-05 11:47:04 +00:00
#if H5_DY
2024-03-07 12:12:48 +00:00
using HC;
2022-08-05 11:47:04 +00:00
#endif
2022-08-02 05:18:13 +00:00
public class TKGSDKManager : TKGSingleton<TKGSDKManager>
{
2022-08-03 09:59:45 +00:00
#region webgl
2022-08-03 08:14:00 +00:00
2022-08-03 08:27:01 +00:00
//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
2022-08-03 08:14:00 +00:00
string[] shareTipsArr = new string[10] { "靠声音过关的游戏,有点意思~",
"你对声音敏感吗?快来试试吧!",
"高智商玩家的选择能过20关的都不是一般人",
"声音解谜,敢来测测你的游戏水平吗?",
"这游戏脑洞太大,快来帮帮我~",
"这游戏有点难度敢不敢来跟我PK一下",
"好友邀请你PK一局点击加入",
"这游戏笑的我肚子痛~",
"这奇葩结局,必须要跟你分享一下!",
"这声音,建议躲在被窝里玩"};
2022-08-05 11:47:04 +00:00
#endregion
2022-08-03 08:14:00 +00:00
2022-08-02 05:18:13 +00:00
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();
}
/// <summary>
/// init sdk
/// </summary>
/// <param name="_initCallback"></param>
public void InitSDK(Action _initCallback = null)
{
if (isInit) return;
2024-03-07 12:12:48 +00:00
HCSDKManager.Instance.InitializeSdk();
isInit = true;
2022-08-02 05:18:13 +00:00
}
/// <summary>
/// Set game focus
/// </summary>
/// <param name="_gameFocusAction"></param>
public void SetGameFocusListener(Action<bool> _gameFocusAction)
{
2024-03-07 12:12:48 +00:00
HCSDKManager.Instance.SetGameFocusListener = _gameFocusAction;
2022-08-02 05:18:13 +00:00
}
// reward click callback
public void SetRewardClickListener(Action _clickCallback = null)
{
2024-03-07 12:12:48 +00:00
2022-08-02 05:18:13 +00:00
}
/// <summary>
/// Get channel
/// </summary>
/// <returns></returns>
public AppChannel GetChannel()
{
2024-03-07 12:12:48 +00:00
return AppChannel.None;
2022-08-02 05:18:13 +00:00
}
/// <summary>
/// Set log enable
/// </summary>
public void SetLogEnable(bool _enable)
{
2024-03-07 12:12:48 +00:00
2022-08-02 05:18:13 +00:00
}
2022-08-03 09:59:45 +00:00
#region Ads
2022-08-02 05:18:13 +00:00
// 去广告接口调用
public void PurchasedRemoveAds()
{
2024-03-07 12:12:48 +00:00
2022-08-02 05:18:13 +00:00
}
/// <summary>
/// Show Interstitial Ad
/// </summary>
/// <param name="_adPos"> Name of interstitial ad placement. </param>
/// <param name="_callback"> Callback of interstitial ad close and show interstitial failed</param>
/// <param name="_IvType"> IVADType for distinguish interstitial ads frequency, default use iv1</param>
2024-03-07 12:12:48 +00:00
public void ShowInterstitialAd(HCIVPositionName _adPos, Action _callback = null, HCIVADType _IvType = HCIVADType.IV1)
2022-08-02 05:18:13 +00:00
{
2024-03-07 12:12:48 +00:00
HCSDKManager.Instance.ShowInterstitial(_adPos, _IvType, _callback);
2022-08-02 05:18:13 +00:00
}
/// <summary>
/// Show Reward Ad
/// </summary>
/// <param name="_adPos"> Name of reward ad placement</param>
/// <param name="_rewardCallback"> true:reward succ, false: reward failed</param>
/// <param name="_showFailedCallback">Callback of reward ad show fail</param>
2024-03-07 12:12:48 +00:00
public void ShowRewardAd(HCRVPositionName _adPos, Action<bool> _rewardCallback = null, Action _showFailedCallback = null)
2022-08-02 05:18:13 +00:00
{
2024-03-07 12:12:48 +00:00
HCSDKManager.Instance.ShowRewardedAd(_adPos,_rewardCallback, _showFailedCallback);
2022-08-02 05:18:13 +00:00
}
public void ShowNative(RectTransform pRect, Camera pCam = null, string pAdPos = "")
{
2024-03-07 12:12:48 +00:00
2022-08-02 05:18:13 +00:00
}
/// <summary>
/// Is Ready Interstitial
/// </summary>
/// <returns></returns>
public bool IsReadyInterstitialAd()
{
2024-03-07 12:12:48 +00:00
return HCSDKManager.Instance.IsInterstitialReady();
2022-08-02 05:18:13 +00:00
}
/// <summary>
/// Is Ready Reward
/// </summary>
/// <returns></returns>
public bool IsReadyRewardAd()
{
2024-03-07 12:12:48 +00:00
return HCSDKManager.Instance.IsRewardedAdReady();
2022-08-02 05:18:13 +00:00
}
/// <summary>
/// Is Ready Native Ad
/// </summary>
/// <returns></returns>
public bool IsReadyNativeAd()
{
return false;
}
/// <summary>
/// Show banner
/// </summary>
/// <param name="_bannerAlign">bannerAlign</param>
public void ShowBanner(TKGBannerAlign _bannerAlign)
{
2024-03-07 12:12:48 +00:00
HCSDKManager.Instance.ShowBanner();
2022-08-02 05:18:13 +00:00
}
/// <summary>
/// Hide banner
/// </summary>
public void HideBanner()
{
2024-03-07 12:12:48 +00:00
HCSDKManager.Instance.HideBanner();
2022-08-02 05:18:13 +00:00
}
/// <summary>
/// Remove Native
/// </summary>
public void RemoveNative()
{
}
#endregion
#region Log Event
#region Normal
/// <summary>
/// Log Event
/// </summary>
/// <param name="_eventSort"></param>
public void LogEvent(string _eventSort)
{
2024-03-07 12:12:48 +00:00
HCSDKManager.Instance.LogEvent(_eventSort);
2022-08-02 05:18:13 +00:00
}
/// <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)
{
2024-03-07 12:12:48 +00:00
HCSDKManager.Instance.LogEvent(_eventSort,_key,_value);
2022-08-02 05:18:13 +00:00
}
/// <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)
{
2024-03-07 12:12:48 +00:00
HCSDKManager.Instance.LogEvent(_eventSort, _key01, _value01, _key02, _value02);
2022-08-02 05:18:13 +00:00
}
/// <summary>
/// Log Event
/// </summary>
/// <param name="_eventSort"></param>
/// <param name="_eventDic"></param>
2024-03-07 12:12:48 +00:00
public void LogEvent(string _eventSort, Dictionary<string, object> _eventDic = null)
2022-08-02 05:18:13 +00:00
{
2024-03-07 12:12:48 +00:00
HCSDKManager.Instance.LogEvent(_eventSort, _eventDic);
2022-08-02 05:18:13 +00:00
}
#endregion
#region Level Event
/// <summary>
/// Level start
/// </summary>
/// <param name="_level"></param>
public void LevelStart(int _level)
{
2024-03-07 12:12:48 +00:00
// todo
2022-08-02 05:18:13 +00:00
}
/// <summary>
/// Level start
/// </summary>
/// <param name="_level"></param>
public void LevelStart(string _level)
{
2024-03-07 12:12:48 +00:00
2022-08-02 05:18:13 +00:00
}
/// <summary>
/// Level end
/// </summary>
/// <param name="_level"></param>
/// <param name="_win"></param>
2024-03-07 12:12:48 +00:00
public void LevelEnd(int _level, StageResult _stageResult)
2022-08-02 05:18:13 +00:00
{
2024-03-07 12:12:48 +00:00
2022-08-02 05:18:13 +00:00
}
/// <summary>
/// Level end,if return false, it means review pops up.
/// </summary>
/// <param name="_level"></param>
/// <param name="_win"></param>
2024-03-07 12:12:48 +00:00
public void LevelEnd(string _level, StageResult _stageResult)
2022-08-02 05:18:13 +00:00
{
}
2024-03-07 12:12:48 +00:00
private void CheckReviewPop(int pLevel)
2022-08-02 05:18:13 +00:00
{
2024-03-07 12:12:48 +00:00
HCSDKManager.Instance.Review();
2022-08-02 05:18:13 +00:00
}
#endregion
#region Reward Ad Button Show
/// <summary>
/// Log Reward ad button show
/// </summary>
/// <param name="_pos"></param>
public void LogRewardAdBtnShow(string _pos)
{
2024-03-07 12:12:48 +00:00
HCSDKManager.Instance.LogRewardBtnShow(_pos);
2022-08-02 05:18:13 +00:00
}
#endregion
#region Tracking Event
/// <summary>
/// Log Tracking Event
/// </summary>
/// <param name="_eventType"></param>
private void LogTrackingEvent(TrackingEventType _eventType)
{
2024-03-07 12:12:48 +00:00
2022-08-02 05:18:13 +00:00
}
#endregion
#endregion
#region Online Config
/// <summary>
/// get config - string
/// </summary>
/// <param name="_key"></param>
/// <returns></returns>
public string GetConfigStr(TKGParamKey _key)
{
2024-03-07 12:12:48 +00:00
return HCSDKManager.Instance.GetRemoteConfigStr(_key.ToString(),"");
2022-08-02 05:18:13 +00:00
}
/// <summary>
/// get config - int
/// </summary>
/// <param name="_key"></param>
/// <returns></returns>
public int GetConfigInt(TKGParamKey _key)
{
2024-03-07 12:12:48 +00:00
return HCSDKManager.Instance.GetRemoteConfigInt(_key.ToString(),0);
2022-08-02 05:18:13 +00:00
}
/// <summary>
/// get config - bool
/// </summary>
/// <param name="_key"></param>
/// <returns></returns>
public bool GetConfigBool(TKGParamKey _key)
{
2024-03-07 12:12:48 +00:00
return HCSDKManager.Instance.GetRemoteConfigBool(_key.ToString(),false);
2022-08-02 05:18:13 +00:00
}
#endregion
#region Others (common)
/// <summary>
/// review
/// </summary>
public void Review()
{
2024-03-07 12:12:48 +00:00
HCSDKManager.Instance.Review();
2022-08-02 05:18:13 +00:00
}
/// 使用 OpenPolicyPop 接口 === Use OpenPolicyPop
/// 使用 OpenPolicyPop 接口 === Use OpenPolicyPop
/// 使用 OpenPolicyPop 接口 === Use OpenPolicyPop
/// <summary>
/// open privacy url
/// </summary>
//public void OpenPrivacyURL()
//{
// m_sdkInterface.OpenPrivacyURL();
//}
/// 使用 OpenPolicyPop 接口 === Use OpenPolicyPop
/// 使用 OpenPolicyPop 接口 === Use OpenPolicyPop
/// 使用 OpenPolicyPop 接口 === Use OpenPolicyPop
/// <summary>
/// open user agreement url
/// </summary>
//public void OpenUserTermURL()
//{
// m_sdkInterface.OpenUserTermURL();
//}
/// <summary>
/// open more game
/// </summary>
public void OpenMoreGame()
{
2024-03-07 12:12:48 +00:00
2022-08-02 05:18:13 +00:00
}
/// <summary>
/// open url by browser
/// </summary>
/// <param name="_url"></param>
public void OpenUrlByBrowser(string _url)
{
}
public void OpenPolicyPop()
{
}
/// <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)
{
}
/// <summary>
/// share txt
/// </summary>
/// <param name="_shareTxt"></param>
public void Share(string shareText)
{
}
/// <summary>
/// regist APNS
/// </summary>
public void RegistAPNS()
{
}
/// <summary>
/// shake
/// </summary>
/// <param name="notiName">notification identifier</param>
/// <param name="body">The body of the notification.</param>
/// <param name="fireDate">notify after the time interval. format:yyyy-MM-dd HH:mm:ss </param>
/// <param name="badge">The application badge number.</param>
/// <param name="title">The title of the notification.</param>
/// <param name="subTitle">The subtitle of the notification.</param>
public void RegistNotification(string notiId, string body, string fireDate, int badge = 1, string title = "", string subTitle = "")
{
}
/// <summary>
/// remove all notification
/// </summary>
public void RemoveAllNotifications()
{
}
/// <summary>
/// remove notification by notification identifier
/// </summary>
/// <param name="notiId">notification identifier</param>
public void RemoveNotification(string notiId)
{
}
2022-08-03 09:59:45 +00:00
#endregion
2022-08-02 05:18:13 +00:00
2022-08-03 09:59:45 +00:00
#region others
2022-08-02 05:18:13 +00:00
/// <summary>
/// Set user source listener
/// only call first can back source
/// </summary>
/// <param name="_userSourceAction"> true : origin userfalse : not origin user </param>
public void SetUserSourceListener(Action<bool, string> _userSourceAction)
{
}
/// <summary>
/// set common callback
/// </summary>
/// <param name="_commonCallbackAction"></param>
public void SetTKGCommonCallback(Action<CommonCallbackCode, string> _commonCallbackAction)
{
}
2022-08-03 09:59:45 +00:00
#endregion
2022-08-02 05:18:13 +00:00
2022-08-03 09:59:45 +00:00
#region h5
2022-08-02 05:18:13 +00:00
2022-08-03 08:14:00 +00:00
public enum WayOfReward
{
None,
Share,
RewardAd,
}
public enum ShareType
{
None,
ShareAppOriginImg,
ShareAppFixedImg,
}
public WayOfReward GetRewardWay()
{
2022-08-08 12:14:47 +00:00
#if H5_DY
return WayOfReward.RewardAd;
#elif H5_WX
2022-08-03 08:14:00 +00:00
return WayOfReward.Share;
2022-08-08 12:14:47 +00:00
#endif
2022-08-09 06:35:45 +00:00
return WayOfReward.RewardAd;
2022-08-03 08:14:00 +00:00
}
public void ShareShareAppMessageByType(ShareType _shareType = ShareType.ShareAppOriginImg)
{
2024-03-07 12:12:48 +00:00
HCDebugger.LogDebug("ShareShareAppMessageByType, type : " + _shareType);
2022-08-05 11:47:04 +00:00
ShareNormalImg();
2022-08-03 08:14:00 +00:00
}
2022-08-03 01:39:10 +00:00
public void ShowShareMenu()
{
2022-08-03 09:59:45 +00:00
#if H5_WX
2022-08-03 01:39:10 +00:00
ShowShareMenuOption ssmo = new ShowShareMenuOption();
ssmo.menus = new string[] { "shareAppMessage", "shareTimeline" };
WX.ShowShareMenu(ssmo);
2022-08-03 09:59:45 +00:00
#endif
2022-08-03 01:39:10 +00:00
}
2022-08-02 05:18:13 +00:00
2022-08-03 01:39:10 +00:00
public void HideShareMenu()
{
2022-08-03 09:59:45 +00:00
#if H5_WX
2022-08-03 01:39:10 +00:00
HideShareMenuOption hsmo = new HideShareMenuOption();
hsmo.menus = new string[] { "shareAppMessage", "shareTimeline" };
WX.HideShareMenu(hsmo);
2022-08-03 09:59:45 +00:00
#endif
2022-08-03 01:39:10 +00:00
}
2022-08-03 08:14:00 +00:00
/// <summary>
/// 直接调用分享 分享当前界面截图
/// </summary>
2022-08-03 01:39:10 +00:00
public void ShareAppMessageOriginImg()
{
2022-08-03 09:59:45 +00:00
#if H5_WX
2022-08-03 01:39:10 +00:00
ShareAppMessageOption samo = new ShareAppMessageOption();
2022-08-03 08:14:00 +00:00
int tipIndex = GetRandomIndex();
samo.title = GetRandomShareTips(tipIndex);
2022-08-03 01:39:10 +00:00
//samo.imageUrlId = "这是图片路径ID";
//samo.path ="独立分包路径";
WX.ShareAppMessage(samo);
2022-08-03 09:59:45 +00:00
#endif
2022-08-03 01:39:10 +00:00
}
2022-08-03 08:14:00 +00:00
/// <summary>
/// 分享随机大图
/// </summary>
public void ShareAppMessageFixedImg()
2022-08-03 01:39:10 +00:00
{
2022-08-03 09:59:45 +00:00
#if H5_WX
2022-08-03 01:39:10 +00:00
ShareAppMessageOption samo = new ShareAppMessageOption();
2022-08-03 08:14:00 +00:00
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));
2022-08-03 01:39:10 +00:00
//samo.imageUrlId = "这是图片路径ID";
//samo.path ="独立分包路径";
WX.ShareAppMessage(samo);
2022-08-03 09:59:45 +00:00
#endif
2022-08-03 01:39:10 +00:00
}
2022-08-03 08:14:00 +00:00
/// <summary>
/// 随机一个分享文本
/// </summary>
/// <returns></returns>
private string GetRandomShareTips(int _index)
{
return shareTipsArr[_index];
}
/// <summary>
/// 随机一个数 0-9
/// </summary>
/// <returns></returns>
private int GetRandomIndex()
{
int randomIndex = UnityEngine.Random.Range(0, shareTipsArr.Length);
return randomIndex;
}
2022-08-03 01:39:10 +00:00
public void ShowShareImageMenu()
{
2022-08-03 09:59:45 +00:00
#if H5_WX
2022-08-03 01:39:10 +00:00
ShowShareImageMenuOption ssimo = new ShowShareImageMenuOption();
ssimo.path = "Share.png";
WX.ShowShareImageMenu(ssimo);
2022-08-03 09:59:45 +00:00
#endif
2022-08-03 01:39:10 +00:00
}
2022-08-02 05:18:13 +00:00
2022-08-08 12:14:47 +00:00
#region dy
2022-08-05 11:47:04 +00:00
/// <summary>
/// 录屏 只支持安卓
/// </summary>
public void ScreenRecordingLogic(SCLCategory sCLCategory, string title, List<string> topics, System.Action actA = null)
{
2022-08-08 12:14:47 +00:00
2024-03-07 12:12:48 +00:00
2022-08-05 11:47:04 +00:00
switch (sCLCategory)
{
case SCLCategory.:
2024-03-07 12:12:48 +00:00
HCDebugger.LogDebug("call StartRecord");
HCSDKManager.Instance.StartRecord(true, 600, () => { HCDebugger.LogDebug("开始录制"); }, (errcode, errmsg) => { HCDebugger.LogDebug("录制错误:" + errcode + "," + errmsg); }, (_videoPath) => { HCDebugger.LogDebug("video path : " + _videoPath); });
2022-08-05 11:47:04 +00:00
break;
case SCLCategory.:
2024-03-07 12:12:48 +00:00
HCDebugger.LogDebug("call StopRecord");
HCSDKManager.Instance.StopRecord((videopath) => { HCDebugger.LogDebug("录制成功,存放路径为" + videopath); }, (err, errmsg) => { HCDebugger.LogDebug("录制错误:" + err + "," + errmsg); });
2022-08-05 11:47:04 +00:00
break;
case SCLCategory.:
2024-03-07 12:12:48 +00:00
HCDebugger.LogDebug("call GetVideoRecordState");
int tipIndex = GetRandomIndex();
string titleTemp = GetRandomShareTips(tipIndex);
HCSDKManager.Instance.DyShareRecordVideo(titleTemp, topics.ToArray(), (_onShareVideoSuccessCallback,msg,resDic) =>
2022-08-05 11:47:04 +00:00
{
2024-03-07 12:12:48 +00:00
if (_onShareVideoSuccessCallback)
{
HCDebugger.LogDebug("分享成功,获得奖励");
actA?.Invoke();
}
else
{
if (msg.Equals("cancelled"))
2022-08-05 11:47:04 +00:00
{
2024-03-07 12:12:48 +00:00
HCDebugger.LogDebug("取消分享");
2022-08-05 11:47:04 +00:00
}
else
{
2024-03-07 12:12:48 +00:00
if (msg.ToLower().Contains("short"))
{
HCDebugger.LogDebug("录制时间少于3s请重新录制");
PopupTipsPanel.PopupTips("录制时间少于3s请重新录制");
}
else
{
HCDebugger.LogDebug("分享失败,请重新录制");
PopupTipsPanel.PopupTips("分享失败,请重新录制");
}
2022-08-05 11:47:04 +00:00
}
2024-03-07 12:12:48 +00:00
}
});
2022-08-05 11:47:04 +00:00
break;
default:
break;
}
2024-03-07 12:12:48 +00:00
2022-08-05 11:47:04 +00:00
}
public enum SCLCategory
{
= 0,
,
,
None,
}
public void ShareNormalImg()
{
int tipIndex = GetRandomIndex();
string imgUrl = string.Format("{0}ShareImg/ShareImg{1}.png", cdnPath, (tipIndex + 1));
2024-03-07 12:12:48 +00:00
HCSDKManager.Instance.Share(GetRandomShareTips(tipIndex), imgUrl);
2022-08-05 11:47:04 +00:00
}
2022-08-08 12:14:47 +00:00
#endregion
2022-08-05 11:47:04 +00:00
2022-08-08 12:14:47 +00:00
#endregion
2022-08-02 05:18:13 +00:00
}