1348 lines
35 KiB
C#
1348 lines
35 KiB
C#
// ***********************************************************************
|
||
// Assembly : Game
|
||
// Author : Kimch
|
||
// Created : 2020-12-07
|
||
// Description :
|
||
// Last Modified By :
|
||
// Last Modified On :
|
||
// ***********************************************************************
|
||
// <copyright file= "KPlatform" company="Kunpo"></copyright>
|
||
// <summary></summary>
|
||
// ***********************************************************************
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
namespace G
|
||
{
|
||
/// <summary>
|
||
/// 平台
|
||
/// </summary>
|
||
partial class KPlatform : MonoBehaviour
|
||
{
|
||
public class ShareInfo
|
||
{
|
||
public string title;
|
||
public string imgUrl;
|
||
public string imgUrlId;
|
||
public string data;
|
||
}
|
||
|
||
[System.Serializable]
|
||
public class InviteInfo
|
||
{
|
||
public string userId;
|
||
public string type;
|
||
|
||
public override string ToString()
|
||
{
|
||
return $"userId={userId}&type={type}";
|
||
}
|
||
}
|
||
|
||
#region Field
|
||
|
||
private IPlatformWapper _platform;
|
||
|
||
#endregion
|
||
|
||
#region Property
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public IPlatformWapper platformWapper => _platform;
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public string platformName
|
||
{
|
||
get { return _platform?.name; }
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public string appId
|
||
{
|
||
get { return _platform?.appId; }
|
||
}
|
||
|
||
public string envVersion
|
||
{
|
||
get
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is KPlatform.WechatPlatform wp)
|
||
{
|
||
return wp.envVersion;
|
||
}
|
||
#endif
|
||
return "";
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region Method
|
||
|
||
|
||
#endregion
|
||
|
||
#region Unity && Instance
|
||
|
||
public static event System.Action<bool> ApplicationFocusEvent;
|
||
|
||
public static KPlatform Instance;
|
||
|
||
private void Awake()
|
||
{
|
||
Instance = this;
|
||
Init();
|
||
}
|
||
|
||
// Update is called once per frame
|
||
private void Update()
|
||
{
|
||
#if UNITY_ANDROID
|
||
if (Input.GetKeyDown(KeyCode.Escape))
|
||
{
|
||
UI.MessageBox.ShowMessage("退出游戏", "确定要离开吗",
|
||
() => Application.Quit(),
|
||
() => { });
|
||
}
|
||
#endif
|
||
}
|
||
|
||
private void OnApplicationFocus(bool focus)
|
||
{
|
||
ApplicationFocusEvent?.Invoke(focus);
|
||
}
|
||
|
||
private void OnApplicationQuit()
|
||
{
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 初始化
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public bool initSuccess
|
||
{
|
||
get;
|
||
private set;
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public void Init()
|
||
{
|
||
#if UNITY_EDITOR
|
||
Invoke(nameof(OnInitSuccess), 0.01f);
|
||
#elif SDK_OHAYOO
|
||
_platform = this.gameObject.AddComponent<OhayooPlatform>();
|
||
#elif SDK_ONESDK
|
||
_platform = this.gameObject.AddComponent<OneSDKPlatform>();
|
||
#elif SDK_WECHAT_WASM
|
||
_platform = this.gameObject.AddComponent<WechatPlatform>();
|
||
#else
|
||
Invoke(nameof(OnInitSuccess), 0.01f);
|
||
#endif
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public void OnInitSuccess()
|
||
{
|
||
initSuccess = true;
|
||
if (_platform != null)
|
||
{
|
||
Debug.Log("OnInitSuccess");
|
||
//_platform.NormalLogin();
|
||
LoadRewardAd(2, "init");
|
||
KStatistics.Instance.ReportEvent_GameInit(1, "sdk", 0, 0);
|
||
}
|
||
else
|
||
{
|
||
this.OnLoginSuccess(SystemInfo.deviceUniqueIdentifier, "", 0, 1);
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 信息
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public string platform
|
||
{
|
||
get
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
return wechatPlatform.platform;
|
||
}
|
||
#endif
|
||
return Application.platform.ToString();
|
||
}
|
||
}
|
||
|
||
private string _deviceId = string.Empty;
|
||
/// <summary>Gets or sets the open identifier.</summary>
|
||
public string deviceId
|
||
{
|
||
get { return !string.IsNullOrEmpty(_deviceId) ? _deviceId : SystemInfo.deviceUniqueIdentifier; }
|
||
set { _deviceId = value; }
|
||
}
|
||
|
||
/// <summary>Gets or sets the channel.</summary>
|
||
public int channel
|
||
{
|
||
get
|
||
{
|
||
#if UNITY_EDITOR
|
||
return 25;
|
||
#elif SDK_WECHAT_WASM
|
||
return 3;
|
||
#else
|
||
return 26;
|
||
#endif
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public string subChanel
|
||
{
|
||
get
|
||
{
|
||
#if UNITY_IOS
|
||
return "ios";
|
||
#elif UNITY_ANDROID
|
||
switch (Application.identifier)
|
||
{
|
||
case "com.kunpo.litaibai.android.ohayoo":
|
||
return "aos";
|
||
case "com.kunpo.litaibai.android.ohayoo.vapp":
|
||
return "vapp";
|
||
case "com.kunpo.litaibai.android.ssjj":
|
||
return "4399";
|
||
case "com.kunpo.litaibai.android.qqers":
|
||
return "7723";
|
||
case "com.kunpo.litaibai.android.cczs":
|
||
return "cczs";
|
||
case "com.kunpo.litaibai.android.uc":
|
||
return "uc";
|
||
case "com.kunpo.litaibai.android.mi":
|
||
return "mi";
|
||
case "com.kunpo.litaibai.android.vivo":
|
||
return "vivo";
|
||
case "com.kunpo.litaibai.android.nearme.gamecenter":
|
||
return "oppo";
|
||
case "com.kunpo.litaibai.android.huawei":
|
||
return "huawei";
|
||
default:
|
||
return "";
|
||
}
|
||
#else
|
||
return "";
|
||
#endif
|
||
}
|
||
}
|
||
|
||
public int safeAreaTop
|
||
{
|
||
get
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
return wechatPlatform.safeAreaTop * 2;
|
||
}
|
||
#endif
|
||
return (int)Screen.safeArea.y;
|
||
}
|
||
}
|
||
|
||
InviteInfo _inviteInfo;
|
||
public InviteInfo inviteInfo
|
||
{
|
||
get { return _inviteInfo; }
|
||
set
|
||
{
|
||
_inviteInfo = value;
|
||
if (ServerProxy.Instance && ServerProxy.Instance.isLoginSuccess)
|
||
{
|
||
ServerProxy.Instance.Invite(inviteInfo.userId, (error, message) =>
|
||
{
|
||
if (error != ErrorCode.NETWORK_ERROR)
|
||
_inviteInfo = null;
|
||
});
|
||
}
|
||
}
|
||
}
|
||
|
||
public int benchmarkLevel
|
||
{
|
||
get
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
return wechatPlatform.benchmarkLevel;
|
||
}
|
||
#endif
|
||
return 30;
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 登录
|
||
|
||
/// <summary>
|
||
/// 账号登录方式
|
||
/// Login type.
|
||
/// </summary>
|
||
public enum LoginType
|
||
{
|
||
/// <summary>
|
||
/// 通过游客方式登录
|
||
/// The login type VISITOR.
|
||
/// </summary>
|
||
LOGIN_TYPE_VISITOR = 1,
|
||
|
||
/// <summary>
|
||
/// 通过头条登录
|
||
/// The login type toutiao.
|
||
/// </summary>
|
||
LOGIN_TYPE_TT = 2,
|
||
|
||
/// <summary>
|
||
/// 通过抖音授权登录
|
||
/// The login type douyin.
|
||
/// </summary>
|
||
LOGIN_TYPE_DY = 3,
|
||
|
||
/// <summary>
|
||
/// 通过手机号登录
|
||
/// The login type phone.
|
||
/// </summary>
|
||
LOGIN_TYPE_PHONE = 4,
|
||
|
||
/// <summary>
|
||
/// 通过苹果方式登录
|
||
/// The login type APPLE.
|
||
/// </summary>
|
||
LOGIN_TYPE_APPLE = 5
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public LoginType loginType
|
||
{
|
||
get;
|
||
set;
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public LoginType lastLoginType
|
||
{
|
||
get;
|
||
set;
|
||
}
|
||
|
||
/// <summary>
|
||
/// ==1 成功 2失败 3 cancel
|
||
/// </summary>
|
||
public int loginStatus
|
||
{
|
||
get;
|
||
private set;
|
||
}
|
||
|
||
private string _openId = string.Empty;
|
||
/// <summary>Gets or sets the open identifier.</summary>
|
||
public string openId
|
||
{
|
||
get => _openId;
|
||
private set { _openId = value; }
|
||
}
|
||
|
||
private string _openToken = string.Empty;
|
||
/// <summary>Gets or sets the open token.</summary>
|
||
public string openToken
|
||
{
|
||
get => _openToken;
|
||
private set { _openToken = value; }
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public string loginTypeText
|
||
{
|
||
get
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
return "点击复制";
|
||
#else
|
||
switch (loginType)
|
||
{
|
||
case LoginType.LOGIN_TYPE_VISITOR:
|
||
return "游客";
|
||
case LoginType.LOGIN_TYPE_TT:
|
||
return "头条";
|
||
case LoginType.LOGIN_TYPE_DY:
|
||
return "抖音";
|
||
case LoginType.LOGIN_TYPE_PHONE:
|
||
return "手机号";
|
||
case LoginType.LOGIN_TYPE_APPLE:
|
||
return "苹果";
|
||
}
|
||
return "游客";
|
||
#endif
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 正常登陆 NormalLogin = 1,// 账号绑定 AccountBind = 2,// 切换账号 SwitchAccount = 3,
|
||
/// </summary>
|
||
public int loginInvokeMode
|
||
{
|
||
get;
|
||
private set;
|
||
}
|
||
|
||
public bool supportSwitchAccount
|
||
{
|
||
get
|
||
{
|
||
#if SDK_WECHAT_WASM || SDK_ONESDK
|
||
return false;
|
||
#else
|
||
return true;
|
||
#endif
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public void NormalLogin()
|
||
{
|
||
loginStatus = 0;
|
||
if (_platform != null)
|
||
_platform.NormalLogin();
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public void SwitchAccount()
|
||
{
|
||
if (_platform != null)
|
||
_platform.SwitchAccount();
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public void VisitorBindAccount()
|
||
{
|
||
if (_platform != null)
|
||
_platform.VisitorBindAccount();
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public bool IsVisitor()
|
||
{
|
||
if (_platform != null)
|
||
return _platform.IsVisitor();
|
||
return true;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 注销帐号
|
||
/// </summary>
|
||
public void Logoff(System.Action<string> onSuccess, System.Action<int, string> onFail)
|
||
{
|
||
if (_platform != null)
|
||
_platform.Logoff(onSuccess, onFail);
|
||
else
|
||
onSuccess?.Invoke("");
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="openId"></param>
|
||
/// <param name="openToken"></param>
|
||
/// <param name="loginType">通过游客方式登录 LOGIN_TYPE_VISITOR = 1, 通过OneSdk方式登录 = 100</param>
|
||
/// <param name="loginInvokeMode">// 正常登陆 NormalLogin = 1,// 账号绑定 AccountBind = 2,// 切换账号 SwitchAccount = 3,</param>
|
||
public void OnLoginSuccess(string openId, string openToken, int loginType, int loginInvokeMode)
|
||
{
|
||
this.openId = openId;
|
||
this.openToken = openToken;
|
||
this.lastLoginType = this.loginType;
|
||
this.loginType = (LoginType)loginType;
|
||
this.loginInvokeMode = loginInvokeMode;
|
||
|
||
loginStatus = 1;
|
||
ServerProxy.Instance.OnSDKLogin(openId, openToken, loginType, loginInvokeMode);
|
||
ArchiveProxy.Instance.OnSDKLogin(openId, openToken, loginType, loginInvokeMode);
|
||
KStatistics.Instance.ReportEvent_GameLogin(openId, loginType.ToString());
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="error"></param>
|
||
/// <param name="errorMsg"></param>
|
||
/// <param name="apiLoginType">// 正常登录 Login = 1, // 账号绑定 AccountBind = 2,// 切换账号 SwitchAccount = 3,</param>
|
||
public void OnLoginFailure(int error, string errorMsg, int apiLoginType)
|
||
{
|
||
loginStatus = 2;
|
||
ServerProxy.Instance.OnSDKLoginFail(error, errorMsg, apiLoginType);
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="errorMsg"></param>
|
||
public void OnLoginCancel(string errorMsg)
|
||
{
|
||
loginStatus = 3;
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 广告
|
||
|
||
private int _adDelay;
|
||
|
||
private bool _autoPlayAd;
|
||
private bool _rewardVerify;
|
||
|
||
float _lastPlayAd = -20f;
|
||
|
||
string _adType = "";
|
||
string _adScene = "";
|
||
string _stageId = "";
|
||
|
||
Callback2 _adCallback;
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="type"></param>
|
||
/// <param name="scene"></param>
|
||
/// <param name="callback"></param>
|
||
public void PlayRewardAd(string type, string scene, Callback2 callback)
|
||
{
|
||
PlayRewardAd(type, scene, "", callback);
|
||
}
|
||
|
||
public void PlayRewardAd(string adType, string adScene, string stageId, Callback2 callback)
|
||
{
|
||
#if DEBUG_MY && !UNITY_WEBGL
|
||
if (KGMOptions.BlockAd)
|
||
{
|
||
Debug.Log(adScene + " 广告播放成功");
|
||
MissionProxy.Instance.OnEvent(MissionProxy.观看视频次数);
|
||
GlobalNotifier.PostNotification(GlobalDefine.EVENT_PLAY_AD_SUCCESS);
|
||
callback?.Invoke(0, "");
|
||
return;
|
||
}
|
||
#endif
|
||
if (_platform != null)
|
||
{
|
||
SetAdParams(adType, adScene, stageId, callback);
|
||
PlayRewardAd();
|
||
}
|
||
else
|
||
{
|
||
Debug.Log(adScene + "广告播放成功");
|
||
MissionProxy.Instance.OnEvent(MissionProxy.观看视频次数);
|
||
GlobalNotifier.PostNotification(GlobalDefine.EVENT_PLAY_AD_SUCCESS, "广告播放成功");
|
||
callback?.Invoke(0, "");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="adType"></param>
|
||
/// <param name="adScene"></param>
|
||
/// <param name="stageId"></param>
|
||
/// <param name="callback"></param>
|
||
private void SetAdParams(string adType, string adScene, string stageId, Callback2 callback)
|
||
{
|
||
_adType = adType;
|
||
_adScene = adScene;
|
||
_stageId = stageId;
|
||
_adCallback = callback;
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
private void ResetAdParams()
|
||
{
|
||
_adType = "";
|
||
_adScene = "";
|
||
_stageId = "";
|
||
_adCallback = null;
|
||
}
|
||
|
||
private void PauseGame(bool pause)
|
||
{
|
||
if (pause)
|
||
{
|
||
Launch.PauseGame(true);
|
||
KUIWindow.OpenWindow<UI.PauseWindow>();
|
||
}
|
||
else
|
||
{
|
||
Launch.PauseGame(false);
|
||
KUIWindow.CloseWindow<UI.PauseWindow>();
|
||
}
|
||
}
|
||
|
||
private void PlayRewardAd()
|
||
{
|
||
if (Time.realtimeSinceStartup - _lastPlayAd < 20f)
|
||
{
|
||
GlobalNotifier.PostNotification(GlobalDefine.EVENT_SHOW_TOAST, "请勿短时间内频繁观看广告,请稍后再看");
|
||
return;
|
||
}
|
||
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
// step3. 广告曝光上报
|
||
// 与广告关联,将以下代码片段埋入如激励广告的曝光(广告组件中的show事件)
|
||
|
||
// step3. 广告曝光上报
|
||
wechatPlatform.ReportUserBehaviorBranchAnalytics("BCBgAAoXHx5d1nii-BqWRt", _adScene, 1);
|
||
}
|
||
#endif
|
||
|
||
int showResult = _platform.ShowRewardAd(_adScene);
|
||
if (showResult == 0)
|
||
{
|
||
_autoPlayAd = false;
|
||
_lastPlayAd = Time.realtimeSinceStartup;
|
||
PauseGame(true);
|
||
}
|
||
else if (showResult == 2)//没有加载广告 请先加载广告
|
||
{
|
||
_autoPlayAd = true;
|
||
LoadRewardAd(0, "play");
|
||
GlobalNotifier.PostNotification(GlobalDefine.EVENT_SHOW_TOAST, "加载广告,请耐心等待.");
|
||
}
|
||
else if (showResult == 1)
|
||
{
|
||
_autoPlayAd = true;
|
||
GlobalNotifier.PostNotification(GlobalDefine.EVENT_SHOW_TOAST, "广告正在加载中,请耐心等待.");
|
||
}
|
||
}
|
||
|
||
private void LoadRewardAd(int delay, string source)
|
||
{
|
||
StartCoroutine(LoadAdCO(delay));
|
||
}
|
||
|
||
private IEnumerator LoadAdCO(int delay)
|
||
{
|
||
if (delay > 0)
|
||
{
|
||
yield return new WaitForSeconds(delay);
|
||
}
|
||
_platform?.LoadRewardVideoAd_V();
|
||
}
|
||
|
||
public void OnRewardedAdShow()
|
||
{
|
||
KStatistics.Instance.ReportEventShowAd("reward", _adType, _adScene, _stageId);
|
||
}
|
||
|
||
public void OnRewardClick()
|
||
{
|
||
KStatistics.Instance.ReportEventClickAd("reward", _adScene, _stageId);
|
||
}
|
||
|
||
private void OnRewardVerify(bool rewardVerify, float rewardAmount, string rewardName)
|
||
{
|
||
_rewardVerify = rewardVerify;
|
||
}
|
||
|
||
public void OnVideoComplete()
|
||
{
|
||
|
||
}
|
||
|
||
public void OnRewardedAdClosed()
|
||
{
|
||
PauseGame(false);
|
||
|
||
if (_rewardVerify)
|
||
{
|
||
_adCallback?.Invoke(0, null);
|
||
MissionProxy.Instance.OnEvent(MissionProxy.观看视频次数);
|
||
GlobalNotifier.PostNotification(GlobalDefine.EVENT_PLAY_AD_SUCCESS, "广告播放成功");
|
||
KStatistics.Instance.ReportEventShowEndAd("reward", _adType, _adScene, "success", _stageId);
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
// step3. 广告曝光上报
|
||
// 与广告关联,将以下代码片段埋入如激励广告的曝光(广告组件中的show事件)
|
||
|
||
// step3. 广告曝光上报
|
||
wechatPlatform.ReportUserBehaviorBranchAnalytics("BCBgAAoXHx5d1nii-BqWRt", _adScene, 2);
|
||
}
|
||
#endif
|
||
}
|
||
else
|
||
{
|
||
_adCallback?.Invoke(-1, "广告播放失败,无法获得奖励");
|
||
KStatistics.Instance.ReportEventShowEndAd("reward", _adType, _adScene, "failure", _stageId);
|
||
}
|
||
|
||
_rewardVerify = false;
|
||
ResetAdParams();
|
||
|
||
LoadRewardAd(2, "ad_closed");
|
||
}
|
||
|
||
public void OnVideoError()
|
||
{
|
||
_adCallback?.Invoke(1, "广告播放错误,请检查网络连接");
|
||
KStatistics.Instance.ReportEventShowEndAd("reward", _adType, _adScene, "error", _stageId);
|
||
ResetAdParams();
|
||
GlobalNotifier.PostNotification(GlobalDefine.EVENT_SHOW_TOAST, "广告播放错误,请检查网络连接");
|
||
GlobalNotifier.PostNotification(GlobalDefine.EVENT_PLAY_AD_ERROR, "广告播放错误,请检查网络连接");
|
||
}
|
||
|
||
public void OnSkippedVideo()
|
||
{
|
||
if (_rewardVerify)
|
||
return;
|
||
_adCallback?.Invoke(2, "跳过广告播放,无法获得奖励");
|
||
KStatistics.Instance.ReportEventShowEndAd("reward", _adType, _adScene, "skip", _stageId);
|
||
ResetAdParams();
|
||
GlobalNotifier.PostNotification(GlobalDefine.EVENT_SHOW_TOAST, "跳过广告播放,无法获得奖励");
|
||
GlobalNotifier.PostNotification(GlobalDefine.EVENT_PLAY_AD_SKIP, "跳过广告播放,无法获得奖励");
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public void OnRewardVideoAdLoad()
|
||
{
|
||
_adDelay = 0;
|
||
|
||
if (_autoPlayAd)
|
||
{
|
||
_autoPlayAd = false;
|
||
if (_platform?.ShowRewardAd(_adScene) == 0)
|
||
{
|
||
PauseGame(true);
|
||
}
|
||
}
|
||
GlobalNotifier.PostNotification(GlobalDefine.EVENT_AD_LOAD_SUCCESS, "广告加载成功");
|
||
}
|
||
|
||
/// <summary>
|
||
/// // 广告加载失败,对应参数为,错误码 + 错误信息
|
||
/// </summary>
|
||
public void OnRewardVideoAdLoadError(int error, string message)
|
||
{
|
||
_adDelay += 30;
|
||
LoadRewardAd(_adDelay, "ad_error");
|
||
GlobalNotifier.PostNotification(GlobalDefine.EVENT_AD_LOAD_SUCCESS, "广告加载失败");
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 兑换
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="redeemCode"></param>
|
||
public void Redeem(string redeemCode)
|
||
{
|
||
if (!string.IsNullOrEmpty(redeemCode))
|
||
{
|
||
_platform?.Redeem(redeemCode);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="json"></param>
|
||
private void OnRedeemSuccess(string json)
|
||
{
|
||
if (!string.IsNullOrEmpty(json))
|
||
{
|
||
var packet = new GamePacket
|
||
{
|
||
id = 90,
|
||
data = json
|
||
};
|
||
GlobalNotifier.PostNotification(GlobalDefine.EVENT_NETWORK_PACKET, packet, "sdk");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="code"></param>
|
||
/// <param name="error"></param>
|
||
private void OnRedeemError(int code, string error)
|
||
{
|
||
GlobalNotifier.PostNotification(GlobalDefine.EVENT_SHOW_TOAST, error);
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region Ab Test
|
||
|
||
public string GetAbConfig(string key, string defaultValue)
|
||
{
|
||
#if (UNITY_EDITOR || DEBUG_MY)
|
||
return KGMOptions.AB_Version;
|
||
#else
|
||
if (initSuccess && _platform != null)
|
||
{
|
||
var result = _platform.GetAbConfig(key, defaultValue);
|
||
return result;
|
||
}
|
||
return null;
|
||
#endif
|
||
}
|
||
|
||
/// <summary>
|
||
/// 默认
|
||
/// </summary>
|
||
/// <param name="key"></param>
|
||
/// <param name="value">默认 null</param>
|
||
/// <returns></returns>
|
||
public bool IsAbConfig(string key, string value)
|
||
{
|
||
#if !UNITY_WEBGL && (UNITY_EDITOR || DEBUG_MY)
|
||
return KGMOptions.AB_Version == value;
|
||
#elif UNITY_ANDROID
|
||
//Debug.Log("key" + _platform.GetAbConfig(key, "{\"key\":\"0\"}"));
|
||
return value == _platform.GetAbConfig(key, "{\"key\":\"0\"}");
|
||
#elif UNITY_IOS
|
||
var result = _platform.GetAbConfig(key, "0");
|
||
if (string.IsNullOrEmpty(value))
|
||
return result == "0";
|
||
return result == value;
|
||
#else
|
||
return false;
|
||
#endif
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 统计
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="key"></param>
|
||
/// <param name="value"></param>
|
||
public void SetEventCommonHeader(string key, string value)
|
||
{
|
||
_platform?.SetEventCommonHeader(key, value);
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="label"></param>
|
||
/// <param name="paramJson"></param>
|
||
public void ReportEvent(string label, string paramJson)
|
||
{
|
||
_platform?.ReportEvent(label, paramJson);
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 支付
|
||
|
||
public bool QueryPay()
|
||
{
|
||
return false;
|
||
#if SDK_OHAYOO
|
||
return false;
|
||
#elif SDK_WECHAT_WASM
|
||
|
||
#if UNITY_EDITOR
|
||
return true;
|
||
|
||
#else
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
return wechatPlatform.QueryPay();
|
||
}
|
||
return false;
|
||
#endif
|
||
|
||
#else
|
||
return true;
|
||
#endif
|
||
}
|
||
|
||
public void Pay(object payInfo, Callback2 callback)
|
||
{
|
||
#if UNITY_EDITOR
|
||
callback?.Invoke(0, "测试环境 支付成功");
|
||
#elif SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
wechatPlatform.Pay(payInfo, callback);
|
||
}
|
||
else
|
||
{
|
||
callback?.Invoke(0, "测试环境 支付成功");
|
||
}
|
||
#endif
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 分享
|
||
|
||
public void Share(ShareInfo shareInfo, Callback2 callback)
|
||
{
|
||
#if UNITY_EDITOR
|
||
callback?.Invoke(0, "测试环境,分享成功");
|
||
#elif SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
wechatPlatform.Share(shareInfo, callback);
|
||
}
|
||
#endif
|
||
}
|
||
|
||
public void JumpToApp(string appId, string extraData)
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
wechatPlatform.JumpToApp(appId, extraData);
|
||
}
|
||
#endif
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 客服
|
||
|
||
public void OpenCustomerServiceConversation()
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
wechatPlatform.OpenCustomerServiceConversation();
|
||
}
|
||
#else
|
||
Application.OpenURL("https://docs.qq.com/form/page/DTXpuUmpaQkdsU1RW#/fill");
|
||
#endif
|
||
}
|
||
|
||
public void OpenFeedback()
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
wechatPlatform.OpenCustomerServiceConversation();
|
||
}
|
||
#else
|
||
Application.OpenURL("https://docs.qq.com/form/page/DTXpuUmpaQkdsU1RW#/fill");
|
||
#endif
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 微信开放域
|
||
|
||
public void ShowOpenData(Texture texture, RectInt rect)
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
wechatPlatform.ShowOpenData(texture, rect.x, rect.y, rect.width, rect.height);
|
||
}
|
||
#endif
|
||
}
|
||
|
||
public void HideOpenData()
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
wechatPlatform.HideOpenData();
|
||
}
|
||
#endif
|
||
}
|
||
|
||
public void SetUserCloundStorage(IDictionary<string, string> kvData, Callback2 callback)
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
wechatPlatform.SetUserCloudStorage(kvData, callback);
|
||
}
|
||
#endif
|
||
}
|
||
|
||
public void RemoveUserCloudStorage(ICollection<string> keys, Callback2 callback)
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
wechatPlatform.RemoveUserCloudStorage(keys, callback);
|
||
}
|
||
#endif
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 交互
|
||
|
||
/// <summary>
|
||
/// 显示 loading 提示框。需主动调用 wx.hideLoading 才能关闭提示框
|
||
/// </summary>
|
||
/// <param name="title"></param>
|
||
/// <param name="mask">是否显示透明蒙层,防止触摸穿透</param>
|
||
public void ShowLoading(string title, bool mask)
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
wechatPlatform.ShowLoading(title, mask);
|
||
}
|
||
#endif
|
||
}
|
||
|
||
/// <summary>
|
||
/// 隐藏 loading 提示框
|
||
/// </summary>
|
||
public void HideLoading()
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
wechatPlatform.HideLoading();
|
||
}
|
||
#endif
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public void ShowToast()
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
wechatPlatform.ShowToast();
|
||
}
|
||
#endif
|
||
}
|
||
|
||
public void HideToast()
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
wechatPlatform.HideToast();
|
||
}
|
||
#endif
|
||
}
|
||
|
||
public void ShowModal()
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
wechatPlatform.ShowModal();
|
||
}
|
||
#endif
|
||
}
|
||
|
||
public void CreateGameClubButton()
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
wechatPlatform.CreateGameClubButton();
|
||
}
|
||
#endif
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 其它
|
||
|
||
/// <summary>
|
||
/// 应用内引导评分
|
||
/// </summary>
|
||
public void InAppRating()
|
||
{
|
||
if (_platform != null)
|
||
_platform.InAppRating();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 验证敏感词.
|
||
/// </summary>
|
||
/// <param name="sensitiveWords">输入的敏感词信息.</param>
|
||
/// <param name="verifyResult">返回的敏感词结果.</param>
|
||
public void VerifySensitiveWords(string sensitiveWords, System.Action<int> verifyResult)
|
||
{
|
||
if (_platform != null)
|
||
_platform.VerifySensitiveWords(sensitiveWords, verifyResult);
|
||
else
|
||
{
|
||
verifyResult?.Invoke(0);
|
||
}
|
||
}
|
||
|
||
public bool IsOppoLeisureChannel()
|
||
{
|
||
#if SDK_ONESDK
|
||
if (_platform is OneSDKPlatform oneSDK)
|
||
{
|
||
return oneSDK.IsOppoLeisureChannel();
|
||
}
|
||
#endif
|
||
return false;
|
||
}
|
||
|
||
public void OppoLeisureJump()
|
||
{
|
||
#if SDK_ONESDK
|
||
if (_platform is OneSDKPlatform oneSDK)
|
||
{
|
||
oneSDK.OppoLeisureJump();
|
||
}
|
||
#endif
|
||
}
|
||
|
||
public void OpenWebView(string url)
|
||
{
|
||
if (_platform != null)
|
||
{
|
||
_platform.OpenWebView(url);
|
||
}
|
||
else
|
||
{
|
||
Application.OpenURL(url);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="data"></param>
|
||
/// <returns>show toast</returns>
|
||
public bool SetClipboardData(string data)
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
wechatPlatform.SetClipboardData(data);
|
||
}
|
||
return false;
|
||
#else
|
||
GlobalUtils.CopyToClipboard(data);
|
||
return true;
|
||
#endif
|
||
}
|
||
|
||
public void GetClipboardData(Callback3 callback)
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
wechatPlatform.GetClipboardData(callback);
|
||
}
|
||
#else
|
||
callback?.Invoke(0, "", GlobalUtils.GetClipboard());
|
||
#endif
|
||
}
|
||
|
||
/// <summary>
|
||
/// heavy、medium、light
|
||
/// </summary>
|
||
public void VibrateShort(int type)
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
wechatPlatform.VibrateShort(type);
|
||
}
|
||
#else
|
||
Handheld.Vibrate();
|
||
#endif
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public void VibrateLong()
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
wechatPlatform.VibrateLong();
|
||
}
|
||
#else
|
||
Handheld.Vibrate();
|
||
#endif
|
||
}
|
||
|
||
public void PlayMusic(string music, float volume)
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
wechatPlatform.PlayMusic(music, volume);
|
||
}
|
||
#endif
|
||
}
|
||
|
||
public void PauseMusic(bool pause)
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
wechatPlatform.PauseMusic(pause);
|
||
}
|
||
#endif
|
||
}
|
||
|
||
public void PreLoadAudio(string[] audios)
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
wechatPlatform.PreLoadShortAudio(audios);
|
||
}
|
||
#endif
|
||
}
|
||
|
||
public void PlayAudio(string audio, float volume)
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
wechatPlatform.PlayShortAudio(audio, volume);
|
||
}
|
||
#endif
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public void GetUserNickName(Callback2 callback)
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
wechatPlatform.GetUserNickName(callback);
|
||
}
|
||
#endif
|
||
}
|
||
|
||
public void ClearCache()
|
||
{
|
||
#if SDK_WECHAT_WASM
|
||
if (_platform is WechatPlatform wechatPlatform)
|
||
{
|
||
wechatPlatform.ClearCache();
|
||
}
|
||
#endif
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 隐私政策
|
||
|
||
public bool supportPrivacyProtocol
|
||
{
|
||
get
|
||
{
|
||
#if SDK_WECHAT_WASM || SDK_ONESDK
|
||
return false;
|
||
#else
|
||
return true;
|
||
#endif
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public void OpenUserProtocol()
|
||
{
|
||
#if !SDK_WECHAT_WASM
|
||
_platform?.OpenUserProtocol();
|
||
#endif
|
||
//Application.OpenURL("https://kunpo.cc/tos");
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public void OpenPrivacyProtocol()
|
||
{
|
||
#if !SDK_WECHAT_WASM
|
||
Kunpo.Privacy.PrivacyProxy.OpenPrivacyTerms();
|
||
#endif
|
||
//Application.OpenURL("https://kunpo.cc/privacy");
|
||
//_platform?.OpenPrivacyProtocol();
|
||
}
|
||
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
public void OpenIdentifyProtocol()
|
||
{
|
||
_platform?.OpenIdentifyProtocol();
|
||
}
|
||
|
||
public void OpenLogoffProtocol()
|
||
{
|
||
#if !SDK_WECHAT_WASM
|
||
Kunpo.Privacy.PrivacyProxy.OpenLogoff();
|
||
#endif
|
||
}
|
||
|
||
#endregion
|
||
|
||
}
|
||
}
|