SDK相关的整理
This commit is contained in:
@@ -1,130 +0,0 @@
|
||||
import { _decorator, Node } from 'cc';
|
||||
import ChannelCfg, { Channel_C } from './ChannelCfg';
|
||||
import GlobalValue from '../Common/GlobalValue';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
|
||||
export enum DominIp {
|
||||
/**本地内网渠道-H5 */
|
||||
Local_C = 1,
|
||||
Local_H5 = 999999,
|
||||
Local_Test = 555,
|
||||
Local_H5_NoRecharge = 999998,
|
||||
Android_TapTap = 7100101,
|
||||
Android_Yuwan = 7100102,
|
||||
wechat_Yuwan = 7100103,
|
||||
|
||||
Android_Zongyou = 7100201,
|
||||
}
|
||||
|
||||
//渠道功能开关
|
||||
export enum ChannelFun {
|
||||
/**微信广告 */
|
||||
wxAd = 1,
|
||||
/**企业微信 */
|
||||
qywx,
|
||||
/**微信游戏圈 */
|
||||
wxClub,
|
||||
/**微信公众号 */
|
||||
wxGZH,
|
||||
/**微信订阅 */
|
||||
wxSubs,
|
||||
/**广邀战友-每日分享 */
|
||||
wxDayShare,
|
||||
}
|
||||
|
||||
|
||||
@ccclass('BuildUtil')
|
||||
export default class BuildUtil {
|
||||
private static _I: BuildUtil = null;
|
||||
public static get I(): BuildUtil {
|
||||
if (!BuildUtil._I) {
|
||||
BuildUtil._I = new BuildUtil();
|
||||
BuildUtil._I.init();
|
||||
}
|
||||
return BuildUtil._I;
|
||||
}
|
||||
|
||||
/**版本号 */
|
||||
private gVersion = `v1.0.`;
|
||||
/**当前线上版本号 */
|
||||
private v_Version = 1;
|
||||
/**当前线上资源上传时间 */
|
||||
private res_Version = '20230101';
|
||||
/**根据不同包==变动的值 */
|
||||
private BuilderChannel = 1;
|
||||
/**是否是正式包 */
|
||||
private isRelease = true;
|
||||
private ChannleInfo: Channel_C = null;
|
||||
private funsList;
|
||||
|
||||
|
||||
init() {
|
||||
this.v_Version = 1;
|
||||
this.res_Version = '20240110';
|
||||
this.BuilderChannel = DominIp.Local_C;
|
||||
// ChannelLogin.I;
|
||||
|
||||
let ScenType = this.getQueryValue("GameScen");
|
||||
if (ScenType) {
|
||||
this.BuilderChannel = +ScenType; //在字符串前面添加+号,可以将string转化为numbre(字符串内容为数字时才有意义)
|
||||
}
|
||||
let JumpGuide = this.getQueryValue("JumpGuide");
|
||||
if (JumpGuide == 'true') {//是否跳过新手引导
|
||||
// GlobalValue.g_Guide = false;
|
||||
}
|
||||
let DBProject = this.getQueryValue("DBProject");
|
||||
if (DBProject == 'true') {//是否是测试包
|
||||
this.isRelease = false;
|
||||
}
|
||||
|
||||
let HG_Channel = window['HG_Channel'];
|
||||
if (HG_Channel) {
|
||||
this.ChannleInfo = HG_Channel;
|
||||
this.BuilderChannel = +this.ChannleInfo.GameId;
|
||||
}
|
||||
let HG_Version = window['HG_Version'];
|
||||
if (HG_Version) {
|
||||
this.v_Version = HG_Version.version;
|
||||
this.res_Version = HG_Version.verExt;
|
||||
}
|
||||
let HG_DomainCfg = window['HG_DomainCfg'];
|
||||
if (HG_DomainCfg) {
|
||||
GlobalValue.m_DomainData = JSON.parse(JSON.stringify(HG_DomainCfg));
|
||||
window['HG_DomainCfg'] = null;
|
||||
}
|
||||
let HG_LoginCfg = window['HG_LoginCfg'];
|
||||
if (HG_LoginCfg) {
|
||||
GlobalValue.g_ChannelCfg = JSON.parse(JSON.stringify(HG_LoginCfg));
|
||||
window['HG_LoginCfg'] = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**获取渠道信息 */
|
||||
get getChannelInfo(): Channel_C {
|
||||
if (this.ChannleInfo) {
|
||||
return this.ChannleInfo;
|
||||
} else {
|
||||
return ChannelCfg.I.getChannelInfo(this.BuilderChannel);
|
||||
}
|
||||
}
|
||||
|
||||
/**H5链接包截取链接参数 */
|
||||
getQueryValue(key) {
|
||||
if (window.location.search) {
|
||||
var query = window.location.search.substring(1);
|
||||
var vars = query.split("&");
|
||||
for (var i = 0; i < vars.length; i++) {
|
||||
var pair = vars[i].split("=");
|
||||
if (pair[0] == key) {
|
||||
return pair[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,128 +0,0 @@
|
||||
import { _decorator, Component, Node } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('ChannelCfg')
|
||||
export default class ChannelCfg {
|
||||
private static _I: ChannelCfg = null;
|
||||
public static get I(): ChannelCfg {
|
||||
if (!ChannelCfg._I) {
|
||||
ChannelCfg._I = new ChannelCfg();
|
||||
ChannelCfg._I.init();
|
||||
}
|
||||
return ChannelCfg._I;
|
||||
}
|
||||
|
||||
|
||||
private ZhuZuo = '著作权人:北京爱游飞天科技有限公司 出版单位:北京中科奥科技有限公司 ISBN:978-7-498-06347-2 审批文号:国新出审[2019]1120号 来文文号:京新广文[2018]206号 软著号:2017SR724614';
|
||||
private ChannelInfo = {
|
||||
1: {//内网
|
||||
CHAppId: 'test',
|
||||
CHChnlId: 'test',
|
||||
ChannelApplyId: 'test',
|
||||
ZhuZuo: this.ZhuZuo,
|
||||
getDomain: 'http://fishres.hgwl710.com/getGZDomainFacInner.html',
|
||||
RealeseCfg: `http://123.52.43.116:40433/fish3/cfg/`,
|
||||
DebugCfg: `http://123.52.43.116:40433/fish3/cfg/`,
|
||||
RealeseRes: ``,
|
||||
DebugRes: ``,
|
||||
},
|
||||
999999: {//内网
|
||||
CHAppId: 'h5',
|
||||
CHChnlId: 'h5',
|
||||
ChannelApplyId: 'h5',
|
||||
ZhuZuo: this.ZhuZuo,
|
||||
getDomain: 'http://fishres.hgwl710.com/Fish/getDomainFacInner.html',
|
||||
RealeseCfg: `http://fishres.hgwl710.com/Fish/DEV/TS/cfg/`,
|
||||
DebugCfg: `http://fishres.hgwl710.com/Fish/DEV/TS/cfg/`,
|
||||
RealeseRes: `http://tk3h5.hgwl710.com/Fish/DEV/TS/Res/`,
|
||||
DebugRes: `http://tk3h5.hgwl710.com/Fish/DEV/TS/Res/`,
|
||||
},
|
||||
555: {//内网
|
||||
CHAppId: 'zy',
|
||||
CHChnlId: 'zy',
|
||||
ChannelApplyId: 'zy',
|
||||
ZhuZuo: this.ZhuZuo,
|
||||
getDomain: 'http://fishres.hgwl710.com/NewFish3/getGZDomainFacOnline.html',
|
||||
RealeseCfg: `http://fishres.hgwl710.com/NewFish3/Android/zongyou/ZS/cfg/`,
|
||||
DebugCfg: `http://fishres.hgwl710.com/NewFish3/Android/zongyou/TS/cfg/`,
|
||||
RealeseRes: ``,
|
||||
DebugRes: ``,
|
||||
},
|
||||
999998: {//内网网页端,无支付模式
|
||||
CHAppId: 'h5_norecharge',
|
||||
CHChnlId: 'h5_norecharge',
|
||||
ChannelApplyId: 'h5_norecharge',
|
||||
ZhuZuo: this.ZhuZuo,
|
||||
getDomain: 'http://fishres.hgwl710.com/Fish/getDomainFacInner.html',
|
||||
RealeseCfg: `http://fishres.hgwl710.com/Fish/DEV/TS/cfg/`,
|
||||
DebugCfg: `http://fishres.hgwl710.com/Fish/DEV/TS/cfg/`,
|
||||
RealeseRes: `http://tk3h5.hgwl710.com/Fish/DEV/TS/Res/`,
|
||||
DebugRes: `http://tk3h5.hgwl710.com/Fish/DEV/TS/Res/`,
|
||||
},
|
||||
7100201: {
|
||||
CHAppId: 'zy',
|
||||
CHChnlId: 'zy',
|
||||
ChannelApplyId: 'zy',
|
||||
GameId: 7100201,
|
||||
ZhuZuo: '著作权人:北京爱游飞天科技有限公司 出版单位:北京中科奥科技有限公司 ISBN:978-7-498-06347-2 审批文号:国新出审[2019]1120号 来文文号:京新广文[2018]206号 软著号:2017SR724614',
|
||||
getDomain: 'http://fishres.hgwl710.com/NewFish3/getGZDomainFacOnline.html',
|
||||
RealeseCfg: `http://fishres.hgwl710.com/NewFish3/Android/zongyou/ZS/cfg/`,
|
||||
DebugCfg: `http://fishres.hgwl710.com/NewFish3/Android/zongyou/TS/cfg/`,
|
||||
RealeseRes: ``,
|
||||
DebugRes: ``,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private C_Info = null;
|
||||
init() {
|
||||
this.C_Info = {};
|
||||
for (const key in this.ChannelInfo) {
|
||||
let c_cfg = this.ChannelInfo[key];
|
||||
let cc_C = new Channel_C();
|
||||
for (const key in c_cfg) {
|
||||
cc_C[key] = c_cfg[key];
|
||||
}
|
||||
this.C_Info[key] = cc_C;
|
||||
}
|
||||
}
|
||||
|
||||
getChannelInfo(type: number): Channel_C {
|
||||
return this.C_Info[type];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export class Channel_C {
|
||||
/**草花应用ID */
|
||||
CHAppId: '';
|
||||
/**草花渠道ID */
|
||||
CHChnlId: '';
|
||||
/**渠道应用ID */
|
||||
ChannelApplyId: '';
|
||||
/**游戏ID */
|
||||
GameId: '';
|
||||
/**游戏秘钥 */
|
||||
GameKey: '';
|
||||
/**投放渠道ID */
|
||||
TouFangId: '';
|
||||
/**投放子渠道ID */
|
||||
TouFangSubId: '';
|
||||
IMEI: 'H5-WeChat';
|
||||
Version: '';
|
||||
UId: '';
|
||||
MacAddress: '';
|
||||
SystemModel: '';
|
||||
Platform: 'H5';
|
||||
AppVersionCode: 'windows';
|
||||
wechatID: 0; //草花微信小程序ID
|
||||
offerID: 0;//微信小程序 offerID
|
||||
ZhuZuo: '';
|
||||
getDomain: '';
|
||||
RealeseCfg: '';
|
||||
DebugCfg: '';
|
||||
RealeseRes: '';
|
||||
DebugRes: '';
|
||||
privacyAgreement: '';//隐私协议
|
||||
}
|
||||
|
||||
@@ -6,6 +6,11 @@ import { sys } from "cc";
|
||||
*/
|
||||
export class PlatformHelper {
|
||||
|
||||
/** 是否Luffa平台 */
|
||||
public static isLuffa(): boolean {
|
||||
return sys.platform === sys.Platform.WECHAT_GAME && typeof window["wx"] !== "undefined";
|
||||
}
|
||||
|
||||
/** 是否微信小游戏 */
|
||||
public static isWechat(): boolean {
|
||||
return sys.platform === sys.Platform.WECHAT_GAME && typeof window["wx"] !== "undefined";
|
||||
@@ -73,6 +78,7 @@ export class PlatformHelper {
|
||||
|
||||
/** 获取当前平台名称(调试用) */
|
||||
public static getPlatformName(): string {
|
||||
if (this.isLuffa()) return "Luffa平台";
|
||||
if (this.isWechat()) return "微信小游戏";
|
||||
if (this.isByteDance()) return "字节跳动小游戏";
|
||||
if (this.isKuaishou()) return "快手小游戏";
|
||||
|
||||
@@ -1,346 +1,188 @@
|
||||
import { _decorator, Component, sys, utils } from "cc";
|
||||
import Utils from "../Common/Utils";
|
||||
import { WXSDK } from "./wxSDK";
|
||||
import { ByteDanceSDK } from "./bdSDK";
|
||||
import { WebSDK } from "./webSDK";
|
||||
import { KSSDK } from "./ksSDK";
|
||||
import AudioManager from "../Manager/AudioManager";
|
||||
import GlobalValue, { VideoRoleType } from "../Common/GlobalValue";
|
||||
import { luffaSDK } from "./luffaSDK";
|
||||
import { logger } from "db://assets/Scripts/Main/Common/Logger";
|
||||
import { PlatformHelper } from "./PlatformHelper";
|
||||
import { IAdSDK } from "./core/IAdSDK";
|
||||
import { IWalletSDK } from "./core/IWalletSDK";
|
||||
import { IPlatformSDK } from "./core/IPlatformSDK";
|
||||
import { IAnalyticsSDK } from "./core/IAnalyticsSDK";
|
||||
import { WxPlatformSDK } from "./platform/WxPlatformSDK";
|
||||
import { WxAdSDK } from "./ads/WxAdSDK";
|
||||
import { LuffaWalletSDK } from "./wallet/LuffaWalletSDK";
|
||||
import { UmaAnalyticsSDK } from "./analytics/UmaAnalyticsSDK";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/**运行渠道 */
|
||||
export enum E_SDK_Channel {
|
||||
/**微信 */
|
||||
WX,
|
||||
/**字节跳动 (抖音、头条) */
|
||||
BD,
|
||||
/**网页 */
|
||||
WEB,
|
||||
/**快手 */
|
||||
KS,
|
||||
}
|
||||
|
||||
/**玩家SDK信息 */
|
||||
export interface I_SDK_UserInfo {
|
||||
/**昵称 */
|
||||
nickName: string;
|
||||
/**头像url */
|
||||
avatarUrl: string;
|
||||
}
|
||||
|
||||
/**玩家SDK信息回调 */
|
||||
export interface I_SDK_UserInfo_Callback {
|
||||
(info: I_SDK_UserInfo): void;
|
||||
}
|
||||
|
||||
//渠道管理器
|
||||
// 渠道管理器
|
||||
@ccclass('SDKManager')
|
||||
export class SDKManager { //extends Component
|
||||
export class SDKManager {
|
||||
private static _I: SDKManager = null;
|
||||
public static get I(): SDKManager {
|
||||
if (!SDKManager._I) {
|
||||
SDKManager._I = new SDKManager();
|
||||
SDKManager._I.init();
|
||||
}
|
||||
return SDKManager._I;
|
||||
}
|
||||
// 广告,分享
|
||||
private adSDK: IAdSDK | null = null;
|
||||
// 钱包
|
||||
private walletSDK: IWalletSDK | null = null;
|
||||
// 平台基础
|
||||
private platformSDK: IPlatformSDK | null = null;
|
||||
// 分析统计
|
||||
private analyticsSDK: IAnalyticsSDK | null = null;
|
||||
|
||||
private init(){
|
||||
}
|
||||
initEmpty(){
|
||||
}
|
||||
|
||||
//玩家头像
|
||||
private static _avatarUrl: string = "";
|
||||
public static get avatarUrl(): string {
|
||||
return SDKManager._avatarUrl;
|
||||
}
|
||||
public static set avatarUrl(value: string) {
|
||||
if (value == null) {
|
||||
value = "";
|
||||
}
|
||||
SDKManager._avatarUrl = value;
|
||||
}
|
||||
|
||||
//玩家昵称
|
||||
private static _nickName: string = "";
|
||||
public static get nickName(): string {
|
||||
return SDKManager._nickName;
|
||||
}
|
||||
public static set nickName(value: string) {
|
||||
if (value == null) {
|
||||
value = "游客";
|
||||
}
|
||||
SDKManager._nickName = value;
|
||||
}
|
||||
private constructor() {
|
||||
|
||||
}
|
||||
|
||||
private static sdk_channel:E_SDK_Channel = E_SDK_Channel.WEB //当前SDK渠道
|
||||
private static video_reward_map:any
|
||||
private static share_reward_map:any
|
||||
private static sdk:any
|
||||
// 初始化
|
||||
public init(cb: Function = null) {
|
||||
logger.info("SDKManager 初始化...");
|
||||
// 检测平台
|
||||
if (PlatformHelper.isKuaishou()) {
|
||||
// 快手
|
||||
|
||||
//初始化SDK
|
||||
static init(cb: Function = null) {
|
||||
this.video_reward_map = {}
|
||||
this.share_reward_map = {}
|
||||
|
||||
logger.log("平台值 wx:",window["wx"], typeof window["wx"])
|
||||
logger.log("平台值 ks:",window["ks"], typeof window["ks"])
|
||||
logger.log("平台值 tt:",window["tt"], typeof window["tt"])
|
||||
} else if (PlatformHelper.isWechat()) {
|
||||
// 微信
|
||||
this.adSDK = new WxAdSDK();
|
||||
this.platformSDK = new WxPlatformSDK();
|
||||
} else if (PlatformHelper.isLuffa()) {
|
||||
// Luffa
|
||||
this.walletSDK = new LuffaWalletSDK();
|
||||
} else if (PlatformHelper.isByteDance()) {
|
||||
// 字节跳动
|
||||
|
||||
if (PlatformHelper.isKuaishou()) {
|
||||
this.sdk_channel = E_SDK_Channel.KS
|
||||
this.sdk = new KSSDK() //快手
|
||||
}else if (PlatformHelper.isWechat()) {
|
||||
this.sdk_channel = E_SDK_Channel.WX
|
||||
this.sdk = new luffaSDK() //微信
|
||||
} else if (PlatformHelper.isByteDance()) {
|
||||
this.sdk_channel = E_SDK_Channel.BD
|
||||
this.sdk = new ByteDanceSDK() //抖音(头条)
|
||||
} else {
|
||||
this.sdk_channel = E_SDK_Channel.WEB
|
||||
this.sdk = new WebSDK()
|
||||
}
|
||||
} else {
|
||||
|
||||
logger.log("当前平台:", PlatformHelper.getPlatformName(), this.sdk_channel)
|
||||
if (GlobalValue.NpcVideoMod) {
|
||||
GlobalValue.NpcVideoMod = this.sdk_channel === E_SDK_Channel.WX || this.sdk_channel === E_SDK_Channel.WEB
|
||||
}
|
||||
|
||||
this.sdk.init(cb)
|
||||
|
||||
SDKManager.umaInit();
|
||||
}
|
||||
|
||||
|
||||
/**是否是微信平台 */
|
||||
static isWenxin() {
|
||||
return this.sdk_channel === E_SDK_Channel.WX
|
||||
}
|
||||
/**是否是抖音平台 */
|
||||
static isByteDance() {
|
||||
return this.sdk_channel === E_SDK_Channel.BD
|
||||
}
|
||||
/**是否是快手平台 */
|
||||
static isKuaishou() {
|
||||
return this.sdk_channel === E_SDK_Channel.KS
|
||||
}
|
||||
/**是否是web平台 */
|
||||
static isWeb() {
|
||||
return this.sdk_channel === E_SDK_Channel.WEB
|
||||
}
|
||||
|
||||
|
||||
//SDK登录,并返回code
|
||||
static login(cb: Function = null) {
|
||||
this.sdk.login(cb)
|
||||
}
|
||||
|
||||
//检查玩家权限
|
||||
//autoKey 授权类型 : userInfo=用户信息
|
||||
static checkAutoSetting(autoKey:string, cb:Function = null) {
|
||||
this.sdk.checkAutoSetting(autoKey, cb)
|
||||
}
|
||||
|
||||
//获取用户信息
|
||||
static getUserInfo(cb:Function = null) {
|
||||
this.sdk.getUserInfo(cb)
|
||||
}
|
||||
|
||||
//注册视频广告回调
|
||||
static register_video_reward(uuid:string, func:Function) {
|
||||
let video_reward_map = this.video_reward_map || {};
|
||||
video_reward_map[uuid] = func
|
||||
|
||||
this.video_reward_map = video_reward_map;
|
||||
}
|
||||
|
||||
//注册分享回调
|
||||
static register_share_reward(uuid:string, func:Function) {
|
||||
let share_reward_map = this.share_reward_map || {};
|
||||
share_reward_map[uuid] = func
|
||||
|
||||
this.share_reward_map = share_reward_map;
|
||||
}
|
||||
|
||||
//执行视频广告回调
|
||||
private static dispatch_video_reward(uuid:string, tag:number) {
|
||||
let video_reward_map = this.video_reward_map || {};
|
||||
let register_func:Function = video_reward_map[uuid];
|
||||
if (register_func) {
|
||||
register_func(tag)
|
||||
}
|
||||
}
|
||||
|
||||
//执行分享回调
|
||||
private static dispatch_share_reward(uuid:string, tag:number) {
|
||||
let share_reward_map = this.share_reward_map || {};
|
||||
let register_func:Function = share_reward_map[uuid];
|
||||
if (register_func) {
|
||||
register_func(tag)
|
||||
}
|
||||
}
|
||||
|
||||
//视频广告
|
||||
static show_reward_video_ad(uuid:string, tag: number) {
|
||||
SDKManager.video_ad_pre();
|
||||
this.sdk.show_video(()=>{
|
||||
this.dispatch_video_reward(uuid,tag)
|
||||
});
|
||||
}
|
||||
//看视频广告前
|
||||
static video_ad_pre() {
|
||||
logger.log("SDKManager 视频广告前")
|
||||
AudioManager.I.PauseMusic();
|
||||
}
|
||||
//看视频广告后返回游戏
|
||||
static video_ad_back() {
|
||||
logger.log("SDKManager 视频广告后")
|
||||
AudioManager.I.ResumeMusic();
|
||||
}
|
||||
|
||||
//插屏广告
|
||||
static show_interstitial_ad() {
|
||||
this.sdk.show_splash();
|
||||
}
|
||||
|
||||
//展示BANNER
|
||||
static show_banner_ad() {
|
||||
this.sdk.show_banner();
|
||||
}
|
||||
|
||||
//隐藏BANNBER
|
||||
static hide_banner_ad() {
|
||||
this.sdk.hide_banner();
|
||||
}
|
||||
|
||||
//主动拉起分享
|
||||
static show_share() {
|
||||
this.sdk.show_share();
|
||||
}
|
||||
|
||||
//分享得奖励
|
||||
static show_reward_share(uuid:string, tag: number) {
|
||||
this.sdk.show_share(()=>{
|
||||
this.dispatch_share_reward(uuid,tag)
|
||||
});
|
||||
}
|
||||
|
||||
//获取设备分辨率
|
||||
static getWindowSize() {
|
||||
return this.sdk.getWindowSize();
|
||||
}
|
||||
|
||||
/**显示游戏圈
|
||||
* @param leftRatio 左边距占屏幕宽度的比例
|
||||
* @param topRatio 顶部边距占屏幕高度的比例
|
||||
* @param widthRatio 游戏圈宽度占屏幕宽度的比例
|
||||
* @param heightRatio 游戏圈高度占屏幕高度的比例
|
||||
*/
|
||||
static show_gameClub(leftRatio, topRatio, widthRatio, heightRatio) {
|
||||
this.sdk.show_gameClub(leftRatio, topRatio, widthRatio, heightRatio);
|
||||
}
|
||||
//隐藏游戏圈
|
||||
static hide_gameClub() {
|
||||
this.sdk.hide_gameClub();
|
||||
}
|
||||
|
||||
|
||||
/**检查是否支持base64音频播放*/
|
||||
static checkSupportBase64Audio() {
|
||||
return this.sdk.checkSupportBase64Audio();
|
||||
}
|
||||
/**播放base64音频 */
|
||||
static playBase64Audio(base64: string, loop: boolean = false) {
|
||||
this.sdk.playBase64Audio(base64, loop);
|
||||
}
|
||||
|
||||
|
||||
//记录GM日志
|
||||
private static _gmLogString: string = "";
|
||||
private static _gmLogCount: number = 0; //记录日志条数
|
||||
static get GMLogString(): string {
|
||||
return SDKManager._gmLogString;
|
||||
}
|
||||
static ShowGMLog(log: string){
|
||||
Utils.Log(log);
|
||||
if (SDKManager._gmLogCount > 100){
|
||||
SDKManager.ClearGMLog();
|
||||
}
|
||||
SDKManager._gmLogString += log + "\n";
|
||||
SDKManager._gmLogCount++;
|
||||
}
|
||||
static ClearGMLog(){
|
||||
SDKManager._gmLogString = "";
|
||||
SDKManager._gmLogCount = 0;
|
||||
}
|
||||
|
||||
// 默认加载 UMA 分析
|
||||
this.analyticsSDK = new UmaAnalyticsSDK();
|
||||
|
||||
/**是否支持客服功能 */
|
||||
static KefuSupport() {
|
||||
return this.sdk.kefuSupport();
|
||||
}
|
||||
/**打开客服 */
|
||||
static OpenKefu() {
|
||||
this.sdk.openKefu();
|
||||
// 初始化各模块
|
||||
this.adSDK?.init();
|
||||
this.walletSDK?.init();
|
||||
this.platformSDK?.init();
|
||||
this.analyticsSDK?.init();
|
||||
|
||||
// 回调
|
||||
cb && cb();
|
||||
}
|
||||
|
||||
/**
|
||||
* 销毁所有 SDK
|
||||
*
|
||||
* - 逐个调用各 SDK 的 `destroy` 方法
|
||||
* - 用于游戏退出、切换账号、切换平台时释放资源
|
||||
* - 调用时机:游戏关闭 / 重新进入大厅 / SDK 切换
|
||||
*/
|
||||
public destroyAll() {
|
||||
this.adSDK?.destroy?.();
|
||||
this.adSDK = null;
|
||||
this.walletSDK?.destroy?.();
|
||||
this.walletSDK = null;
|
||||
this.platformSDK?.destroy?.();
|
||||
this.platformSDK = null;
|
||||
this.analyticsSDK?.destroy?.();
|
||||
this.analyticsSDK = null;
|
||||
logger.log("所有 SDK 已销毁并清空引用");
|
||||
}
|
||||
|
||||
//region 播放背景视频 cbMap = {cbReady, cbEnded}
|
||||
static PlayBgAudio(remoteUrl:string, loop:boolean = false, extra:any = {}) {
|
||||
this.sdk.playBgAudio(remoteUrl, loop, extra);
|
||||
}
|
||||
//添加要播放的表情视频
|
||||
static AddEmoAudio(remoteUrl:string, vtype:VideoRoleType, loop:boolean = false, extra:any = {}) {
|
||||
this.sdk.addEmoAudio(remoteUrl, vtype, loop, extra);
|
||||
/** --------------------------------------------------------- 广告,分享 --------------------------------------------------------- */
|
||||
|
||||
// 展示激励视频广告
|
||||
public showRewardVideo(cb: (ok: boolean) => void): void {
|
||||
if (!this.adSDK) return;
|
||||
this.adSDK.showRewardVideo(cb)
|
||||
}
|
||||
|
||||
// 展示插屏广告
|
||||
public showInterstitial(): void {
|
||||
if (!this.adSDK) return;
|
||||
this.adSDK.showInterstitial()
|
||||
}
|
||||
|
||||
// 展示 Banner 广告
|
||||
public showBanner(): void {
|
||||
if (!this.adSDK) return;
|
||||
this.adSDK.showBanner()
|
||||
}
|
||||
|
||||
// 隐藏 Banner 广告
|
||||
public hideBanner(): void {
|
||||
if (!this.adSDK) return;
|
||||
this.adSDK.hideBanner()
|
||||
}
|
||||
|
||||
// 主动拉起分享
|
||||
public showShare(cb?: Function): void {
|
||||
if (!this.adSDK) return;
|
||||
this.adSDK.showShare(cb)
|
||||
}
|
||||
|
||||
/** --------------------------------------------------------- 钱包 --------------------------------------------------------- */
|
||||
|
||||
// 获取当前钱包地址
|
||||
public getWalletAddress(): string | null {
|
||||
if (!this.walletSDK) return null;
|
||||
return this.walletSDK.getWalletAddress()
|
||||
}
|
||||
|
||||
/** --------------------------------------------------------- 平台基础 --------------------------------------------------------- */
|
||||
|
||||
// 登录
|
||||
public login(cb?: Function): void {
|
||||
if (!this.platformSDK) return;
|
||||
this.platformSDK.login(cb)
|
||||
}
|
||||
|
||||
// 获取用户信息
|
||||
public getUserInfo(cb: (info: { nickName: string; avatarUrl: string }) => void): void {
|
||||
if (!this.platformSDK) return;
|
||||
this.platformSDK.getUserInfo(cb)
|
||||
}
|
||||
|
||||
// 检查平台权限
|
||||
public checkPermission(scope: string, cb: (granted: boolean) => void): void {
|
||||
if (!this.platformSDK) return;
|
||||
this.platformSDK.checkPermission(scope, cb)
|
||||
}
|
||||
|
||||
|
||||
//region 语音转文字
|
||||
static startRecordRecognition() {
|
||||
if (this.sdk.startRecordRecognition) {
|
||||
this.sdk.startRecordRecognition();
|
||||
} else {
|
||||
Utils.Log("sdk not support startRecordRecognition");
|
||||
}
|
||||
}
|
||||
static stopRecordRecognition() {
|
||||
if (this.sdk.stopRecordRecognition) {
|
||||
this.sdk.stopRecordRecognition();
|
||||
} else {
|
||||
Utils.Log("sdk not support stopRecordRecognition");
|
||||
}
|
||||
// 复制文本到剪贴板
|
||||
public copyToClipboard(text: string, cb?: Function): void {
|
||||
if (!this.platformSDK) return;
|
||||
this.platformSDK.copyToClipboard(text, cb);
|
||||
}
|
||||
|
||||
|
||||
//region 复制到剪贴板
|
||||
/**复制文本到剪贴板 */
|
||||
static copyToClipboard(text: string, cb?: Function) {
|
||||
if (this.sdk.copyToClipboard) {
|
||||
this.sdk.copyToClipboard(text, cb);
|
||||
} else {
|
||||
Utils.Log("当前平台不支持复制功能");
|
||||
cb && cb(false);
|
||||
}
|
||||
// 客服功能是否可用
|
||||
public kefuSupport(): boolean {
|
||||
if (!this.platformSDK) return false;
|
||||
return this.platformSDK.kefuSupport();
|
||||
}
|
||||
|
||||
//region 友盟+
|
||||
static Uma_Event_TalkRound = "_um.talk.round"; //聊天轮次
|
||||
static Uma_Event_LvUnlock = "_um.lv.unlock"; //解锁新关卡
|
||||
/**初始化友盟 */
|
||||
static umaInit() {
|
||||
this.sdk.umaInit();
|
||||
}
|
||||
/**友盟功能是否生效 */
|
||||
static umaSwt() {
|
||||
return this.sdk.umaSwt();
|
||||
}
|
||||
/**友盟事件上报 */
|
||||
static umaEvent(eventName: string, value: any = {}) {
|
||||
this.sdk.umaEvent(eventName, value);
|
||||
}
|
||||
// 打开客服会话
|
||||
public openKefu(): void {
|
||||
if (!this.platformSDK) return;
|
||||
this.platformSDK.openKefu();
|
||||
}
|
||||
|
||||
// 获取设备分辨率
|
||||
public getWindowSize(): { width: number, height: number } {
|
||||
if (!this.platformSDK) return {width: 720, height: 1280};
|
||||
return this.platformSDK.getWindowSize();
|
||||
}
|
||||
|
||||
/** --------------------------------------------------------- 分析统计 --------------------------------------------------------- */
|
||||
|
||||
// 判断统计功能是否可用
|
||||
public isAnalyticsEnabled(): boolean {
|
||||
if (!this.analyticsSDK) return false;
|
||||
return this.analyticsSDK.isAnalyticsEnabled();
|
||||
}
|
||||
|
||||
// 上报事件
|
||||
public trackEvent(eventName: string, value?: any): void {
|
||||
if (!this.analyticsSDK) return;
|
||||
return this.analyticsSDK.trackEvent(eventName, value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "00b997f2-6558-406c-aa8d-0be9f1c6aff4",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { IAdSDK } from "../core/IAdSDK";
|
||||
|
||||
export class WxAdSDK implements IAdSDK {
|
||||
init(cb?: Function): void {
|
||||
console.log("微信广告初始化");
|
||||
cb && cb();
|
||||
}
|
||||
|
||||
// 展示激励视频广告
|
||||
showRewardVideo(cb: (ok: boolean) => void): void {
|
||||
console.log("展示微信激励广告");
|
||||
cb(true);
|
||||
}
|
||||
|
||||
// 展示插屏广告
|
||||
showInterstitial(): void {
|
||||
console.log("展示微信插屏广告");
|
||||
}
|
||||
|
||||
// 展示 Banner 广告
|
||||
showBanner(): void {
|
||||
console.log("展示微信Banner广告");
|
||||
}
|
||||
|
||||
// 隐藏 Banner 广告
|
||||
hideBanner(): void {
|
||||
console.log("隐藏微信Banner广告");
|
||||
}
|
||||
|
||||
// 主动拉起分享
|
||||
showShare(): void {
|
||||
console.log("主动拉起分享");
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ae1fd2cf-a4c5-4d59-baec-dad3b25fe2d2",
|
||||
"uuid": "7dba64ca-42f4-444c-96fc-374d91e5ec90",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "3142b87f-56d2-4fbb-baef-101b930e9124",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
import { IAnalyticsSDK } from "../core/IAnalyticsSDK";
|
||||
import { logger } from "db://assets/Scripts/Main/Common/Logger";
|
||||
|
||||
/**
|
||||
* UmaAnalyticsSDK
|
||||
*
|
||||
* - 负责集成友盟统计(UMeng+)
|
||||
* - 提供初始化、事件上报、开关控制等功能
|
||||
*/
|
||||
export class UmaAnalyticsSDK implements IAnalyticsSDK {
|
||||
private enabled: boolean = false;
|
||||
|
||||
/**
|
||||
* 初始化友盟统计
|
||||
* @param cb 初始化完成后的回调
|
||||
*
|
||||
* - 通常在游戏启动时调用
|
||||
* - 内部调用 window["wx"].uma.init 或其他平台的 UMA 初始化
|
||||
*/
|
||||
init(cb?: Function): void {
|
||||
try {
|
||||
if (typeof window !== "undefined" && window["wx"] && window["wx"].uma) {
|
||||
window["wx"].uma.init({
|
||||
appKey: "YOUR_UMA_APP_KEY", // TODO: 替换成实际 key
|
||||
useOpenid: true,
|
||||
autoGetOpenid: true,
|
||||
debug: false,
|
||||
uploadUserInfo: true,
|
||||
});
|
||||
this.enabled = true;
|
||||
logger.info("UmaAnalyticsSDK 初始化完成 ");
|
||||
} else {
|
||||
this.enabled = false;
|
||||
logger.warn("UmaAnalyticsSDK 初始化失败 (未检测到 wx.uma)");
|
||||
}
|
||||
} catch (e) {
|
||||
this.enabled = false;
|
||||
logger.error("UmaAnalyticsSDK 初始化异常:", e);
|
||||
}
|
||||
|
||||
cb && cb();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否启用 UMA 统计
|
||||
*
|
||||
* @returns true 启用,false 关闭
|
||||
*/
|
||||
isAnalyticsEnabled(): boolean {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* 上报事件
|
||||
* @param eventName 事件名称
|
||||
* @param value 事件参数(可选)
|
||||
*
|
||||
* - 例如:trackEvent("_um.talk.round", { round: 5 })
|
||||
*/
|
||||
trackEvent(eventName: string, value?: any): void {
|
||||
if (!this.enabled) {
|
||||
logger.debug("UmaAnalyticsSDK 未启用,跳过事件上报:", eventName, value);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
window["wx"].uma.trackEvent(eventName, value || {});
|
||||
logger.info("UmaAnalyticsSDK 上报事件:", eventName, value);
|
||||
} catch (e) {
|
||||
logger.error("UmaAnalyticsSDK 上报事件失败:", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 销毁 SDK
|
||||
*
|
||||
* - 用于释放资源或清理缓存
|
||||
* - 通常在游戏退出或切换环境时调用
|
||||
*/
|
||||
destroy(): void {
|
||||
logger.info("UmaAnalyticsSDK 已销毁");
|
||||
this.enabled = false;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "f1136fde-852b-445f-b4e6-750712006155",
|
||||
"uuid": "7ab6fef3-1927-4956-9536-f2cdd7fe2842",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
@@ -1,601 +0,0 @@
|
||||
import { randomRange } from "cc"
|
||||
import GlobalValue from "../Common/GlobalValue"
|
||||
import { I_SDK_UserInfo, I_SDK_UserInfo_Callback, SDKManager } from "./SDKManager"
|
||||
import SubManager from "../../Sub/SubManager"
|
||||
import Utils from "../Common/Utils"
|
||||
import { InnerMsgCode } from "../Config/InnerMsgCode"
|
||||
import HttpUnit from "../Common/HttpUnit"
|
||||
import { logger } from "db://assets/Scripts/Main/Common/Logger";
|
||||
|
||||
//广告ID
|
||||
const AD_AWARD = "1ntrdiqhmdket7v5fe"
|
||||
const AD_SPLASH = "test"
|
||||
const AD_BANNER = "test"
|
||||
const AD_BANNER_INTERVAL = 30
|
||||
const AD_BANNER_HEIGHT = 130
|
||||
|
||||
export class ByteDanceSDK{
|
||||
|
||||
private bd_video:any = null;
|
||||
private bd_splash:any = null;
|
||||
private bd_banner:any = null;
|
||||
private bd_video_callback:Function = null;
|
||||
private bd_video_tag:number = null;
|
||||
|
||||
private ShareSTime: any;
|
||||
private ShareCb: any; //分享回调
|
||||
private shareTxt = ["分享失败", "请分享到一个群", "请分享给一位好友", "分享过于频繁"]
|
||||
|
||||
|
||||
/**侧边栏状态 =0不显示 =1显示前往按钮 =2从侧边栏返回 =3奖励已领取 */
|
||||
private static _SidebarState:number = 0;
|
||||
public static get SidebarState():number{
|
||||
return ByteDanceSDK._SidebarState;
|
||||
}
|
||||
|
||||
|
||||
/**检测侧边栏功能是否可用 */
|
||||
public static CheckSidebarState(cb:Function=null){
|
||||
if (HttpUnit.IsBDSidebarReceive()) {
|
||||
ByteDanceSDK._SidebarState = 3;
|
||||
cb && cb(true);
|
||||
return;
|
||||
}
|
||||
if (ByteDanceSDK._SidebarState > 0){
|
||||
cb && cb(true);
|
||||
return;
|
||||
}
|
||||
window['tt'].checkScene({
|
||||
scene: "sidebar",
|
||||
success: (res) => {
|
||||
logger.log("抖音 检测侧边栏功能->", res)
|
||||
if (res.isExist == true) {
|
||||
if (ByteDanceSDK._SidebarState == 0) {
|
||||
ByteDanceSDK._SidebarState = 1
|
||||
}
|
||||
}
|
||||
cb && cb(res.isExist == true);
|
||||
},
|
||||
fail: (res) => {
|
||||
logger.log("抖音 检测侧边栏功能失败->", res)
|
||||
cb && cb(false);
|
||||
}
|
||||
})
|
||||
}
|
||||
/**前往侧边栏 */
|
||||
public static GotoSidebar(cb:Function = null){
|
||||
logger.log("抖音 正在前往侧边栏...")
|
||||
window["tt"].navigateToScene({
|
||||
scene: "sidebar",
|
||||
success(res) {
|
||||
logger.log("抖音 前往侧边栏 成功")
|
||||
cb && cb(true);
|
||||
},
|
||||
fail(res) {
|
||||
logger.log("抖音 前往侧边栏 失败", res)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//初始化
|
||||
init(cb: Function = null) {
|
||||
logger.log("init 抖音 初始化...")
|
||||
// 保持屏幕常亮
|
||||
window["tt"].setKeepScreenOn({
|
||||
keepScreenOn: true,
|
||||
success(res) {
|
||||
},
|
||||
fail(res) {
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
//小游戏回到前台
|
||||
window['tt'].onShow((res)=>{
|
||||
logger.log("抖音 小游戏回到前台->", res)
|
||||
if (!res) {
|
||||
return;
|
||||
}
|
||||
// logger.log("启动参数:", res.query);
|
||||
// logger.log("来源信息:", res.refererInfo);
|
||||
// logger.log("场景值:", res.scene);
|
||||
// logger.log("启动场景字段:", res.launch_from, ", ", res.location);
|
||||
|
||||
//返回小游戏场景值
|
||||
if (res.query && res.query.ShareCode) {
|
||||
GlobalValue.ShareTocusid = res.query.ShareCode
|
||||
}
|
||||
|
||||
//从侧边栏返回
|
||||
if (res.launch_from == "homepage" && res.location == "sidebar_card") {
|
||||
logger.log("从侧边栏返回, SidebarState=", ByteDanceSDK._SidebarState)
|
||||
if (ByteDanceSDK._SidebarState == 1) {
|
||||
ByteDanceSDK._SidebarState = 2
|
||||
Utils.sendInnerMsg(InnerMsgCode.UI_BD_Sidebar, {})
|
||||
//获取奖励
|
||||
HttpUnit.ins.getBDSidebarReward({}, (data) => {
|
||||
Utils.sendInnerMsg(InnerMsgCode.Data_BDSidebarReward, {})
|
||||
SubManager.ShowConfirm({
|
||||
content: "侧边栏奖励领取成功,相亲次数+1",
|
||||
hideNo: true, //隐藏取消按钮
|
||||
yesCallback: () => {
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
//处理分享事件
|
||||
if (this.ShareCb) {
|
||||
if (this.ShareSTime) {
|
||||
let nT = new Date().getTime();
|
||||
logger.log("分享时间差 计算:",nT, this.ShareSTime);
|
||||
if (nT - this.ShareSTime > 1500) {
|
||||
let cb = this.ShareCb.succ
|
||||
cb && cb()
|
||||
} else {
|
||||
this.tostErr()
|
||||
}
|
||||
}
|
||||
this.ShareCb = null;
|
||||
}
|
||||
});
|
||||
//小游戏被隐藏 记个时间
|
||||
window['tt'].onHide(() => {
|
||||
if (this.ShareCb) {
|
||||
this.ShareSTime = new Date().getTime();
|
||||
logger.log("分享时间差 记录:", this.ShareSTime);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
this.init_video();
|
||||
this.init_splash();
|
||||
this.init_banner();
|
||||
this.qiangzhiUpdata(); //检测更新
|
||||
cb && cb();
|
||||
}
|
||||
|
||||
//分享失败
|
||||
tostErr() {
|
||||
let rint = Math.floor( randomRange(0, this.shareTxt.length - 1) )
|
||||
SubManager.ShowPrompt(this.shareTxt[rint])
|
||||
if (this.ShareCb) {
|
||||
let cb = this.ShareCb.fail
|
||||
cb && cb()
|
||||
}
|
||||
}
|
||||
|
||||
//检查权限
|
||||
checkAutoSetting(autoKey:string, cb:Function = null) {
|
||||
// cb && cb(true);
|
||||
if (autoKey == "userInfo") {
|
||||
autoKey = "scope.userInfo"
|
||||
}
|
||||
window['tt'].authorize({
|
||||
scope: autoKey,
|
||||
success(res:any) {
|
||||
logger.log("抖音 - 检测权限状态 succ:", JSON.stringify(res))
|
||||
if (autoKey == "scope.userInfo" && res.data['scope.userInfo']) {
|
||||
cb && cb(true)
|
||||
} else {
|
||||
cb && cb(false)
|
||||
}
|
||||
},
|
||||
fail(res:any) {
|
||||
logger.log("抖音 - 检测权限状态 fail:",JSON.stringify(res))
|
||||
cb && cb(false)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
//获取用户信息
|
||||
getUserInfo(cb:I_SDK_UserInfo_Callback = null) {
|
||||
// cb && cb({ nickName:"", avatarUrl:"" });
|
||||
//getUserProfile报错未找到
|
||||
window["tt"].getUserInfo({
|
||||
force: false, //当宿主未登录时,是否强制拉起登录框
|
||||
success(res) {
|
||||
logger.log("抖音 - 获取用户信息成功:", res);
|
||||
cb && cb({avatarUrl:res.userInfo.avatarUrl, nickName:res.userInfo.nickName}) //encryptedData
|
||||
},
|
||||
fail(res) {
|
||||
logger.log("抖音 - 获取用户信息失败", res);
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
//region 登录
|
||||
login(cb: Function = null) {
|
||||
// cb && cb({ platform:2, code: null });
|
||||
window["tt"].login({
|
||||
force: false, //未登录时, 是否强制调起登录框
|
||||
success(res) {
|
||||
logger.log(`抖音 - 登录成功 code=${res.code}, anonymousCode=${res.anonymousCode}`);
|
||||
cb && cb({ platform:2, code: res.code });
|
||||
},
|
||||
fail(res) {
|
||||
logger.log(`抖音 - 登录失败`, res);
|
||||
cb && cb({ platform:2, code: null });
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
private init_banner() {
|
||||
if (AD_BANNER as any == "test") {
|
||||
logger.log("抖音 横幅广告id未配置,跳过此类型初始化")
|
||||
return
|
||||
}
|
||||
|
||||
if (!window["tt"] || !window["tt"].createBannerAd) return
|
||||
|
||||
const systemInfo = window["tt"].getSystemInfoSync();
|
||||
//if (systemInfo.appName.toUpperCase() == 'DOUYIN') return
|
||||
//if (systemInfo.appName.toUpperCase() == 'TOUTIAO' && systemInfo.platform == "ios") return
|
||||
|
||||
if (systemInfo.appName.toUpperCase() == 'DOUYIN' || systemInfo.platform == "ios") return
|
||||
|
||||
const { windowWidth, windowHeight } = window["tt"].getSystemInfoSync();
|
||||
var targetBannerAdWidth = 128+ 100
|
||||
var targetBannerAdHeight = AD_BANNER_HEIGHT
|
||||
// 创建一个居于屏幕底部正中的广告
|
||||
this.bd_banner = window["tt"].createBannerAd({
|
||||
adUnitId: AD_BANNER,
|
||||
adIntervals: AD_BANNER_INTERVAL,
|
||||
style: {
|
||||
width: targetBannerAdWidth,
|
||||
left:(windowWidth - targetBannerAdWidth) / 2,
|
||||
top: windowHeight - targetBannerAdHeight
|
||||
},
|
||||
});
|
||||
|
||||
// 尺寸调整时会触发回调
|
||||
// 注意:如果在回调里再次调整尺寸,要确保不要触发死循环!!!
|
||||
this.bd_banner.onResize(size => {
|
||||
this.bd_banner.style.left = (windowWidth - size.width) / 2;
|
||||
this.bd_banner.style.top = windowHeight - size.height;
|
||||
});
|
||||
|
||||
// bd_banner.onLoad(() => {
|
||||
// bd_banner
|
||||
// .show()
|
||||
// .then(() => {
|
||||
// logger.log("init_banner 广告显示成功");
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// logger.log("init_banner 广告组件出现问题", err);
|
||||
// });
|
||||
// })
|
||||
}
|
||||
|
||||
private init_splash() {
|
||||
|
||||
this.preload_splash()
|
||||
}
|
||||
|
||||
private preload_splash() {
|
||||
if (AD_SPLASH as any == "test") {
|
||||
logger.log("抖音 插屏广告id未配置,跳过此类型初始化")
|
||||
return
|
||||
}
|
||||
|
||||
if (!window["tt"] || !window["tt"].createInterstitialAd) return
|
||||
|
||||
if (this.bd_splash) {
|
||||
if (this.bd_splash['custom_show_stautus']) {
|
||||
this.bd_splash.destroy()
|
||||
this.bd_splash = null
|
||||
} else {
|
||||
if (!this.bd_splash['custom_load_stautus']) {
|
||||
this.bd_splash
|
||||
.load()
|
||||
.catch(err => {
|
||||
logger.log("preload_splash err:",err);
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.bd_splash) return
|
||||
|
||||
// 创建插屏广告实例,会自动进行一次load
|
||||
this.bd_splash = window["tt"].createInterstitialAd({
|
||||
adUnitId: AD_SPLASH
|
||||
})
|
||||
this.bd_splash.onLoad(function(){
|
||||
this.bd_splash['custom_load_stautus'] = true
|
||||
})
|
||||
this.bd_splash.onClose(function(){
|
||||
this.bd_splash.destroy()
|
||||
this.bd_splash = null
|
||||
|
||||
this.preload_splash()
|
||||
})
|
||||
this.bd_splash.onError(function(err){
|
||||
logger.log("bd_splash err:",err)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
private init_video() {
|
||||
if (AD_AWARD as any == "test") {
|
||||
logger.log("抖音 激励广告id未配置,跳过此类型初始化")
|
||||
return
|
||||
}
|
||||
|
||||
if (!window["tt"] || !window["tt"].createRewardedVideoAd) return
|
||||
|
||||
this.bd_video = window["tt"].createRewardedVideoAd({
|
||||
adUnitId: AD_AWARD,
|
||||
});
|
||||
|
||||
this.bd_video.onClose(res => {
|
||||
if (res.isEnded) {
|
||||
if (this.bd_video_callback) {
|
||||
this.bd_video_callback(this.bd_video_tag);
|
||||
}
|
||||
}
|
||||
SDKManager.video_ad_back();
|
||||
});
|
||||
|
||||
this.bd_video.onError((err) => {
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
//显示视频广告
|
||||
show_video(callback:Function, tag:number) {
|
||||
if (AD_AWARD as any == 'test') {
|
||||
logger.log('未接入广告ID,视频广告请求直接返回');
|
||||
callback && callback();
|
||||
SDKManager.video_ad_back();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.bd_video) return
|
||||
|
||||
this.bd_video_callback = callback;
|
||||
this.bd_video_tag = tag
|
||||
|
||||
this.bd_video
|
||||
.load()
|
||||
.then(() => {
|
||||
this.bd_video.show()
|
||||
})
|
||||
.catch(err => {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
//显示插屏
|
||||
show_splash() {
|
||||
|
||||
//已加载 未展示
|
||||
if (this.bd_splash && this.bd_splash['custom_load_stautus'] && !this.bd_splash['custom_show_stautus']) {
|
||||
this.bd_splash.show().then(() => {
|
||||
this.bd_splash['custom_show_stautus'] = true
|
||||
logger.log("插屏广告展示成功");
|
||||
})
|
||||
} else {
|
||||
logger.log("插屏广告展示失败");
|
||||
this.preload_splash()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//显示Banner
|
||||
show_banner() {
|
||||
if (this.bd_banner) {
|
||||
this.bd_banner.show(); //banner 默认隐藏(hide) 要打开
|
||||
}
|
||||
}
|
||||
|
||||
//隐藏Banner
|
||||
hide_banner() {
|
||||
if (this.bd_banner) {
|
||||
this.bd_banner.hide(); //banner 默认隐藏(hide) 要打开
|
||||
}
|
||||
}
|
||||
|
||||
//移除
|
||||
clear_banner() {
|
||||
if (this.bd_banner) {
|
||||
this.bd_banner.destroy(); //banner 默认隐藏(hide) 要打开
|
||||
this.bd_banner = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//分享信息
|
||||
shareInfo() {
|
||||
return {
|
||||
title: "告白契约", //Resource.getText(_shareInfo.invite_des),
|
||||
query: "ShareCode=" + "user_default", //ModelPlayer.I.getPlayerId(),
|
||||
}
|
||||
}
|
||||
//主动拉起分享
|
||||
show_share(rewardCB?:Function) {
|
||||
// rewardCB && rewardCB()
|
||||
logger.log("主动拉起分享");
|
||||
let info:any = this.shareInfo();
|
||||
info.succ = rewardCB;
|
||||
|
||||
info.success = (res) => {
|
||||
logger.log("抖音 主动拉起分享成功", res);
|
||||
}
|
||||
info.fail = (err) => {
|
||||
logger.log("抖音 主动拉起分享失败", err);
|
||||
}
|
||||
// info.complete = (res) => {
|
||||
// logger.log("抖音 主动拉起分享完成", res);
|
||||
// }
|
||||
|
||||
this.ShareCb = info;
|
||||
window['tt'].shareAppMessage(info);
|
||||
}
|
||||
|
||||
//获取设备分辨率
|
||||
getWindowSize() {
|
||||
return {width:screen.width, height: screen.height};
|
||||
}
|
||||
|
||||
//显示游戏圈
|
||||
show_gameClub(leftRatio, topRatio, widthRatio, heightRatio) {
|
||||
|
||||
}
|
||||
//隐藏游戏圈
|
||||
hide_gameClub() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
//检查是否支持base64音频播放
|
||||
checkSupportBase64Audio() {
|
||||
return true;
|
||||
}
|
||||
//播放base64音频
|
||||
private _innerAudioContext: any = null;
|
||||
private _iacIdx = 0 //音频播放索引
|
||||
playBase64Audio(base64, loop) {
|
||||
if (!this.checkSupportBase64Audio()) {
|
||||
return;
|
||||
}
|
||||
|
||||
let substring = base64;
|
||||
let qianzhui = "data:audio/x-wav;base64,"
|
||||
if(base64.startsWith(qianzhui)) {
|
||||
substring = base64.substring(qianzhui.length, base64.length)
|
||||
}
|
||||
|
||||
let self = this;
|
||||
const fs = window['tt'].getFileSystemManager();
|
||||
//1.删除上一个音频
|
||||
const lastPath = window['tt'].env.USER_DATA_PATH + `/ordernew${self._iacIdx}.mp3`
|
||||
logger.log("抖音 正在删除上一个音频 ->", lastPath);
|
||||
fs.removeSavedFile({
|
||||
filePath: lastPath,
|
||||
success(res) {
|
||||
logger.log("抖音 删除上一个音频成功", res);
|
||||
},
|
||||
fail(err) {
|
||||
logger.log("抖音 删除上一个音频失败", err);
|
||||
},
|
||||
complete(res) {
|
||||
logger.log("抖音 删除上一个音频完成", res);
|
||||
|
||||
//2.保存当前音频
|
||||
//这里需要每次保存时换一下名字的原因是:innerAudioContext设置路径时如果路径相同,会认为还是同一个音频,不会重新加载,所以需要每次保存时换一下名字
|
||||
self._iacIdx++;
|
||||
const audioPath = window['tt'].env.USER_DATA_PATH + `/ordernew${self._iacIdx}.mp3`
|
||||
logger.log("抖音 正在保存本次音频 ->", audioPath);
|
||||
fs.writeFile({
|
||||
filePath: audioPath,
|
||||
data: substring,
|
||||
encoding: 'base64',
|
||||
success(res) {
|
||||
if (self._innerAudioContext == null){
|
||||
self._innerAudioContext = window['tt'].createInnerAudioContext();
|
||||
// 添加播放结束的回调
|
||||
self._innerAudioContext.onEnded(() => {
|
||||
logger.log("抖音 AI语音播放结束")
|
||||
self._innerAudioContext.stop(); // 使用 stop 方法停止音频并重置播放状态
|
||||
self._innerAudioContext.destroy(); // 销毁音频实例
|
||||
self._innerAudioContext = null;
|
||||
});
|
||||
}
|
||||
logger.log("抖音 播放base64音频", audioPath)
|
||||
self._innerAudioContext.src = audioPath;
|
||||
self._innerAudioContext.play(); // 开始播放音频
|
||||
},
|
||||
fail(err) {
|
||||
logger.log("抖音 保存本次音频失败", err);
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//region版本更新检测
|
||||
//微信开发者工具上可以通过「编译模式」下的「下次编译模拟更新」开关来调试
|
||||
qiangzhiUpdata() {
|
||||
if (window['tt'].getUpdateManager == null) {
|
||||
logger.log("抖音 没有更新管理器", window['tt'].getUpdateManager)
|
||||
return;
|
||||
}
|
||||
|
||||
const updateManager = window['tt'].getUpdateManager();
|
||||
|
||||
//监听向微信后台请求检查更新结果事件。微信在小程序每次启动(包括热启动)时自动检查更新,不需由开发者主动触发。
|
||||
updateManager.onCheckForUpdate((res) => {
|
||||
// 请求完新版本信息的回调
|
||||
logger.log("抖音 检查是否有新版本:", res.hasUpdate)
|
||||
});
|
||||
|
||||
//监听小程序有版本更新事件。客户端主动触发下载(无需开发者触发),下载成功后回调
|
||||
updateManager.onUpdateReady(async () => {
|
||||
window['tt'].showModal({
|
||||
title: '更新提示',
|
||||
content: '新版本已经准备好,是否重启应用?',
|
||||
success: function (res) {
|
||||
if (res.confirm) {
|
||||
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
||||
updateManager.applyUpdate()
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
//监听小程序更新失败事件。小程序有新版本,客户端主动触发下载(无需开发者触发),下载失败(可能是网络原因等)时回调
|
||||
updateManager.onUpdateFailed(function (err) {
|
||||
logger.log("抖音 新版本下载失败", err)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//客服功能是否支持
|
||||
kefuSupport() {
|
||||
logger.log("抖音 不支持联系客服")
|
||||
return false;
|
||||
}
|
||||
//进入联系客服
|
||||
openKefu() {
|
||||
logger.log("抖音 进入联系客服")
|
||||
}
|
||||
|
||||
|
||||
//播放背景视频
|
||||
playBgAudio(remoteUrl:string, loop:boolean = false, cbStart?: Function, cbEnded?: Function) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
//region 复制到剪贴板
|
||||
/**复制文本到剪贴板 */
|
||||
copyToClipboard(text: string, cb?: Function) {
|
||||
logger.log("抖音 复制到剪贴板:", text);
|
||||
window['tt'].setClipboardData({
|
||||
data: text,
|
||||
success: () => {
|
||||
logger.log("抖音 复制成功");
|
||||
cb && cb(true);
|
||||
},
|
||||
fail: (err) => {
|
||||
logger.log("抖音 复制失败:", err);
|
||||
cb && cb(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//region 友盟+
|
||||
umaInit() {
|
||||
}
|
||||
//友盟统计是否开启
|
||||
umaSwt() {
|
||||
return false;
|
||||
}
|
||||
//友盟事件统计
|
||||
umaEvent(eventName: string, value: any = {}) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "48902f92-f887-41d1-a657-a1f5db62bfff",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* 定义广告能力接口,所有广告 SDK 必须实现
|
||||
*
|
||||
*/
|
||||
|
||||
import { ISDK } from "./ISDK";
|
||||
|
||||
export interface IAdSDK extends ISDK {
|
||||
/**
|
||||
* 展示激励视频广告
|
||||
* @param cb 回调,用户看完广告后触发
|
||||
*
|
||||
* - 成功播放到结尾时触发回调 → 发放奖励
|
||||
* - 中途关闭时一般不触发
|
||||
*/
|
||||
showRewardVideo(cb: (ok: boolean) => void): void;
|
||||
|
||||
/**
|
||||
* 展示插屏广告(splash/interstitial)
|
||||
*
|
||||
* - 一般在关卡切换/场景切换时调用
|
||||
*/
|
||||
showInterstitial(): void;
|
||||
|
||||
/**
|
||||
* 展示 Banner 广告
|
||||
*
|
||||
* - 通常固定在屏幕底部或顶部
|
||||
*/
|
||||
showBanner(): void;
|
||||
|
||||
/**
|
||||
* 隐藏 Banner 广告
|
||||
*/
|
||||
hideBanner(): void;
|
||||
|
||||
/**
|
||||
* 主动拉起分享
|
||||
* @param cb 分享成功后的回调(某些平台支持)
|
||||
*
|
||||
* - 分享到好友/群聊
|
||||
* - 不同平台回调机制不同,有的平台不保证能检测到分享成功
|
||||
*/
|
||||
showShare(cb?: Function): void;
|
||||
}
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "6c186fa7-4295-4a83-a698-874a29a67c0d",
|
||||
"uuid": "12cfc56c-d0fa-4010-88ae-ab5cdf69494a",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* 分析统计 SDK 接口
|
||||
*
|
||||
* - 分析/统计 SDK 的通用接口
|
||||
* - 用于事件上报(例如:友盟、Google Analytics、Mixpanel)
|
||||
* - 所有分析 SDK 都应该实现这些方法
|
||||
*/
|
||||
|
||||
import { ISDK } from "./ISDK";
|
||||
|
||||
export interface IAnalyticsSDK extends ISDK {
|
||||
/**
|
||||
* 判断统计功能是否可用
|
||||
* @returns {boolean} true 表示启用,false 表示禁用
|
||||
*
|
||||
* - 不同环境下可能有不同表现(如 Test 环境默认关闭)
|
||||
* - SDK 初始化失败时也可能返回 false
|
||||
*/
|
||||
isAnalyticsEnabled(): boolean;
|
||||
|
||||
/**
|
||||
* 上报事件
|
||||
* @param eventName 事件名称
|
||||
* @param value 事件参数(可选)
|
||||
*
|
||||
* - 常用于埋点上报,例如:关卡完成、按钮点击
|
||||
* - 不同 SDK 内部实现方式可能不同(友盟、Firebase、GA)
|
||||
*/
|
||||
trackEvent(eventName: string, value?: any): void;
|
||||
}
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "cccc5fab-681f-424a-8410-1d418257aaf9",
|
||||
"uuid": "5273f505-c9c6-46bf-b0d9-af450515aafa",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* 定义平台基础能力接口(登录、获取用户信息、权限检测)
|
||||
*
|
||||
*/
|
||||
|
||||
import { ISDK } from "./ISDK";
|
||||
|
||||
export interface IPlatformSDK extends ISDK {
|
||||
/**
|
||||
* 登录
|
||||
* @param cb 登录完成后的回调,返回平台相关的登录结果(如 code)
|
||||
*
|
||||
* - 微信/抖音:返回临时 code,需要交给服务器换取 openid/session_key
|
||||
* - Web 平台:可能返回一个模拟的 code
|
||||
*/
|
||||
login(cb?: Function): void;
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
* @param cb 回调,返回 { nickName, avatarUrl }
|
||||
*
|
||||
* - 有的平台需要用户授权才能拿到头像和昵称
|
||||
* - 失败时可能触发授权按钮逻辑
|
||||
*/
|
||||
getUserInfo(cb: (info: { nickName: string; avatarUrl: string }) => void): void;
|
||||
|
||||
/**
|
||||
* 检查平台权限
|
||||
*
|
||||
* 不同平台(微信 / 抖音 / 快手 / Web)对于用户隐私或接口调用,通常需要先申请权限。
|
||||
* 例如:微信的 scope.userInfo(用户信息)、scope.record(录音)、scope.writePhotosAlbum(保存相册)。
|
||||
*
|
||||
* @param scope string
|
||||
* 权限范围标识,不同平台有不同的 key,比如:
|
||||
* - "scope.userInfo" 用户信息
|
||||
* - "scope.record" 录音
|
||||
* - "scope.writePhotosAlbum" 保存到相册
|
||||
*
|
||||
* @param cb (granted: boolean) => void
|
||||
* 回调函数,返回布尔值:
|
||||
* - true:表示用户已经授权该权限,可以直接使用相关 API
|
||||
* - false:表示未授权,需要提示用户去设置或引导授权
|
||||
*
|
||||
*/
|
||||
checkPermission(scope: string, cb: (granted: boolean) => void): void;
|
||||
|
||||
/**
|
||||
* 复制文本到剪贴板
|
||||
* @param text 要复制的文本
|
||||
* @param cb 回调,true 表示复制成功,false 表示失败
|
||||
*
|
||||
* - Web 使用 navigator.clipboard
|
||||
* - 微信使用 wx.setClipboardData
|
||||
*/
|
||||
copyToClipboard(text: string, cb?: Function): void;
|
||||
|
||||
/**
|
||||
* 客服功能是否可用
|
||||
* @returns boolean,true 表示支持
|
||||
*
|
||||
* - 微信:wx.openCustomerServiceConversation
|
||||
* - Web / 其他平台:通常返回 false
|
||||
*/
|
||||
kefuSupport(): boolean;
|
||||
|
||||
/**
|
||||
* 打开客服会话
|
||||
*
|
||||
* - 仅在支持客服的平台生效
|
||||
*/
|
||||
openKefu(): void;
|
||||
|
||||
/**
|
||||
* 获取设备分辨率
|
||||
* @returns { width, height }
|
||||
*
|
||||
* - Web:window.innerWidth / window.innerHeight
|
||||
* - 小游戏:wx.getWindowInfo()
|
||||
*/
|
||||
getWindowSize(): { width: number, height: number };
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "99996676-dd93-488c-8d43-c4e9f9f0527a",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* 定义 SDK 的基础生命周期接口
|
||||
*
|
||||
*/
|
||||
|
||||
export interface ISDK {
|
||||
/**
|
||||
* 初始化 SDK
|
||||
* @param cb 初始化完成后的回调
|
||||
*
|
||||
* - 通常在游戏启动时调用
|
||||
* - 可执行一些准备动作(保持常亮、获取启动参数、初始化广告等)
|
||||
*/
|
||||
init(cb?: Function): void;
|
||||
|
||||
/**
|
||||
* 销毁 SDK(可选实现)
|
||||
*
|
||||
* - 通常在游戏退出或切换场景时调用
|
||||
* - 用于释放资源、注销事件监听、停止定时器等
|
||||
* - 如果 SDK 不需要额外清理,可以不实现
|
||||
*/
|
||||
destroy?(): void;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "6e61a536-2663-4ea0-a97f-0bf2b6450c51",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* 定义钱包 SDK 的统一接口,用于封装不同平台的钱包接入逻辑(例如 Luffa、MetaMask、Phantom)。
|
||||
*
|
||||
*/
|
||||
|
||||
import { ISDK } from "./ISDK";
|
||||
|
||||
export interface IWalletSDK extends ISDK {
|
||||
/**
|
||||
* 连接钱包
|
||||
*
|
||||
* 触发钱包连接流程(如唤起 Luffa 钱包授权、MetaMask 插件弹窗)。
|
||||
* 成功后返回钱包地址和可选的公钥。
|
||||
*
|
||||
* @param cb 回调函数
|
||||
* - address: 钱包地址(字符串)
|
||||
* - publicKey?: 钱包公钥(部分钱包可能返回,用于后续签名验证)
|
||||
*/
|
||||
connect(cb: (address: string, publicKey?: string) => void): void;
|
||||
|
||||
/**
|
||||
* 断开钱包连接
|
||||
*
|
||||
* 清理当前钱包的会话信息(如地址、公钥、缓存的 session)。
|
||||
* 调用后 getWalletAddress() 应返回 null。
|
||||
*/
|
||||
disconnect(): void;
|
||||
|
||||
/**
|
||||
* 获取当前钱包地址
|
||||
*
|
||||
* 如果用户已连接钱包,则返回钱包地址。
|
||||
* 如果尚未连接,则返回 null。
|
||||
*/
|
||||
getWalletAddress(): string | null;
|
||||
|
||||
//
|
||||
signMessage(message: string, nonce: number, options?: any): Promise<any>;
|
||||
|
||||
//
|
||||
buildTransaction(payload: any): Promise<any>;
|
||||
|
||||
//
|
||||
signTransaction(rawData: any): Promise<any>;
|
||||
|
||||
//
|
||||
sendTransaction(signedData: any): Promise<{ hash: string }>;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "d691d1e1-187a-4010-862a-86e62444eae4",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -1,792 +0,0 @@
|
||||
import { isValid, randomRange, view } from "cc";
|
||||
import GlobalValue, { VideoRoleType } from "../Common/GlobalValue";
|
||||
import SubManager from "../../Sub/SubManager";
|
||||
import { I_SDK_UserInfo_Callback, SDKManager } from "./SDKManager";
|
||||
import Utils from "../Common/Utils";
|
||||
import { InnerMsgCode } from "../Config/InnerMsgCode";
|
||||
import { BgVideo } from "./BgVideo";
|
||||
import { SceneBgVideoLayer } from "../../Sub/UI/SceneBgVideoLayer";
|
||||
import { logger } from "db://assets/Scripts/Main/Common/Logger";
|
||||
|
||||
//广告ID
|
||||
const wx_banner_ad_unit_id = 'test'
|
||||
const wx_splash_ad_unit_id = 'test'
|
||||
const wx_video_ad_unit_id = 'test'
|
||||
|
||||
export class KSSDK{
|
||||
|
||||
static g_InGameScene = null; //游戏场景值
|
||||
|
||||
private wx_video:any = null;
|
||||
private wx_splash:any = null;
|
||||
private wx_banner:any = null;
|
||||
private wx_video_callback:Function = null;
|
||||
private wx_video_tag:number = null;
|
||||
private wx_gameClub:any = null; //游戏圈按钮
|
||||
|
||||
private ShareSTime: any;
|
||||
private ShareCb: any; //分享回调
|
||||
private shareTxt = ["分享失败", "请分享到一个群", "请分享给一位好友", "分享过于频繁"]
|
||||
|
||||
//初始化
|
||||
init(cb: Function = null) {
|
||||
// 保持屏幕常亮
|
||||
// window['ks'].setKeepScreenOn({ keepScreenOn: true });
|
||||
|
||||
//获取小游戏冷启动时的参数 热启动参数通过 ks.onShow 接口获取。
|
||||
let launchOption = window['ks'].getLaunchOptionsSync();
|
||||
KSSDK.g_InGameScene = launchOption.from;
|
||||
logger.log('init 快手 - 进入游戏的场景值', launchOption);
|
||||
|
||||
// //显示分享按钮
|
||||
// window['ks'].showShareMenu({
|
||||
// withShareTicket: true,
|
||||
// menus: ["shareAppMessage", "shareTimeline"],
|
||||
// });
|
||||
// window['ks'].onShareAppMessage(() => {
|
||||
// return this.shareInfo();
|
||||
// });
|
||||
// window['ks'].onShareTimeline(() => {
|
||||
// return this.shareInfo();
|
||||
// })
|
||||
|
||||
//小游戏回到前台
|
||||
window['ks'].onShow(this.onWxShow.bind(this));
|
||||
//小游戏被隐藏 记个时间
|
||||
window['ks'].onHide(() => {
|
||||
logger.log("快手 onHide回调:")
|
||||
if (this.ShareCb) {
|
||||
this.ShareSTime = new Date().getTime();
|
||||
logger.log("分享时间差 记录:", this.ShareSTime);
|
||||
}
|
||||
});
|
||||
|
||||
this.init_video(); //初始化视频广告
|
||||
this.init_splash(); //初始化插屏广告
|
||||
this.init_banner(); //初始化Banner广告 弹窗广告
|
||||
this.qiangzhiUpdata(); //强制更新
|
||||
cb && cb();
|
||||
}
|
||||
|
||||
|
||||
//小游戏回到前台
|
||||
onWxShow(data: any) {
|
||||
logger.log("快手 onShow回调:", data)
|
||||
if (data) {
|
||||
//启动小游戏时传入的参数 object
|
||||
if (data.query) {
|
||||
GlobalValue.ShareTocusid = data.query.ShareCode
|
||||
}
|
||||
//游戏启动场景 string
|
||||
if (data.from) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (this.ShareCb) {
|
||||
if (this.ShareSTime) {
|
||||
let nT = new Date().getTime();
|
||||
logger.log("分享时间差 计算:",nT, this.ShareSTime, nT - this.ShareSTime);
|
||||
if (nT - this.ShareSTime > 1) { //快手的onHide有问题,离onShow很近
|
||||
let cb = this.ShareCb.succ
|
||||
cb && cb()
|
||||
} else {
|
||||
this.tostErr()
|
||||
}
|
||||
}
|
||||
this.ShareCb = null;
|
||||
}
|
||||
}
|
||||
//分享失败
|
||||
tostErr() {
|
||||
let rint = Math.floor( randomRange(0, this.shareTxt.length - 1) )
|
||||
SubManager.ShowPrompt(this.shareTxt[rint])
|
||||
if (this.ShareCb) {
|
||||
let cb = this.ShareCb.fail
|
||||
cb && cb()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**获取用户授权状态
|
||||
* @param autoKey string 授权类型 userInfo=用户信息,对应接口wx.getUserInfo
|
||||
*/
|
||||
checkAutoSetting(autoKey:string, cb:Function = null) {
|
||||
window['ks'].getSetting({
|
||||
success(res:any) {
|
||||
logger.log("快手 - 检测权限状态 succ:", res)
|
||||
if (autoKey == "userInfo" && res.authSetting['scope.userInfo']) {
|
||||
cb && cb(true)
|
||||
} else {
|
||||
cb && cb(false)
|
||||
}
|
||||
},
|
||||
fail(res:any) {
|
||||
logger.log("快手 - 检测权限状态 fail:", res)
|
||||
cb && cb(false)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取个人信息
|
||||
*/
|
||||
getUserInfo(cb:I_SDK_UserInfo_Callback = null) {
|
||||
var self = this;
|
||||
window['ks'].getSetting({
|
||||
success(res:any) {
|
||||
logger.log("快手 - 获取授权信息成功:", res);
|
||||
let isScope = res.authSetting['scope.userInfo']
|
||||
if (isScope) {
|
||||
window['ks'].getUserInfo({
|
||||
success: (res2) => {
|
||||
logger.log("快手 - 获取用户信息成功:", res2);
|
||||
cb && cb({avatarUrl:res2.userInfo.avatarUrl, nickName:res2.userInfo.nickName})
|
||||
},
|
||||
fail: (error) => {
|
||||
logger.log("快手 - 获取用户信息失败:", error);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
//向用户发起授权请求
|
||||
window['ks'].authorize({
|
||||
scope: 'scope.userInfo',
|
||||
success: (res) => {
|
||||
logger.log("快手 - 发起授权请求成功:", res);
|
||||
self.getUserInfo(cb)
|
||||
},
|
||||
fail: (error) => {
|
||||
logger.log("快手 - 发起授权请求失败: ", error);
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
fail: (error) => {
|
||||
logger.log("快手 - 获取授权信息失败: ", error);
|
||||
// cb && cb({avatarUrl:"", nickName:""})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//region 快手登录
|
||||
login(cb: Function = null) {
|
||||
window['ks'].login({
|
||||
success: (res) => {
|
||||
logger.log('快手 - 登录成功', res.code);
|
||||
cb && cb({ platform:3, code: res.code });
|
||||
},
|
||||
fail(res: any) {
|
||||
logger.log(`快手 login 调用失败`, res);
|
||||
cb && cb({ platform:3, code: null });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
//初始化视频广告
|
||||
private init_video() {
|
||||
if (wx_video_ad_unit_id as any == "test") {
|
||||
logger.log("快手 激励广告id未配置,跳过此类型初始化")
|
||||
return
|
||||
}
|
||||
|
||||
this.wx_video = window['ks'].createRewardedVideoAd({
|
||||
adUnitId: wx_video_ad_unit_id
|
||||
});
|
||||
this.wx_video.onError((err) => {
|
||||
logger.log('onError event emit', err);
|
||||
});
|
||||
this.wx_video.onClose(res => {
|
||||
logger.log('onClose event emit',res);
|
||||
// 用户点击了【关闭广告】按钮
|
||||
// 小于 2.1.0 的基础库版本,res 是一个 undefined
|
||||
if ((res && res.isEnded) || res === undefined) {
|
||||
// 正常播放结束,可以下发游戏奖励
|
||||
if (this.wx_video_callback) {
|
||||
this.wx_video_callback(this.wx_video_tag);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// 播放中途退出,不下发游戏奖励
|
||||
//wx_video_callback(-1);
|
||||
}
|
||||
SDKManager.video_ad_back();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
//初始化插屏广告
|
||||
private init_splash() {
|
||||
if (wx_splash_ad_unit_id as any == "test") {
|
||||
logger.log("快手 插屏广告id未配置,跳过此类型初始化")
|
||||
return
|
||||
}
|
||||
|
||||
// 创建插屏广告实例,提前初始化
|
||||
if (window['ks'].createInterstitialAd){
|
||||
this.wx_splash = window['ks'].createInterstitialAd({
|
||||
adUnitId: wx_splash_ad_unit_id
|
||||
});
|
||||
this.wx_splash.onError((err) => {
|
||||
logger.log('splash onError event emit', err);
|
||||
});
|
||||
this.wx_splash.onClose(res => {
|
||||
logger.log('splash onClose event emit', res);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//初始化Banner
|
||||
private init_banner() {
|
||||
if (wx_banner_ad_unit_id as any == "test") {
|
||||
logger.log("快手 横幅广告id未配置,跳过此类型初始化")
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//显示视频广告
|
||||
show_video(callback:Function, tag:number) {
|
||||
if (wx_video_ad_unit_id == 'test') {
|
||||
logger.log('未接入广告ID,视频广告请求直接返回');
|
||||
callback && callback();
|
||||
SDKManager.video_ad_back();
|
||||
return;
|
||||
}
|
||||
if (this.wx_video) {
|
||||
this.wx_video_callback = callback;
|
||||
this.wx_video_tag = tag;
|
||||
let p = this.wx_video.show()
|
||||
p.then(function(result){
|
||||
// 激励视频展示成功
|
||||
logger.log(`快手 show rewarded video ad success, result is ${result}`)
|
||||
}).catch(function(error){
|
||||
// 激励视频展示失败
|
||||
logger.log(`快手 show rewarded video ad failed, error is ${error}`)
|
||||
})
|
||||
|
||||
// this.wx_video.load()
|
||||
// .then(() => {
|
||||
// this.wx_video.show()
|
||||
// .catch(err => {
|
||||
// this.wx_video.load()
|
||||
// .then(() => this.wx_video.show())
|
||||
// })
|
||||
// })
|
||||
}
|
||||
}
|
||||
|
||||
//显示插屏
|
||||
show_splash() {
|
||||
|
||||
if (this.wx_splash) {
|
||||
let p = this.wx_splash.show()
|
||||
p.then(function(result){
|
||||
// 插屏广告展示成功
|
||||
logger.log(`快手 show interstitial ad success, result is ${result}`)
|
||||
}).catch(function(error){
|
||||
// 插屏广告展示失败
|
||||
logger.log(`快手 show interstitial ad failed, error is ${error}`)
|
||||
if (error.code === -10005) {
|
||||
// 表明当前app版本不支持插屏广告,可以提醒用户升级app版本
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//显示Banner
|
||||
show_banner() {
|
||||
if (this.wx_banner) {
|
||||
this.wx_banner.show(); //banner 默认隐藏(hide) 要打开
|
||||
}
|
||||
}
|
||||
|
||||
//隐藏Banner
|
||||
hide_banner() {
|
||||
if (this.wx_banner) {
|
||||
this.wx_banner.hide(); //banner 默认隐藏(hide) 要打开
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//分享信息
|
||||
shareInfo() {
|
||||
return {
|
||||
templateId: undefined, //分享模版id,不传走默认分享文案
|
||||
//查询字符串,从这条转发消息进入后,可通过 ks.getLaunchOptionsSync() 或 ks.onShow() 获取启动参数中的 query。必须是 key1=val1&key2=val2 的格式。
|
||||
query: "ShareCode=" + "user_default", //ModelPlayer.I.getPlayerId(),
|
||||
}
|
||||
}
|
||||
//主动拉起分享
|
||||
show_share(rewardCB?:Function) {
|
||||
logger.log("主动拉起分享");
|
||||
let info:any = this.shareInfo();
|
||||
info.succ = rewardCB;
|
||||
info.success = null;
|
||||
info.fail = null;
|
||||
this.ShareCb = info;
|
||||
window['ks'].shareAppMessage(info);
|
||||
}
|
||||
|
||||
//获取设备分辨率
|
||||
getWindowSize() {
|
||||
let windowinfo = window['ks'].getSystemInfoSync();
|
||||
return {width:windowinfo.screenWidth, height: windowinfo.screenHeight};
|
||||
}
|
||||
|
||||
//显示游戏圈
|
||||
show_gameClub(leftRatio, topRatio, widthRatio, heightRatio) {
|
||||
if (true) {
|
||||
logger.log("显示游戏圈,快手暂不支持");
|
||||
return
|
||||
}
|
||||
}
|
||||
//隐藏游戏圈
|
||||
hide_gameClub() {
|
||||
logger.log("隐藏游戏圈");
|
||||
if (this.wx_gameClub) {
|
||||
this.wx_gameClub.hide();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//检查是否支持base64音频播放
|
||||
checkSupportBase64Audio() {
|
||||
return true;
|
||||
}
|
||||
//播放base64音频
|
||||
private _innerAudioContext: any = null;
|
||||
private _iacIdx = 0 //音频播放索引
|
||||
playBase64Audio(base64, loop) {
|
||||
if (!this.checkSupportBase64Audio()) {
|
||||
logger.log("当前平台不支持base64音频播放");
|
||||
return;
|
||||
}
|
||||
|
||||
let substring = base64;
|
||||
let qianzhui = "data:audio/x-wav;base64,"
|
||||
if(base64.startsWith(qianzhui)) {
|
||||
substring = base64.substring(qianzhui.length, base64.length)
|
||||
}
|
||||
|
||||
let self = this;
|
||||
const fs = window['ks'].getFileSystemManager();
|
||||
//1.删除上一个音频
|
||||
const lastPath = window['ks'].env.USER_DATA_PATH + `/ordernew${self._iacIdx}.mp3`
|
||||
logger.log("快手 正在删除上一个音频 ->", lastPath);
|
||||
fs.removeSavedFile({
|
||||
filePath: lastPath,
|
||||
success(res) {
|
||||
logger.log("快手 删除上一个音频成功", res);
|
||||
},
|
||||
fail(err) {
|
||||
logger.log("快手 删除上一个音频失败", err);
|
||||
},
|
||||
complete(res) {
|
||||
logger.log("快手 删除上一个音频完成", res);
|
||||
|
||||
//2.保存当前音频
|
||||
//这里需要每次保存时换一下名字的原因是:innerAudioContext设置路径时如果路径相同,会认为还是同一个音频,不会重新加载,所以需要每次保存时换一下名字
|
||||
self._iacIdx++;
|
||||
const audioPath = window['ks'].env.USER_DATA_PATH + `/ordernew${self._iacIdx}.mp3`
|
||||
logger.log("快手 正在保存本次音频 ->", audioPath);
|
||||
fs.writeFile({
|
||||
filePath: audioPath,
|
||||
data: substring,
|
||||
encoding: 'base64',
|
||||
success(res) {
|
||||
if (self._innerAudioContext == null){
|
||||
self._innerAudioContext = window['ks'].createInnerAudioContext();
|
||||
// 添加播放结束的回调
|
||||
self._innerAudioContext.onEnded(() => {
|
||||
logger.log("快手 AI语音播放结束")
|
||||
self._innerAudioContext.stop(); // 使用 stop 方法停止音频并重置播放状态
|
||||
self._innerAudioContext.destroy(); // 销毁音频实例
|
||||
self._innerAudioContext = null;
|
||||
});
|
||||
}
|
||||
logger.log("快手 播放base64音频", audioPath)
|
||||
self._innerAudioContext.src = audioPath;
|
||||
self._innerAudioContext.play(); // 开始播放音频
|
||||
},
|
||||
fail(err) {
|
||||
logger.log("快手 保存本次音频失败", err);
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
//region版本更新检测
|
||||
//微信开发者工具上可以通过「编译模式」下的「下次编译模拟更新」开关来调试
|
||||
qiangzhiUpdata() {
|
||||
if (window['ks'].getUpdateManager == null) {
|
||||
logger.log("快手 没有更新管理器", window['ks'].getUpdateManager)
|
||||
return;
|
||||
}
|
||||
|
||||
const updateManager = window['ks'].getUpdateManager();
|
||||
|
||||
//监听向微信后台请求检查更新结果事件。微信在小程序每次启动(包括热启动)时自动检查更新,不需由开发者主动触发。
|
||||
updateManager.onCheckForUpdate((res) => {
|
||||
// 请求完新版本信息的回调
|
||||
logger.log("快手 检查是否有新版本:", res.hasUpdate)
|
||||
});
|
||||
|
||||
//监听小程序有版本更新事件。客户端主动触发下载(无需开发者触发),下载成功后回调
|
||||
updateManager.onUpdateReady(async () => {
|
||||
const { confirm } = await window['ks'].showModal({
|
||||
title: '更新提示',
|
||||
content: '新版本已经准备好,是否重启应用?',
|
||||
});
|
||||
if (confirm) {
|
||||
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
||||
updateManager.applyUpdate();
|
||||
}
|
||||
});
|
||||
|
||||
//监听小程序更新失败事件。小程序有新版本,客户端主动触发下载(无需开发者触发),下载失败(可能是网络原因等)时回调
|
||||
updateManager.onUpdateFailed(function (err) {
|
||||
logger.log("快手 新版本下载失败", err)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//客服功能是否支持
|
||||
kefuSupport() {
|
||||
logger.log("快手 不支持联系客服")
|
||||
return false;
|
||||
}
|
||||
//进入联系客服
|
||||
openKefu() {
|
||||
logger.log("快手 进入联系客服")
|
||||
}
|
||||
|
||||
|
||||
//region 播放背景视频
|
||||
private _bgVideo: any = null; //正式播放的视频组件
|
||||
private _bgShow: boolean = false;
|
||||
private curPlayType: VideoRoleType = VideoRoleType.None //当前播放的视频的类型
|
||||
playBgAudio(remoteUrl:string, vtype:VideoRoleType, loop:boolean = false, extra:any = {}) {
|
||||
if (!window['ks'].createVideo) {
|
||||
logger.log("快手 不支持播放视频")
|
||||
return
|
||||
}
|
||||
if (this._bgVideo && this._bgShow) {
|
||||
this.playBgAudioNext(remoteUrl, vtype, loop, extra);
|
||||
return
|
||||
}
|
||||
let self = this;
|
||||
logger.log("微信 播放背景视频组件1", remoteUrl);
|
||||
this.curPlayType = vtype
|
||||
if (!this._bgVideo) {
|
||||
this._bgVideo = this.createVideoHandle();
|
||||
// this._bgVideo.onPlay(() => {
|
||||
// logger.log("微信 背景视频播放开始");
|
||||
// })
|
||||
this._bgVideo.onTimeUpdate((_tinfo:any) =>{
|
||||
// logger.log("微信 背景视频播放进度", self._bgShow, _tinfo);
|
||||
if (!self._bgShow) {
|
||||
if (_tinfo && _tinfo.position > 0.01) {
|
||||
logger.log("微信 背景视频1进入视野");
|
||||
self.videoMoveIn(self._bgVideo)
|
||||
self._bgShow = true;
|
||||
self.removeBgAudioNext()
|
||||
Utils.sendInnerMsg(InnerMsgCode.BgVideo_Ready, {});
|
||||
}
|
||||
}
|
||||
})
|
||||
this._bgVideo.onEnded(() => {
|
||||
if (self.doPlayEmoReadyAudio()) {
|
||||
self.setBgAudioPause(self._bgVideo)
|
||||
}
|
||||
Utils.sendInnerMsg(InnerMsgCode.BgVideo_End, {});
|
||||
})
|
||||
}
|
||||
this._bgVideo.src = remoteUrl; //视频的地址
|
||||
this._bgVideo.loop = loop; //循环播放
|
||||
this._bgVideo.play();
|
||||
}
|
||||
removeBgAudio() {
|
||||
this._bgShow = false;
|
||||
if (this._bgVideo) {
|
||||
this._bgVideo.stop();
|
||||
this.videoMoveOut(this._bgVideo)
|
||||
}
|
||||
}
|
||||
//播放下一个视频,先加载,播放后再转到正式组件上
|
||||
private _bgTempVideo: any = null; //临时视频组件,等加载完成
|
||||
private _bgTempShow: boolean = false;
|
||||
playBgAudioNext(remoteUrl:string, vtype:VideoRoleType, loop:boolean = false, extra:any = {}) {
|
||||
this.removeBgAudioNext();
|
||||
logger.log("微信 创建背景视频组件2--->", remoteUrl);
|
||||
this.curPlayType = vtype
|
||||
let self = this;
|
||||
if (!this._bgTempVideo) {
|
||||
this._bgTempVideo = this.createVideoHandle();
|
||||
// this._bgTempVideo.onPlay(() => {
|
||||
// logger.log("微信 临时背景视频播放开始");
|
||||
// })
|
||||
this._bgTempVideo.onTimeUpdate((_tinfo:any) =>{
|
||||
// logger.log("微信 临时背景视频播放进度", self._bgTempShow, _tinfo);
|
||||
if (!self._bgTempShow) {
|
||||
if (_tinfo && _tinfo.position > 0.01) {
|
||||
logger.log("微信 背景视频2进入视野");
|
||||
self._bgTempShow = true;
|
||||
self.videoMoveIn(self._bgTempVideo)
|
||||
self.removeBgAudio()
|
||||
Utils.sendInnerMsg(InnerMsgCode.BgVideo_Ready, {});
|
||||
}
|
||||
}
|
||||
})
|
||||
this._bgTempVideo.onEnded(() => {
|
||||
if (self.doPlayEmoReadyAudio()) {
|
||||
self.setBgAudioPause(self._bgTempVideo)
|
||||
}
|
||||
Utils.sendInnerMsg(InnerMsgCode.BgVideo_End, {});
|
||||
})
|
||||
}
|
||||
this._bgTempVideo.src = remoteUrl; //视频的地址
|
||||
this._bgTempVideo.loop = loop; //循环播放
|
||||
this._bgTempVideo.play();
|
||||
}
|
||||
removeBgAudioNext() {
|
||||
this._bgTempShow = false;
|
||||
if (this._bgTempVideo) {
|
||||
this._bgTempVideo.stop();
|
||||
this.videoMoveOut(this._bgTempVideo)
|
||||
}
|
||||
}
|
||||
|
||||
//region 播放emo视频
|
||||
private _emoVideo: any = null; //正式播放的视频组件
|
||||
private _emoShow: boolean = false;
|
||||
addEmoAudio(remoteUrl:string, vtype:VideoRoleType, loop:boolean = false, extra:any = {}) {
|
||||
if (this._emoVideo && this._emoShow) {
|
||||
this.playEmoAudioNext(remoteUrl, vtype, loop, extra);
|
||||
return
|
||||
}
|
||||
let self = this;
|
||||
logger.log("微信 播放emo视频1", remoteUrl);
|
||||
this.curPlayType = vtype
|
||||
if (!this._emoVideo) {
|
||||
this._emoVideo = this.createVideoHandle();
|
||||
// this._emoVideo.onPlay(() => {
|
||||
// logger.log("微信 背景视频播放开始");
|
||||
// })
|
||||
this._emoVideo.onTimeUpdate((_tinfo:any) =>{
|
||||
// logger.log("微信 背景视频播放进度", self._emoShow, _tinfo);
|
||||
if (!self._emoShow) {
|
||||
if (_tinfo && _tinfo.position > 0.01) {
|
||||
logger.log("微信 emo视频1准备好了");
|
||||
self._emoShow = true;
|
||||
self.removeEmoAudioNext()
|
||||
self.setEmoReadyAudio(self._emoVideo)
|
||||
if (self.curPlayType == VideoRoleType.emo) {
|
||||
self.doPlayEmoReadyAudio()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
this._emoVideo.onEnded(() => {
|
||||
self.doEmoFinish()
|
||||
})
|
||||
}
|
||||
this._emoVideo.src = remoteUrl; //视频的地址
|
||||
this._emoVideo.loop = loop; //循环播放
|
||||
this._emoVideo.play();
|
||||
}
|
||||
removeEmoAudio() {
|
||||
this._emoShow = false;
|
||||
if (this._emoVideo) {
|
||||
this._emoVideo.stop();
|
||||
this.videoMoveOut(this._emoVideo)
|
||||
}
|
||||
}
|
||||
//播放下一个视频,先加载,播放后再转到正式组件上
|
||||
private _emoTempVideo: any = null; //临时视频组件,等加载完成
|
||||
private _emoTempShow: boolean = false;
|
||||
playEmoAudioNext(remoteUrl:string, vtype:VideoRoleType, loop:boolean = false, extra:any = {}) {
|
||||
this.removeEmoAudioNext();
|
||||
logger.log("微信 播放emo视频2--->", remoteUrl);
|
||||
this.curPlayType = vtype
|
||||
let self = this;
|
||||
if (!this._emoTempVideo) {
|
||||
this._emoTempVideo = this.createVideoHandle();
|
||||
// this._emoTempVideo.onPlay(() => {
|
||||
// logger.log("微信 临时背景视频播放开始");
|
||||
// })
|
||||
this._emoTempVideo.onTimeUpdate((_tinfo:any) =>{
|
||||
// logger.log("微信 临时背景视频播放进度", self._emoTempShow, _tinfo);
|
||||
if (!self._emoTempShow) {
|
||||
if (_tinfo && _tinfo.position > 0.01) {
|
||||
logger.log("微信 emo视频2已准备好");
|
||||
self._emoTempShow = true;
|
||||
self.removeEmoAudio()
|
||||
self.setEmoReadyAudio(self._emoTempVideo)
|
||||
if (self.curPlayType == VideoRoleType.emo) {
|
||||
self.doPlayEmoReadyAudio()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
this._emoTempVideo.onEnded(() => {
|
||||
self.doEmoFinish()
|
||||
})
|
||||
}
|
||||
this._emoTempVideo.src = remoteUrl; //视频的地址
|
||||
this._emoTempVideo.loop = loop; //循环播放
|
||||
this._emoTempVideo.play();
|
||||
}
|
||||
removeEmoAudioNext() {
|
||||
this._emoTempShow = false;
|
||||
if (this._emoTempVideo) {
|
||||
this._emoTempVideo.stop();
|
||||
this.videoMoveOut(this._emoTempVideo)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//视频移入屏幕
|
||||
private videoMoveIn(video:any) {
|
||||
let adainfo = this.getVideoAdaInfo()
|
||||
video.x = adainfo.x
|
||||
video.y = adainfo.y
|
||||
}
|
||||
//视频移出屏幕
|
||||
private videoMoveOut(video:any) {
|
||||
video.x = 10000
|
||||
video.y = 10000
|
||||
}
|
||||
/**创建一个视频播放器 */
|
||||
private createVideoHandle() {
|
||||
let size = this.getWindowSize();
|
||||
let adainfo = this.getVideoAdaInfo()
|
||||
let bgVideo = window['ks'].createVideo({
|
||||
// src: remoteUrl, //视频的地址
|
||||
x: size.width, //先在屏幕外创建,等加载完成后再移动到屏幕上
|
||||
y: size.height,
|
||||
width: this.videoWidth*adainfo.scale, //视频的宽度
|
||||
height: this.videoHeight*adainfo.scale, //视频的高度
|
||||
autoplay: true, //自动播放
|
||||
// loop: loop, //循环播放
|
||||
controls: false, //是否显示控件
|
||||
showProgress: false, //显示进度条
|
||||
showProgressInControlMode: false, //在控制模式下显示进度条
|
||||
enableProgressGesture: false, //是否启用进度手势
|
||||
showCenterPlayBtn: false, //是否显示中间的播放按钮
|
||||
underGameView: true, //视频是否显示在游戏画布之下。需要设置Camera的Clear Color为透明色
|
||||
// backgroundColor: "#00000000", //视频背景颜色
|
||||
objectFit: "fill" //视频的填充模式
|
||||
})
|
||||
return bgVideo
|
||||
}
|
||||
//获取视频适配信息
|
||||
private videoWidth = 720
|
||||
private videoHeight = 1280
|
||||
private videoAdaInfo = null
|
||||
private getVideoAdaInfo() {
|
||||
if (this.videoAdaInfo) return this.videoAdaInfo
|
||||
this.videoAdaInfo = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
scale: 1
|
||||
}
|
||||
let size = this.getWindowSize();
|
||||
let ratiow = size.width / this.videoWidth; //屏幕和视频的宽高比,谁大用谁
|
||||
let ratioh = size.height / this.videoHeight;
|
||||
if (ratiow > ratioh) {
|
||||
this.videoAdaInfo.scale = ratiow
|
||||
this.videoAdaInfo.x = 0
|
||||
this.videoAdaInfo.y = -(this.videoHeight * ratiow - size.height) / 2
|
||||
} else {
|
||||
this.videoAdaInfo.scale = ratioh
|
||||
this.videoAdaInfo.x = -(this.videoWidth * ratioh - size.width) / 2
|
||||
this.videoAdaInfo.y = 0
|
||||
}
|
||||
logger.log("微信 视频适配信息", this.videoAdaInfo, size)
|
||||
return this.videoAdaInfo
|
||||
}
|
||||
|
||||
//设置暂停播放的主视频
|
||||
private vpWait: any = null;
|
||||
setBgAudioPause(wait:any) {
|
||||
logger.log("微信 主视频暂停播放")
|
||||
this.vpWait = wait
|
||||
this.vpWait.pause()
|
||||
}
|
||||
replayBgAudioPause() {
|
||||
logger.log("微信 主视频继续播放")
|
||||
if (this.vpWait) {
|
||||
this.vpWait.play()
|
||||
}
|
||||
}
|
||||
|
||||
//设置准备好要播放的表情视频
|
||||
private emoReady: any = null;
|
||||
setEmoReadyAudio(au: any) {
|
||||
logger.log("微信 设置emo ready视频")
|
||||
if (this.emoReady) {
|
||||
this.emoReady.stop()
|
||||
this.videoMoveOut(this.emoReady)
|
||||
}
|
||||
this.emoReady = au;
|
||||
this.emoReady.pause()
|
||||
}
|
||||
//移除准备好要播放的表情视频
|
||||
removeEmoReadyAudio() {
|
||||
logger.log("微信 移除emo ready视频")
|
||||
if (this.emoReady) {
|
||||
this.emoReady.stop()
|
||||
this.videoMoveOut(this.emoReady)
|
||||
}
|
||||
this.emoReady = null
|
||||
}
|
||||
//播放准备好要播放的表情视频
|
||||
doPlayEmoReadyAudio():boolean {
|
||||
if (this.emoReady) {
|
||||
logger.log("微信 播放emo ready视频")
|
||||
this.emoReady.play()
|
||||
this.videoMoveIn(this.emoReady)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
//表情视频播放结束
|
||||
doEmoFinish() {
|
||||
logger.log("微信emo ready视频播放结束")
|
||||
this.removeEmoReadyAudio()
|
||||
this.replayBgAudioPause()
|
||||
}
|
||||
|
||||
//region 复制到剪贴板
|
||||
/**复制文本到剪贴板 */
|
||||
copyToClipboard(text: string, cb?: Function) {
|
||||
logger.log("快手 复制到剪贴板:", text);
|
||||
window['ks'].setClipboardData({
|
||||
data: text,
|
||||
success: () => {
|
||||
logger.log("快手 复制成功");
|
||||
cb && cb(true);
|
||||
},
|
||||
fail: (err) => {
|
||||
logger.log("快手 复制失败:", err);
|
||||
cb && cb(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//region 友盟+
|
||||
umaInit() {
|
||||
}
|
||||
//友盟统计是否开启
|
||||
umaSwt() {
|
||||
return false;
|
||||
}
|
||||
//友盟事件统计
|
||||
umaEvent(eventName: string, value: any = {}) {
|
||||
}
|
||||
}
|
||||
@@ -1,965 +0,0 @@
|
||||
import { randomRange, view } from "cc";
|
||||
import GlobalValue, { VideoRoleType } from "../Common/GlobalValue";
|
||||
import SubManager from "../../Sub/SubManager";
|
||||
import { I_SDK_UserInfo_Callback, SDKManager } from "./SDKManager";
|
||||
import Utils from "../Common/Utils";
|
||||
import uma from "../../../utils/uma.wx.min.js";
|
||||
import { InnerMsgCode } from "../Config/InnerMsgCode";
|
||||
import { logger } from "db://assets/Scripts/Main/Common/Logger";
|
||||
|
||||
//广告ID
|
||||
const wx_banner_ad_unit_id = "test";
|
||||
const wx_splash_ad_unit_id = "test";
|
||||
const wx_video_ad_unit_id = "adunit-a79e037dfaac7bae";
|
||||
|
||||
export class luffaSDK {
|
||||
static g_InGameScene = null; //游戏场景值
|
||||
|
||||
private wx_video: any = null;
|
||||
private wx_splash: any = null;
|
||||
private wx_banner: any = null;
|
||||
private wx_video_callback: Function = null;
|
||||
private wx_video_tag: number = null;
|
||||
private wx_gameClub: any = null; //游戏圈按钮
|
||||
|
||||
private ShareSTime: any;
|
||||
private ShareCb: any; //分享回调
|
||||
private shareTxt = [
|
||||
"分享失败",
|
||||
"请分享到一个群",
|
||||
"请分享给一位好友",
|
||||
"分享过于频繁",
|
||||
];
|
||||
|
||||
//初始化
|
||||
init(cb: Function = null) {
|
||||
// 保持屏幕常亮
|
||||
window["wx"].setKeepScreenOn({ keepScreenOn: true });
|
||||
luffaSDK.g_InGameScene = window["wx"].getLaunchOptionsSync().scene;
|
||||
logger.log("init luffa - 进入游戏的场景值", luffaSDK.g_InGameScene);
|
||||
|
||||
//this.init_video(); //初始化视频广告
|
||||
//this.init_splash(); //初始化插屏广告
|
||||
//this.init_banner(); //初始化Banner广告 横幅广告
|
||||
this.qiangzhiUpdata(); //检测更新
|
||||
cb && cb();
|
||||
}
|
||||
|
||||
/**获取用户授权状态
|
||||
* @param autoKey string 授权类型 userInfo=用户信息,对应接口wx.getUserInfo
|
||||
*/
|
||||
checkAutoSetting(autoKey: string, cb: Function = null) {
|
||||
window["wx"].getSetting({
|
||||
success(res: any) {
|
||||
logger.log("微信 - 检测权限状态 succ:", JSON.stringify(res));
|
||||
if (autoKey == "userInfo" && res.authSetting["scope.userInfo"]) {
|
||||
cb && cb(true);
|
||||
} else {
|
||||
cb && cb(false);
|
||||
}
|
||||
},
|
||||
fail(res: any) {
|
||||
logger.log("微信 - 检测权限状态 fail:", JSON.stringify(res));
|
||||
cb && cb(false);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取个人信息
|
||||
*/
|
||||
getUserInfo(cb: I_SDK_UserInfo_Callback = null) {
|
||||
logger.log("微信 - 正在获取用户信息...");
|
||||
var self = this;
|
||||
window["wx"].getUserInfo({
|
||||
success: (res) => {
|
||||
logger.log("微信 - 获取用户信息成功:", res);
|
||||
cb &&
|
||||
cb({
|
||||
avatarUrl: res.userInfo.avatarUrl,
|
||||
nickName: res.userInfo.nickName,
|
||||
});
|
||||
},
|
||||
fail: (err) => {
|
||||
logger.log("微信 - 获取用户信息失败:", err);
|
||||
self.openUserAuthorize(cb);
|
||||
},
|
||||
});
|
||||
}
|
||||
//申请用户信息授权
|
||||
openUserAuthorize(cb: any) {
|
||||
var self = this;
|
||||
window["wx"].getSetting({
|
||||
scope: "scope.userInfo",
|
||||
success(res: any) {
|
||||
logger.log("微信 authorize succ:", JSON.stringify(res));
|
||||
|
||||
if (res.authSetting["scope.userInfo"]) {
|
||||
self.getUserInfo(cb);
|
||||
} else {
|
||||
let systemInfo = window["wx"].getSystemInfoSync();
|
||||
let button = window["wx"].createUserInfoButton({
|
||||
type: "text",
|
||||
text: "",
|
||||
// @ts-ignore
|
||||
style: {
|
||||
left: 0,
|
||||
top: 0,
|
||||
width: systemInfo.screenWidth,
|
||||
height: systemInfo.screenHeight,
|
||||
backgroundColor: "#00000000", //最后两位为透明度
|
||||
textAlign: "center",
|
||||
},
|
||||
});
|
||||
logger.log("微信 点击开始游戏授权用户信息");
|
||||
button.onTap((res) => {
|
||||
button.destroy();
|
||||
// if (res.userInfo) {
|
||||
// logger.log(res.userInfo)
|
||||
// //此时可进行登录操作
|
||||
// cb && cb(res.userInfo)
|
||||
// }
|
||||
logger.log("微信 点击Tap", res);
|
||||
self.getUserInfo(cb);
|
||||
});
|
||||
}
|
||||
},
|
||||
fail(err) {
|
||||
logger.log("微信 - authorize fail", err);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
//region 微信登录
|
||||
login(cb: Function = null) {
|
||||
window["wx"].login({
|
||||
success: (res) => {
|
||||
if (res.code) {
|
||||
logger.log("微信 - 登录成功", res.code);
|
||||
cb && cb({ platform: 1, code: res.code });
|
||||
} else {
|
||||
logger.log("微信 - 登录失败", res.errMsg);
|
||||
cb && cb({ platform: 1, code: null });
|
||||
}
|
||||
},
|
||||
fail(res: any) {
|
||||
logger.log(`微信 login 调用失败`);
|
||||
logger.log(res.anonymousCode);
|
||||
cb && cb({ platform: 1, code: null });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
//初始化视频广告
|
||||
private init_video() {
|
||||
if ((wx_video_ad_unit_id as any) == "test") {
|
||||
logger.log("微信 激励广告id未配置,跳过此类型初始化");
|
||||
return;
|
||||
}
|
||||
|
||||
this.wx_video = window["wx"].createRewardedVideoAd({
|
||||
adUnitId: wx_video_ad_unit_id,
|
||||
disableFallbackSharePage: true, // 是否禁用分享页,默认为false
|
||||
});
|
||||
this.wx_video.onLoad(() => {
|
||||
logger.log("onLoad event emit");
|
||||
});
|
||||
this.wx_video.onError((err) => {
|
||||
logger.log("onError event emit", err);
|
||||
});
|
||||
this.wx_video.onClose((res) => {
|
||||
logger.log("onClose event emit", res);
|
||||
// 用户点击了【关闭广告】按钮
|
||||
// 小于 2.1.0 的基础库版本,res 是一个 undefined
|
||||
if ((res && res.isEnded) || res === undefined) {
|
||||
// 正常播放结束,可以下发游戏奖励
|
||||
if (this.wx_video_callback) {
|
||||
this.wx_video_callback(this.wx_video_tag);
|
||||
}
|
||||
} else {
|
||||
// 播放中途退出,不下发游戏奖励
|
||||
//wx_video_callback(-1);
|
||||
}
|
||||
SDKManager.video_ad_back();
|
||||
});
|
||||
}
|
||||
|
||||
//初始化插屏广告
|
||||
private init_splash() {
|
||||
if ((wx_splash_ad_unit_id as any) == "test") {
|
||||
logger.log("微信 插屏广告id未配置,跳过此类型初始化");
|
||||
return;
|
||||
}
|
||||
// 创建插屏广告实例,提前初始化
|
||||
if (window["wx"].createInterstitialAd) {
|
||||
this.wx_splash = window["wx"].createInterstitialAd({
|
||||
adUnitId: wx_splash_ad_unit_id,
|
||||
});
|
||||
this.wx_splash.onLoad(() => {
|
||||
logger.log("splash onLoad event emit");
|
||||
});
|
||||
this.wx_splash.onError((err) => {
|
||||
logger.log("splash onError event emit", err);
|
||||
});
|
||||
this.wx_splash.onClose((res) => {
|
||||
logger.log("splash onClose event emit", res);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//初始化Banner
|
||||
private init_banner() {
|
||||
if ((wx_banner_ad_unit_id as any) == "test") {
|
||||
logger.log("微信 横幅广告id未配置,跳过此类型初始化");
|
||||
return;
|
||||
}
|
||||
let winSize = window["wx"].getSystemInfoSync();
|
||||
let bannerHeight = 80;
|
||||
let bannerWidth = 300;
|
||||
this.wx_banner = window["wx"].createBannerAd({
|
||||
adUnitId: wx_banner_ad_unit_id,
|
||||
adIntervals: 30,
|
||||
style: {
|
||||
left: (winSize.windowWidth - bannerWidth) / 2,
|
||||
top: winSize.windowHeight - bannerHeight,
|
||||
width: bannerWidth,
|
||||
},
|
||||
});
|
||||
//微信缩放后得到banner的真实高度,从新设置banner的top 属性
|
||||
this.wx_banner.onResize((res) => {
|
||||
this.wx_banner.style.top =
|
||||
winSize.windowHeight - this.wx_banner.style.realHeight;
|
||||
});
|
||||
|
||||
this.wx_banner.onError((res) => {});
|
||||
}
|
||||
|
||||
//region 广告
|
||||
//显示视频广告
|
||||
show_video(callback: Function, tag: number) {
|
||||
if ((wx_video_ad_unit_id as any) == "test") {
|
||||
logger.log("未接入广告ID,视频广告请求直接返回");
|
||||
callback && callback();
|
||||
SDKManager.video_ad_back();
|
||||
return;
|
||||
}
|
||||
if (this.wx_video) {
|
||||
this.wx_video_callback = callback;
|
||||
this.wx_video_tag = tag;
|
||||
this.wx_video.load().then(() => {
|
||||
this.wx_video.show().catch((err) => {
|
||||
this.wx_video.load().then(() => this.wx_video.show());
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//显示插屏
|
||||
show_splash() {
|
||||
// 在适合的场景显示插屏广告
|
||||
// if (this.wx_splash) {
|
||||
// this.wx_splash.show().catch((err) => {
|
||||
// this.wx_splash.load().then(()=>{
|
||||
|
||||
// })
|
||||
// })
|
||||
// }
|
||||
|
||||
if (this.wx_splash) {
|
||||
this.wx_splash
|
||||
.load()
|
||||
.then(() => {
|
||||
this.wx_splash.show();
|
||||
})
|
||||
.catch((err) => {
|
||||
logger.log(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//显示Banner
|
||||
show_banner() {
|
||||
if (this.wx_banner) {
|
||||
this.wx_banner.show(); //banner 默认隐藏(hide) 要打开
|
||||
}
|
||||
}
|
||||
|
||||
//隐藏Banner
|
||||
hide_banner() {
|
||||
if (this.wx_banner) {
|
||||
this.wx_banner.hide(); //banner 默认隐藏(hide) 要打开
|
||||
}
|
||||
}
|
||||
|
||||
//region 分享
|
||||
/**分享图片*/
|
||||
private SharePicAry = [
|
||||
{
|
||||
id: "7wUnG0FFQry/nCdxI9kKYQ==",
|
||||
url: "https://mmocgame.qpic.cn/wechatgame/W9Az4zfwkAvic2MPaoBEdYEMVht0VwJv6eQF2myMU8IIFbQAZ92Fg73Qp9MUdPMj8/0",
|
||||
},
|
||||
{
|
||||
id: "NCa1cR9YSWinaozMovG6kQ==",
|
||||
url: "https://mmocgame.qpic.cn/wechatgame/uRnpa1JW3rTyYxQHVUI2OaUmHZStMSWfoXPpx7AgceIN2EuqE2DRicDNjcBTA7arK/0",
|
||||
},
|
||||
{
|
||||
id: "adU43/q3Te+86ThFH+8R+g==",
|
||||
url: "https://mmocgame.qpic.cn/wechatgame/fVu8XV4rOQv0iaLzIr4m67DZAOgN1NDe7jSCDoT2ibHuqRkacaeHCdCopIgLzrlBibR/0",
|
||||
},
|
||||
{
|
||||
id: "k93MB1OQQzGuHDv6LhlJ4g==",
|
||||
url: "https://mmocgame.qpic.cn/wechatgame/rrYFeia8mywog7QfGagj9Uiad5Sicu3qNhV6IQcgVkZbUjibaWe70SUsvp9vNESBpje7/0",
|
||||
},
|
||||
{
|
||||
id: "/ry07TA6SXea+AoABH1D+w==",
|
||||
url: "https://mmocgame.qpic.cn/wechatgame/f0cXVicm8xoT33Txqf2o2CRyreAicOiaHh8JFlbxHaDibYWZoBulHTF9v1s3EaUWfaMk/0",
|
||||
},
|
||||
{
|
||||
id: "hYrwZorvQaOP3XbbC77PZw==",
|
||||
url: "https://mmocgame.qpic.cn/wechatgame/HEsiaI4wLnb2SVCthB5pZeBULvWsk71EdlK1WUXic23cPuzeWribbjibjlebOPyNy1wL/0",
|
||||
},
|
||||
{
|
||||
id: "nzn7R/iLQoerxHhYbEM6AQ==",
|
||||
url: "https://mmocgame.qpic.cn/wechatgame/fxaAdTaO5GvRicwozj7sfUiat1ef3XLgjicLLZpeJYWtjyBjIhfh7TP2aZzOItwlpff/0",
|
||||
},
|
||||
{
|
||||
id: "RvJk1ZZzR1iwqKvI39Rt8w==",
|
||||
url: "https://mmocgame.qpic.cn/wechatgame/WibiboKxDQsGxnVMhxebwvouMGnn5MKJibF18lS1iaibo1yrWnoTJgPAIgVX3dZEkV0Ta/0",
|
||||
},
|
||||
{
|
||||
id: "6OgcDWd5SI2R2SmnOxs3Gw==",
|
||||
url: "https://mmocgame.qpic.cn/wechatgame/bpd6RQyPEB7xsoqyzribiaGnibELo6xARRPSLsgtickwcMHtSv920nweBbxIG7OiaJXFo/0",
|
||||
},
|
||||
{
|
||||
id: "6qb2SmFBRgi3pv+pUIbulA==",
|
||||
url: "https://mmocgame.qpic.cn/wechatgame/LXCSUXdVagducqPcChicS5yQWqna7oduKCnzwlG11a7W1Lx6Rwv4Y1tBsMVWqP4Fs/0",
|
||||
},
|
||||
{
|
||||
id: "rdrtaMpJTd6CtMI3dJikHg==",
|
||||
url: "https://mmocgame.qpic.cn/wechatgame/Zzc9s1q36erWTkUxLDjqOus62PTTysBW4PGUaDO5Pr67kT3g9W3HlMakBSiaicxGdH/0",
|
||||
},
|
||||
{
|
||||
id: "sflrnBurRxC2dow0iuQNEg==",
|
||||
url: "https://mmocgame.qpic.cn/wechatgame/YiacDpfxzCGbXUHmtMmcfr8gIF7DicDib6q0pJaiaWXbTWOBGkCbpeuMic1SMgr91v43K/0",
|
||||
},
|
||||
{
|
||||
id: "GkB88GpmR6KvjrV3yMxeWA==",
|
||||
url: "https://mmocgame.qpic.cn/wechatgame/f4fzfIKfgFIBFWxjsFibMUHKQA72JutALOXbuM3vaS0W9ZSUjC2rysb5Tic23lQb95/0",
|
||||
},
|
||||
{
|
||||
id: "UxAhraIxTayr/3Mdhi0Uzg==",
|
||||
url: "https://mmocgame.qpic.cn/wechatgame/qDv24VqH6NBBP0IXNJ2EbSScIic6WsX0KcLJSNs1ThibYJx6QnDnKIT59CcIQSnZvD/0",
|
||||
},
|
||||
{
|
||||
id: "ISSkaxiBRhyn3yZh2AS0eQ==",
|
||||
url: "https://mmocgame.qpic.cn/wechatgame/22HxqYDEUu1yelwdMR30ntjn6rzaYf8QJgrOkFlteicoqbacSptHiaNgK7cygteg99/0",
|
||||
},
|
||||
{
|
||||
id: "m0GQ8b4YTU2u1So1Wr9Rjg==",
|
||||
url: "https://mmocgame.qpic.cn/wechatgame/D8nvAYkIticAEYwTBb3uC83TVferTkpqU5Akj8XGwPCYfNZibTeunZVd5ticqHxvgHC/0",
|
||||
},
|
||||
{
|
||||
id: "F6j57H82QyyiD1i0MaS+0g==",
|
||||
url: "https://mmocgame.qpic.cn/wechatgame/FtniagLR3ueTRx3ibhy98G6pGdC69A38n9jUrVFHEhL9gqceaUnaTpmQHkiaPU1JE4h/0",
|
||||
},
|
||||
{
|
||||
id: "dqd9Gfx2QGKilvChFwoc7Q==",
|
||||
url: "https://mmocgame.qpic.cn/wechatgame/yauvGchcicTl0zx4dYqfhAxl40k7ZbVM59VbPjDPcouesWbPrpsFQzNvfsSUYwUkb/0",
|
||||
},
|
||||
];
|
||||
|
||||
//分享文本
|
||||
private ShareTextAry = [
|
||||
"话术策略大挑战:十句话让 AI 二次元少女心动!",
|
||||
"心动话术挑战,60 位 AI 女友候选等你 Pick!",
|
||||
"二次元话术相亲模拟!60 位 AI 对象等你攻略!",
|
||||
"全 AI 聊天互动!收集二次元少女的心动信号!",
|
||||
"首款 AI 话术策略游戏,攻略个性 AI 二次元女友!",
|
||||
"锻炼你的话术策略,挑战 AI 女友最速结婚路线!",
|
||||
"直男 or 情话海王?60 位 AI 女友检测话术段位!",
|
||||
"高能话术挑战 60 位 AI 少女,解锁专属甜蜜结局!",
|
||||
];
|
||||
|
||||
//分享信息
|
||||
shareInfo() {
|
||||
let rand1 = Utils.getRandomInt(0, this.SharePicAry.length - 1);
|
||||
let picmap = this.SharePicAry[rand1];
|
||||
let rand2 = Utils.getRandomInt(0, this.ShareTextAry.length - 1);
|
||||
let text = this.ShareTextAry[rand2];
|
||||
logger.log("分享:", rand1, rand2);
|
||||
return {
|
||||
title: text,
|
||||
query: "ShareCode=" + "user_default", //ModelPlayer.I.getPlayerId(),
|
||||
imageUrl: picmap.url,
|
||||
imageUrlId: picmap.id,
|
||||
};
|
||||
}
|
||||
//主动拉起分享
|
||||
show_share(rewardCB?: Function) {
|
||||
logger.log("主动拉起分享");
|
||||
let info: any = this.shareInfo();
|
||||
info.succ = rewardCB;
|
||||
info.fail = null;
|
||||
this.ShareCb = info;
|
||||
window["wx"].shareAppMessage(info);
|
||||
}
|
||||
|
||||
//获取设备分辨率
|
||||
getWindowSize() {
|
||||
let windowinfo = window["wx"].getWindowInfo();
|
||||
return { width: windowinfo.screenWidth, height: windowinfo.screenHeight };
|
||||
}
|
||||
|
||||
//显示游戏圈
|
||||
show_gameClub(leftRatio, topRatio, widthRatio, heightRatio) {
|
||||
logger.log("显示游戏圈");
|
||||
if (this.wx_gameClub) {
|
||||
this.wx_gameClub.show();
|
||||
} else {
|
||||
let windowinfo = window["wx"].getWindowInfo();
|
||||
let x = windowinfo.screenWidth * leftRatio;
|
||||
let y = windowinfo.screenHeight * topRatio;
|
||||
let w = windowinfo.screenWidth * widthRatio; //按钮宽高
|
||||
let h = windowinfo.screenHeight * heightRatio;
|
||||
|
||||
logger.log(
|
||||
"游戏圈按钮配置:",
|
||||
windowinfo,
|
||||
leftRatio,
|
||||
topRatio,
|
||||
widthRatio,
|
||||
heightRatio,
|
||||
x,
|
||||
y,
|
||||
w,
|
||||
h
|
||||
);
|
||||
this.wx_gameClub = window["wx"].createGameClubButton({
|
||||
type: "string",
|
||||
text: "",
|
||||
// type: 'image',
|
||||
icon: "green",
|
||||
style: {
|
||||
left: x, //这个坐标对应UI上的按钮时,按钮要勾选适配
|
||||
top: y,
|
||||
width: w,
|
||||
height: h,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
//隐藏游戏圈
|
||||
hide_gameClub() {
|
||||
logger.log("隐藏游戏圈");
|
||||
if (this.wx_gameClub) {
|
||||
this.wx_gameClub.hide();
|
||||
}
|
||||
}
|
||||
|
||||
//region base64音频播放
|
||||
//检查是否支持base64音频播放
|
||||
checkSupportBase64Audio() {
|
||||
return true;
|
||||
}
|
||||
//播放base64音频
|
||||
private _innerAudioContext: any = null;
|
||||
private _iacIdx = 0; //音频播放索引
|
||||
playBase64Audio(base64, loop) {
|
||||
if (!this.checkSupportBase64Audio()) {
|
||||
logger.log("微信平台不支持base64音频播放");
|
||||
return;
|
||||
}
|
||||
|
||||
let substring = base64;
|
||||
let qianzhui = "data:audio/x-wav;base64,";
|
||||
if (base64.startsWith(qianzhui)) {
|
||||
substring = base64.substring(qianzhui.length, base64.length);
|
||||
}
|
||||
|
||||
let self = this;
|
||||
const fs = window["wx"].getFileSystemManager();
|
||||
//1.删除上一个音频
|
||||
const lastPath =
|
||||
window["wx"].env.USER_DATA_PATH + `/ordernew${self._iacIdx}.mp3`;
|
||||
logger.log("微信 正在删除上一个音频 ->", lastPath);
|
||||
fs.removeSavedFile({
|
||||
filePath: lastPath,
|
||||
success(res) {
|
||||
logger.log("微信 删除上一个音频成功", res);
|
||||
},
|
||||
fail(err) {
|
||||
logger.log("微信 删除上一个音频失败", err);
|
||||
},
|
||||
complete(res) {
|
||||
logger.log("微信 删除上一个音频完成", res);
|
||||
|
||||
//2.保存当前音频
|
||||
//这里需要每次保存时换一下名字的原因是:innerAudioContext设置路径时如果路径相同,会认为还是同一个音频,不会重新加载,所以需要每次保存时换一下名字
|
||||
self._iacIdx++;
|
||||
const audioPath =
|
||||
window["wx"].env.USER_DATA_PATH + `/ordernew${self._iacIdx}.mp3`;
|
||||
logger.log("微信 正在保存本次音频 ->", audioPath);
|
||||
fs.writeFile({
|
||||
filePath: audioPath,
|
||||
data: substring,
|
||||
encoding: "base64",
|
||||
success(res) {
|
||||
if (self._innerAudioContext == null) {
|
||||
self._innerAudioContext = window["wx"].createInnerAudioContext();
|
||||
// 添加播放结束的回调
|
||||
self._innerAudioContext.onEnded(() => {
|
||||
logger.log("微信 AI语音播放结束");
|
||||
self._innerAudioContext.stop(); // 使用 stop 方法停止音频并重置播放状态
|
||||
self._innerAudioContext.destroy(); // 销毁音频实例
|
||||
self._innerAudioContext = null;
|
||||
});
|
||||
}
|
||||
logger.log("微信 播放base64音频", audioPath);
|
||||
self._innerAudioContext.src = audioPath;
|
||||
self._innerAudioContext.play(); // 开始播放音频
|
||||
},
|
||||
fail(err) {
|
||||
logger.log("微信 保存本次音频失败", err);
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
//region版本更新检测
|
||||
//微信开发者工具上可以通过「编译模式」下的「下次编译模拟更新」开关来调试
|
||||
qiangzhiUpdata() {
|
||||
const updateManager = window["wx"].getUpdateManager();
|
||||
|
||||
//监听向微信后台请求检查更新结果事件。微信在小程序每次启动(包括热启动)时自动检查更新,不需由开发者主动触发。
|
||||
updateManager.onCheckForUpdate((res) => {
|
||||
// 请求完新版本信息的回调
|
||||
logger.log("微信 检查是否有新版本:", res.hasUpdate);
|
||||
});
|
||||
|
||||
//监听小程序有版本更新事件。客户端主动触发下载(无需开发者触发),下载成功后回调
|
||||
updateManager.onUpdateReady(function () {
|
||||
window["wx"].showModal({
|
||||
title: "更新提示",
|
||||
content: "新版本已经准备好,是否重启应用?",
|
||||
success: function (res) {
|
||||
if (res.confirm) {
|
||||
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
||||
updateManager.applyUpdate();
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
//监听小程序更新失败事件。小程序有新版本,客户端主动触发下载(无需开发者触发),下载失败(可能是网络原因等)时回调
|
||||
updateManager.onUpdateFailed(function (err) {
|
||||
logger.log("微信 新版本下载失败", err);
|
||||
});
|
||||
}
|
||||
|
||||
//客服功能是否支持
|
||||
kefuSupport() {
|
||||
if (window["wx"].openCustomerServiceConversation) {
|
||||
return true;
|
||||
}
|
||||
logger.log("微信 不支持联系客服");
|
||||
return false;
|
||||
}
|
||||
//进入联系客服
|
||||
openKefu() {
|
||||
let wx = window["wx"];
|
||||
if (wx) {
|
||||
if (!wx.openCustomerServiceConversation) {
|
||||
return;
|
||||
}
|
||||
wx.openCustomerServiceConversation({
|
||||
success: (res) => {
|
||||
const { path, query } = res;
|
||||
logger.log("微信 进入客服成功", path, query);
|
||||
},
|
||||
fail: (res) => {
|
||||
logger.log("微信 进入客服失败", res);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//region 播放背景视频
|
||||
private _bgVideo: any = null; //正式播放的视频组件
|
||||
private _bgShow: boolean = false;
|
||||
private curPlayType: VideoRoleType = VideoRoleType.None; //当前播放的视频的类型
|
||||
playBgAudio(
|
||||
remoteUrl: string,
|
||||
vtype: VideoRoleType,
|
||||
loop: boolean = false,
|
||||
extra: any = {}
|
||||
) {
|
||||
if (this._bgVideo && this._bgShow) {
|
||||
this.playBgAudioNext(remoteUrl, vtype, loop, extra);
|
||||
return;
|
||||
}
|
||||
let self = this;
|
||||
logger.log("微信 播放背景视频组件1", remoteUrl);
|
||||
this.curPlayType = vtype;
|
||||
if (!this._bgVideo) {
|
||||
this._bgVideo = this.createVideoHandle();
|
||||
// this._bgVideo.onPlay(() => {
|
||||
// logger.log("微信 背景视频播放开始");
|
||||
// })
|
||||
this._bgVideo.onTimeUpdate((_tinfo: any) => {
|
||||
// logger.log("微信 背景视频播放进度", self._bgShow, _tinfo);
|
||||
if (!self._bgShow) {
|
||||
if (_tinfo && _tinfo.position > 0.01) {
|
||||
logger.log("微信 背景视频1进入视野");
|
||||
self.videoMoveIn(self._bgVideo);
|
||||
self._bgShow = true;
|
||||
self.removeBgAudioNext();
|
||||
Utils.sendInnerMsg(InnerMsgCode.BgVideo_Ready, {});
|
||||
}
|
||||
}
|
||||
});
|
||||
this._bgVideo.onEnded(() => {
|
||||
if (self.doPlayEmoReadyAudio()) {
|
||||
self.setBgAudioPause(self._bgVideo);
|
||||
}
|
||||
Utils.sendInnerMsg(InnerMsgCode.BgVideo_End, {});
|
||||
});
|
||||
}
|
||||
this._bgVideo.src = remoteUrl; //视频的地址
|
||||
this._bgVideo.loop = loop; //循环播放
|
||||
this._bgVideo.play();
|
||||
}
|
||||
removeBgAudio() {
|
||||
this._bgShow = false;
|
||||
if (this._bgVideo) {
|
||||
this._bgVideo.stop();
|
||||
this.videoMoveOut(this._bgVideo);
|
||||
}
|
||||
}
|
||||
//播放下一个视频,先加载,播放后再转到正式组件上
|
||||
private _bgTempVideo: any = null; //临时视频组件,等加载完成
|
||||
private _bgTempShow: boolean = false;
|
||||
playBgAudioNext(
|
||||
remoteUrl: string,
|
||||
vtype: VideoRoleType,
|
||||
loop: boolean = false,
|
||||
extra: any = {}
|
||||
) {
|
||||
this.removeBgAudioNext();
|
||||
logger.log("微信 创建背景视频组件2--->", remoteUrl);
|
||||
this.curPlayType = vtype;
|
||||
let self = this;
|
||||
if (!this._bgTempVideo) {
|
||||
this._bgTempVideo = this.createVideoHandle();
|
||||
// this._bgTempVideo.onPlay(() => {
|
||||
// logger.log("微信 临时背景视频播放开始");
|
||||
// })
|
||||
this._bgTempVideo.onTimeUpdate((_tinfo: any) => {
|
||||
// logger.log("微信 临时背景视频播放进度", self._bgTempShow, _tinfo);
|
||||
if (!self._bgTempShow) {
|
||||
if (_tinfo && _tinfo.position > 0.01) {
|
||||
logger.log("微信 背景视频2进入视野");
|
||||
self._bgTempShow = true;
|
||||
self.videoMoveIn(self._bgTempVideo);
|
||||
self.removeBgAudio();
|
||||
Utils.sendInnerMsg(InnerMsgCode.BgVideo_Ready, {});
|
||||
}
|
||||
}
|
||||
});
|
||||
this._bgTempVideo.onEnded(() => {
|
||||
if (self.doPlayEmoReadyAudio()) {
|
||||
self.setBgAudioPause(self._bgTempVideo);
|
||||
}
|
||||
Utils.sendInnerMsg(InnerMsgCode.BgVideo_End, {});
|
||||
});
|
||||
}
|
||||
this._bgTempVideo.src = remoteUrl; //视频的地址
|
||||
this._bgTempVideo.loop = loop; //循环播放
|
||||
this._bgTempVideo.play();
|
||||
}
|
||||
removeBgAudioNext() {
|
||||
this._bgTempShow = false;
|
||||
if (this._bgTempVideo) {
|
||||
this._bgTempVideo.stop();
|
||||
this.videoMoveOut(this._bgTempVideo);
|
||||
}
|
||||
}
|
||||
|
||||
//region 播放emo视频
|
||||
private _emoVideo: any = null; //正式播放的视频组件
|
||||
private _emoShow: boolean = false;
|
||||
addEmoAudio(
|
||||
remoteUrl: string,
|
||||
vtype: VideoRoleType,
|
||||
loop: boolean = false,
|
||||
extra: any = {}
|
||||
) {
|
||||
if (this._emoVideo && this._emoShow) {
|
||||
this.playEmoAudioNext(remoteUrl, vtype, loop, extra);
|
||||
return;
|
||||
}
|
||||
let self = this;
|
||||
logger.log("微信 播放emo视频1", remoteUrl);
|
||||
this.curPlayType = vtype;
|
||||
if (!this._emoVideo) {
|
||||
this._emoVideo = this.createVideoHandle();
|
||||
// this._emoVideo.onPlay(() => {
|
||||
// logger.log("微信 背景视频播放开始");
|
||||
// })
|
||||
this._emoVideo.onTimeUpdate((_tinfo: any) => {
|
||||
// logger.log("微信 背景视频播放进度", self._emoShow, _tinfo);
|
||||
if (!self._emoShow) {
|
||||
if (_tinfo && _tinfo.position > 0.01) {
|
||||
logger.log("微信 emo视频1准备好了");
|
||||
self._emoShow = true;
|
||||
self.removeEmoAudioNext();
|
||||
self.setEmoReadyAudio(self._emoVideo);
|
||||
if (self.curPlayType == VideoRoleType.emo) {
|
||||
self.doPlayEmoReadyAudio();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
this._emoVideo.onEnded(() => {
|
||||
self.doEmoFinish();
|
||||
});
|
||||
}
|
||||
this._emoVideo.src = remoteUrl; //视频的地址
|
||||
this._emoVideo.loop = loop; //循环播放
|
||||
this._emoVideo.play();
|
||||
}
|
||||
removeEmoAudio() {
|
||||
this._emoShow = false;
|
||||
if (this._emoVideo) {
|
||||
this._emoVideo.stop();
|
||||
this.videoMoveOut(this._emoVideo);
|
||||
}
|
||||
}
|
||||
//播放下一个视频,先加载,播放后再转到正式组件上
|
||||
private _emoTempVideo: any = null; //临时视频组件,等加载完成
|
||||
private _emoTempShow: boolean = false;
|
||||
playEmoAudioNext(
|
||||
remoteUrl: string,
|
||||
vtype: VideoRoleType,
|
||||
loop: boolean = false,
|
||||
extra: any = {}
|
||||
) {
|
||||
this.removeEmoAudioNext();
|
||||
logger.log("微信 播放emo视频2--->", remoteUrl);
|
||||
this.curPlayType = vtype;
|
||||
let self = this;
|
||||
if (!this._emoTempVideo) {
|
||||
this._emoTempVideo = this.createVideoHandle();
|
||||
// this._emoTempVideo.onPlay(() => {
|
||||
// logger.log("微信 临时背景视频播放开始");
|
||||
// })
|
||||
this._emoTempVideo.onTimeUpdate((_tinfo: any) => {
|
||||
// logger.log("微信 临时背景视频播放进度", self._emoTempShow, _tinfo);
|
||||
if (!self._emoTempShow) {
|
||||
if (_tinfo && _tinfo.position > 0.01) {
|
||||
logger.log("微信 emo视频2已准备好");
|
||||
self._emoTempShow = true;
|
||||
self.removeEmoAudio();
|
||||
self.setEmoReadyAudio(self._emoTempVideo);
|
||||
if (self.curPlayType == VideoRoleType.emo) {
|
||||
self.doPlayEmoReadyAudio();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
this._emoTempVideo.onEnded(() => {
|
||||
self.doEmoFinish();
|
||||
});
|
||||
}
|
||||
this._emoTempVideo.src = remoteUrl; //视频的地址
|
||||
this._emoTempVideo.loop = loop; //循环播放
|
||||
this._emoTempVideo.play();
|
||||
}
|
||||
removeEmoAudioNext() {
|
||||
this._emoTempShow = false;
|
||||
if (this._emoTempVideo) {
|
||||
this._emoTempVideo.stop();
|
||||
this.videoMoveOut(this._emoTempVideo);
|
||||
}
|
||||
}
|
||||
|
||||
//视频移入屏幕
|
||||
private videoMoveIn(video: any) {
|
||||
let adainfo = this.getVideoAdaInfo();
|
||||
video.x = adainfo.x;
|
||||
video.y = adainfo.y;
|
||||
}
|
||||
//视频移出屏幕
|
||||
private videoMoveOut(video: any) {
|
||||
video.x = 10000;
|
||||
video.y = 10000;
|
||||
}
|
||||
/**创建一个视频播放器 */
|
||||
private createVideoHandle() {
|
||||
let size = this.getWindowSize();
|
||||
let adainfo = this.getVideoAdaInfo();
|
||||
let bgVideo = window["wx"].createVideo({
|
||||
// src: remoteUrl, //视频的地址
|
||||
x: size.width, //先在屏幕外创建,等加载完成后再移动到屏幕上
|
||||
y: size.height,
|
||||
width: this.videoWidth * adainfo.scale, //视频的宽度
|
||||
height: this.videoHeight * adainfo.scale, //视频的高度
|
||||
autoplay: true, //自动播放
|
||||
// loop: loop, //循环播放
|
||||
controls: false, //是否显示控件
|
||||
showProgress: false, //显示进度条
|
||||
showProgressInControlMode: false, //在控制模式下显示进度条
|
||||
enableProgressGesture: false, //是否启用进度手势
|
||||
showCenterPlayBtn: false, //是否显示中间的播放按钮
|
||||
underGameView: true, //视频是否显示在游戏画布之下。需要设置Camera的Clear Color为透明色
|
||||
// backgroundColor: "#00000000", //视频背景颜色
|
||||
objectFit: "fill", //视频的填充模式
|
||||
});
|
||||
return bgVideo;
|
||||
}
|
||||
//获取视频适配信息
|
||||
private videoWidth = 720;
|
||||
private videoHeight = 1280;
|
||||
private videoAdaInfo = null;
|
||||
private getVideoAdaInfo() {
|
||||
if (this.videoAdaInfo) return this.videoAdaInfo;
|
||||
this.videoAdaInfo = {
|
||||
x: 0,
|
||||
y: 0,
|
||||
scale: 1,
|
||||
};
|
||||
let size = this.getWindowSize();
|
||||
let ratiow = size.width / this.videoWidth; //屏幕和视频的宽高比,谁大用谁
|
||||
let ratioh = size.height / this.videoHeight;
|
||||
if (ratiow > ratioh) {
|
||||
this.videoAdaInfo.scale = ratiow;
|
||||
this.videoAdaInfo.x = 0;
|
||||
this.videoAdaInfo.y = -(this.videoHeight * ratiow - size.height) / 2;
|
||||
} else {
|
||||
this.videoAdaInfo.scale = ratioh;
|
||||
this.videoAdaInfo.x = -(this.videoWidth * ratioh - size.width) / 2;
|
||||
this.videoAdaInfo.y = 0;
|
||||
}
|
||||
logger.log("微信 视频适配信息", this.videoAdaInfo, size);
|
||||
return this.videoAdaInfo;
|
||||
}
|
||||
|
||||
//设置暂停播放的主视频
|
||||
private vpWait: any = null;
|
||||
setBgAudioPause(wait: any) {
|
||||
logger.log("微信 主视频暂停播放");
|
||||
this.vpWait = wait;
|
||||
this.vpWait.pause();
|
||||
}
|
||||
replayBgAudioPause() {
|
||||
logger.log("微信 主视频继续播放");
|
||||
if (this.vpWait) {
|
||||
this.vpWait.play();
|
||||
}
|
||||
}
|
||||
|
||||
//设置准备好要播放的表情视频
|
||||
private emoReady: any = null;
|
||||
setEmoReadyAudio(au: any) {
|
||||
logger.log("微信 设置emo ready视频");
|
||||
if (this.emoReady) {
|
||||
this.emoReady.stop();
|
||||
this.videoMoveOut(this.emoReady);
|
||||
}
|
||||
this.emoReady = au;
|
||||
this.emoReady.pause();
|
||||
}
|
||||
//移除准备好要播放的表情视频
|
||||
removeEmoReadyAudio() {
|
||||
logger.log("微信 移除emo ready视频");
|
||||
if (this.emoReady) {
|
||||
this.emoReady.stop();
|
||||
this.videoMoveOut(this.emoReady);
|
||||
}
|
||||
this.emoReady = null;
|
||||
}
|
||||
//播放准备好要播放的表情视频
|
||||
doPlayEmoReadyAudio(): boolean {
|
||||
if (this.emoReady) {
|
||||
logger.log("微信 播放emo ready视频");
|
||||
this.emoReady.play();
|
||||
this.videoMoveIn(this.emoReady);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
//表情视频播放结束
|
||||
doEmoFinish() {
|
||||
logger.log("微信emo ready视频播放结束");
|
||||
this.removeEmoReadyAudio();
|
||||
this.replayBgAudioPause();
|
||||
}
|
||||
|
||||
//region 微信同声传译
|
||||
// private rrmgr: any = null;
|
||||
// startRecordRecognition() {
|
||||
// logger.log("微信 同声传译111")
|
||||
// if (!this.rrmgr) {
|
||||
// const plugin = requirePlugin("WechatSI");
|
||||
// this.rrmgr = plugin.getRecordRecognitionManager();
|
||||
// logger.log("微信 同声传译222")
|
||||
|
||||
// // 监听识别结果
|
||||
// this.rrmgr.onRecognize = (res) => {
|
||||
// logger.log("微信 同声传译识别结果:", res.result);
|
||||
// };
|
||||
|
||||
// // 监听录音结束
|
||||
// this.rrmgr.onStop = (res) => {
|
||||
// logger.log("微信 同声传译录音结束", res);
|
||||
// };
|
||||
// }
|
||||
// this.rrmgr.start({ lang: "zh_CN" });
|
||||
// logger.log("微信 同声传译333")
|
||||
// }
|
||||
// stopRecordRecognition() {
|
||||
// if (this.rrmgr) {
|
||||
// this.rrmgr.stop();
|
||||
// logger.log("微信 同声传译444")
|
||||
// }
|
||||
// }
|
||||
|
||||
//region 复制到剪贴板
|
||||
/**复制文本到剪贴板 */
|
||||
copyToClipboard(text: string, cb?: Function) {
|
||||
logger.log("微信 复制到剪贴板:", text);
|
||||
window["wx"].setClipboardData({
|
||||
data: text,
|
||||
success: () => {
|
||||
logger.log("微信 复制成功");
|
||||
cb && cb(true);
|
||||
},
|
||||
fail: (err) => {
|
||||
logger.log("微信 复制失败:", err);
|
||||
cb && cb(false);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
//region 友盟+
|
||||
//初始化友盟+
|
||||
umaInit() {
|
||||
// window["wx"].uma.init({
|
||||
// appKey: "67c969b99a16fe6dcd5bfec5",
|
||||
// useOpenid: true, // default true
|
||||
// autoGetOpenid: true,
|
||||
// debug: true,
|
||||
// uploadUserInfo: true, // 上传用户信息,上传后可以看到有用户头像和昵称的分享信息
|
||||
// });
|
||||
// logger.log("微信 uma 初始化");
|
||||
}
|
||||
//友盟统计是否开启
|
||||
umaSwt() {
|
||||
return true;
|
||||
}
|
||||
//友盟事件统计
|
||||
umaEvent(eventName: string, value: any = {}) {
|
||||
window["wx"].uma.trackEvent(eventName, value);
|
||||
logger.log("微信 uma 统计:", eventName, value);
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
{"ver":"4.0.24","importer":"typescript","imported":true,"uuid":"0c025735-16d4-4eb8-adc9-5fdfccf35794","files":[],"subMetas":{},"userData":{}}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "dc10aeea-668d-4ee8-85e1-44b0d50eab01",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { IPlatformSDK } from "../core/IPlatformSDK";
|
||||
|
||||
export class WxPlatformSDK implements IPlatformSDK {
|
||||
init(cb?: Function): void {
|
||||
console.log("微信平台初始化");
|
||||
cb && cb();
|
||||
}
|
||||
|
||||
// 登录
|
||||
login(cb?: Function): void {
|
||||
console.log("调用微信登录");
|
||||
cb && cb({ code: "wx-code" });
|
||||
}
|
||||
|
||||
// 获取用户信息
|
||||
getUserInfo(cb: (info: { nickName: string; avatarUrl: string }) => void): void {
|
||||
cb({ nickName: "小明", avatarUrl: "avatar.png" });
|
||||
}
|
||||
|
||||
// 检查平台权限
|
||||
checkPermission(scope: string, cb: (granted: boolean) => void): void {
|
||||
cb(true);
|
||||
}
|
||||
|
||||
// 复制文本到剪贴板
|
||||
copyToClipboard(text: string, cb?: Function): void {
|
||||
|
||||
}
|
||||
|
||||
// 客服功能是否可用
|
||||
kefuSupport(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 打开客服会话
|
||||
openKefu(): void {
|
||||
|
||||
}
|
||||
|
||||
// 获取设备分辨率
|
||||
getWindowSize(): { width: number, height: number } {
|
||||
return {width: 720, height: 1280};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "1cc51f5b-df3a-4ac7-b10e-52132843eb22",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "acf83fdd-385c-4a39-9f24-d77052efea5c",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { IWalletSDK } from "../core/IWalletSDK";
|
||||
|
||||
export class LuffaWalletSDK implements IWalletSDK {
|
||||
private address: string | null = null;
|
||||
|
||||
init(cb?: Function): void {
|
||||
console.log("Luffa 钱包初始化");
|
||||
cb && cb();
|
||||
}
|
||||
|
||||
connect(cb: (address: string, publicKey?: string) => void): void {
|
||||
console.log("连接 Luffa 钱包");
|
||||
this.address = "0x123456"; // 模拟地址
|
||||
cb(this.address, "public-key");
|
||||
}
|
||||
|
||||
disconnect(): void {
|
||||
this.address = null;
|
||||
}
|
||||
|
||||
getWalletAddress(): string | null {
|
||||
return this.address;
|
||||
}
|
||||
|
||||
async signMessage(message: string, nonce: number): Promise<any> {
|
||||
console.log("调用 Luffa 单签签名");
|
||||
return { signature: "xxx", fullMessage: `${message}-${nonce}` };
|
||||
}
|
||||
|
||||
async buildTransaction(payload: any): Promise<any> {
|
||||
console.log("构建交易", payload);
|
||||
return { raw: "rawTx" };
|
||||
}
|
||||
|
||||
async signTransaction(rawData: any): Promise<any> {
|
||||
console.log("签名交易", rawData);
|
||||
return { signed: "signedTx" };
|
||||
}
|
||||
|
||||
async sendTransaction(signed: any): Promise<{ hash: string }> {
|
||||
console.log("发送交易", signed);
|
||||
return { hash: "0xabcdef" };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "aaa01f0f-e74c-48a2-85ed-da571f0c2643",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -1,387 +0,0 @@
|
||||
import { VideoPlayer, Node, director, Component, isValid } from "cc";
|
||||
import HttpUnit from "../Common/HttpUnit";
|
||||
import { SDKManager } from "./SDKManager";
|
||||
import { SceneBgVideoLayer } from "../../Sub/UI/SceneBgVideoLayer";
|
||||
import { BgVideo } from "./BgVideo";
|
||||
import Utils from "../Common/Utils";
|
||||
import { InnerMsgCode } from "../Config/InnerMsgCode";
|
||||
import { VideoRoleType } from "../Common/GlobalValue";
|
||||
import { logger } from "db://assets/Scripts/Main/Common/Logger";
|
||||
|
||||
export class WebSDK {
|
||||
//初始化
|
||||
init(cb: Function = null) {
|
||||
logger.log("init webSDK");
|
||||
cb && cb();
|
||||
}
|
||||
|
||||
//检查权限
|
||||
checkAutoSetting(autoKey: string, cb: Function = null) {
|
||||
cb && cb(true);
|
||||
}
|
||||
|
||||
//获取用户信息
|
||||
getUserInfo(cb: Function = null) {
|
||||
let name = HttpUnit.GetNickName();
|
||||
cb &&
|
||||
cb({
|
||||
nickName: name,
|
||||
avatarUrl: "https://hxzgame.vip.hnhxzkj.com/lzx/XiangQin/webHead.png",
|
||||
});
|
||||
}
|
||||
|
||||
//region 登录
|
||||
login(cb: Function = null) {
|
||||
cb && cb({ platform: 2, code: null });
|
||||
}
|
||||
|
||||
//显示视频广告
|
||||
show_video(callback: Function, tag: number) {
|
||||
callback && callback({ code: 0, tag: tag });
|
||||
SDKManager.video_ad_back();
|
||||
}
|
||||
|
||||
//显示插屏
|
||||
show_splash() {}
|
||||
|
||||
//显示Banner
|
||||
show_banner(...args) {}
|
||||
|
||||
//隐藏Banner
|
||||
hide_banner(...args) {}
|
||||
|
||||
//主动拉起分享
|
||||
show_share(rewardCB?: Function) {
|
||||
rewardCB && rewardCB();
|
||||
}
|
||||
|
||||
//获取设备分辨率
|
||||
getWindowSize() {
|
||||
return { width: screen.width, height: screen.height };
|
||||
}
|
||||
|
||||
//显示游戏圈
|
||||
show_gameClub(leftRatio, topRatio, widthRatio, heightRatio) {}
|
||||
//隐藏游戏圈
|
||||
hide_gameClub() {}
|
||||
|
||||
//检查是否支持base64音频播放
|
||||
checkSupportBase64Audio() {
|
||||
return true;
|
||||
}
|
||||
//播放base64音频
|
||||
private _audioInst: HTMLAudioElement = null;
|
||||
playBase64Audio(base64: string, loop: boolean) {
|
||||
let substring = base64;
|
||||
let qianzhui = "data:audio/x-wav;base64,";
|
||||
if (base64.startsWith(qianzhui)) {
|
||||
substring = base64.substring(qianzhui.length, base64.length);
|
||||
}
|
||||
|
||||
// 解码 Base64 字符串为二进制数据
|
||||
const binaryData = atob(substring);
|
||||
|
||||
// 创建一个包含二进制数据的 Uint8Array
|
||||
const byteArray = new Uint8Array(binaryData.length);
|
||||
for (let i = 0; i < binaryData.length; i++) {
|
||||
byteArray[i] = binaryData.charCodeAt(i);
|
||||
}
|
||||
|
||||
// 创建 Blob 对象,指定 MIME 类型为音频格式(例如 mp3)
|
||||
const audioBlob = new Blob([byteArray], { type: "audio/mp3" });
|
||||
|
||||
// 创建音频 URL
|
||||
const audioUrl = URL.createObjectURL(audioBlob);
|
||||
|
||||
logger.log("web 播放base64音频", audioUrl);
|
||||
// 创建音频元素并播放
|
||||
if (this._audioInst == null) {
|
||||
this._audioInst = new Audio(audioUrl);
|
||||
} else {
|
||||
this._audioInst.src = audioUrl;
|
||||
}
|
||||
this._audioInst.play();
|
||||
}
|
||||
|
||||
//客服功能是否支持
|
||||
kefuSupport() {
|
||||
logger.log("web 不支持联系客服");
|
||||
return false;
|
||||
}
|
||||
//进入联系客服
|
||||
openKefu() {
|
||||
logger.log("web 进入联系客服");
|
||||
}
|
||||
|
||||
//region 播放主背景视频
|
||||
private zhuVideo1: BgVideo | null = null;
|
||||
private zhuExtra1: any = null;
|
||||
playBgAudio(
|
||||
remoteUrl: string,
|
||||
vtype: VideoRoleType,
|
||||
loop: boolean = false,
|
||||
extra: any = {}
|
||||
) {
|
||||
let bgvideo = SceneBgVideoLayer.handle;
|
||||
if (!bgvideo) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.initBgAudio();
|
||||
if (this.zhuVideo1 && this.zhuVideo1.isPlaying) {
|
||||
this.playBgAudioNext(remoteUrl, vtype, loop, extra);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.zhuVideo1) {
|
||||
this.zhuVideo1 = bgvideo.getVideoClone();
|
||||
}
|
||||
this.zhuExtra1 = extra;
|
||||
this.zhuVideo1.vtype = vtype;
|
||||
this.zhuVideo1.cbReady = this.audioReady.bind(this);
|
||||
this.zhuVideo1.cbEnd = this.audioEnded.bind(this);
|
||||
this.zhuVideo1.playVideo(remoteUrl, loop, false);
|
||||
}
|
||||
initBgAudio() {
|
||||
let bgvideo = SceneBgVideoLayer.handle;
|
||||
if (!bgvideo) {
|
||||
return;
|
||||
}
|
||||
|
||||
logger.log("web 初始化主背景视频");
|
||||
if (!this.zhuVideo1) {
|
||||
this.zhuVideo1 = bgvideo.getVideoClone();
|
||||
this.zhuVideo1.remoteUrl =
|
||||
"http://hxzgame.vip.hnhxzkj.com/lzx/XiangQin/bginited.mp4";
|
||||
}
|
||||
if (!this.zhuVideo2) {
|
||||
this.zhuVideo2 = bgvideo.getVideoClone();
|
||||
this.zhuVideo2.remoteUrl =
|
||||
"http://hxzgame.vip.hnhxzkj.com/lzx/XiangQin/bginited.mp4";
|
||||
}
|
||||
if (!this.emoVideo1) {
|
||||
this.emoVideo1 = bgvideo.getVideoClone();
|
||||
this.emoVideo1.remoteUrl =
|
||||
"http://hxzgame.vip.hnhxzkj.com/lzx/XiangQin/bginited.mp4";
|
||||
}
|
||||
if (!this.emoVideo2) {
|
||||
this.emoVideo2 = bgvideo.getVideoClone();
|
||||
this.emoVideo2.remoteUrl =
|
||||
"http://hxzgame.vip.hnhxzkj.com/lzx/XiangQin/bginited.mp4";
|
||||
}
|
||||
}
|
||||
audioReady() {
|
||||
this.removeBgAudioNext();
|
||||
this.zhuVideo1.moveIn();
|
||||
Utils.sendInnerMsg(InnerMsgCode.BgVideo_Ready, {
|
||||
compo: this.zhuVideo1,
|
||||
extra: this.zhuExtra1,
|
||||
});
|
||||
}
|
||||
audioEnded() {
|
||||
Utils.sendInnerMsg(InnerMsgCode.BgVideo_End, {
|
||||
compo: this.zhuVideo1,
|
||||
extra: this.zhuExtra1,
|
||||
});
|
||||
}
|
||||
removeBgAudio() {
|
||||
if (this.zhuVideo1 && this.zhuVideo1.isPlaying) {
|
||||
this.zhuVideo1.recycleVideo();
|
||||
}
|
||||
}
|
||||
//主背景临时视频
|
||||
private zhuVideo2: BgVideo | null = null;
|
||||
private zhuExtra2: any = null;
|
||||
playBgAudioNext(
|
||||
remoteUrl: string,
|
||||
vtype: VideoRoleType,
|
||||
loop: boolean = false,
|
||||
extra: any = {}
|
||||
) {
|
||||
let bgvideo = SceneBgVideoLayer.handle;
|
||||
if (!bgvideo) {
|
||||
return;
|
||||
}
|
||||
this.removeBgAudioNext();
|
||||
if (!this.zhuVideo2) {
|
||||
this.zhuVideo2 = bgvideo.getVideoClone();
|
||||
}
|
||||
this.zhuExtra2 = extra;
|
||||
this.zhuVideo2.vtype = vtype;
|
||||
this.zhuVideo2.cbReady = this.audioNextReady.bind(this);
|
||||
this.zhuVideo2.cbEnd = this.audioNextEnded.bind(this);
|
||||
this.zhuVideo2.playVideo(remoteUrl, loop, false);
|
||||
}
|
||||
audioNextReady() {
|
||||
this.removeBgAudio();
|
||||
this.zhuVideo2.moveIn();
|
||||
Utils.sendInnerMsg(InnerMsgCode.BgVideo_Ready, {
|
||||
compo: this.zhuVideo2,
|
||||
extra: this.zhuExtra2,
|
||||
});
|
||||
}
|
||||
audioNextEnded() {
|
||||
Utils.sendInnerMsg(InnerMsgCode.BgVideo_End, {
|
||||
compo: this.zhuVideo2,
|
||||
extra: this.zhuExtra2,
|
||||
});
|
||||
}
|
||||
removeBgAudioNext() {
|
||||
if (this.zhuVideo2 && this.zhuVideo2.isPlaying) {
|
||||
this.zhuVideo2.recycleVideo();
|
||||
}
|
||||
}
|
||||
|
||||
//region 播放emo视频
|
||||
private emoVideo1: BgVideo | null = null;
|
||||
private emoExtra1: any = {};
|
||||
addEmoAudio(
|
||||
remoteUrl: string,
|
||||
vtype: VideoRoleType,
|
||||
loop: boolean = false,
|
||||
extra: any = {}
|
||||
) {
|
||||
let bgvideo = SceneBgVideoLayer.handle;
|
||||
if (!bgvideo) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.emoVideo1 && this.emoVideo1.isPlaying) {
|
||||
this.playEmoAudioNext(remoteUrl, vtype, loop, extra);
|
||||
return;
|
||||
// this.emoVideo1.recycleVideo();
|
||||
}
|
||||
|
||||
if (!this.emoVideo1 || !isValid(this.emoVideo1.node)) {
|
||||
this.emoVideo1 = bgvideo.getVideoClone();
|
||||
}
|
||||
this.emoExtra1 = extra;
|
||||
this.emoVideo1.vtype = vtype;
|
||||
this.emoVideo1.cbReady = this.emoReady.bind(this);
|
||||
this.emoVideo1.cbEnd = this.emoEnded.bind(this);
|
||||
this.emoVideo1.playVideo(remoteUrl, loop, false);
|
||||
}
|
||||
emoReady() {
|
||||
this.removeEmoNextAudio();
|
||||
Utils.sendInnerMsg(InnerMsgCode.BgVideo_Ready, {
|
||||
compo: this.emoVideo1,
|
||||
extra: this.emoExtra1,
|
||||
});
|
||||
}
|
||||
emoEnded() {
|
||||
Utils.sendInnerMsg(InnerMsgCode.BgVideo_End, {
|
||||
compo: this.emoVideo1,
|
||||
extra: this.emoExtra1,
|
||||
});
|
||||
}
|
||||
removeEmoAudio() {
|
||||
if (this.emoVideo1 && this.emoVideo1.isPlaying) {
|
||||
this.emoVideo1.recycleVideo();
|
||||
}
|
||||
}
|
||||
// 播放emo临时视频
|
||||
private emoVideo2: BgVideo | null = null;
|
||||
private emoExtra2: any = {};
|
||||
playEmoAudioNext(
|
||||
remoteUrl: string,
|
||||
vtype: VideoRoleType,
|
||||
loop: boolean = false,
|
||||
extra: any = {}
|
||||
) {
|
||||
let bgvideo = SceneBgVideoLayer.handle;
|
||||
if (!bgvideo) {
|
||||
return;
|
||||
}
|
||||
this.removeEmoNextAudio();
|
||||
if (!this.emoVideo2) {
|
||||
this.emoVideo2 = bgvideo.getVideoClone();
|
||||
}
|
||||
this.emoExtra2 = extra;
|
||||
this.emoVideo2.vtype = vtype;
|
||||
this.emoVideo2.cbReady = this.emoNextReady.bind(this);
|
||||
this.emoVideo2.cbEnd = this.emoNextEnded.bind(this);
|
||||
this.emoVideo2.playVideo(remoteUrl, loop, false);
|
||||
}
|
||||
emoNextReady() {
|
||||
this.removeEmoAudio();
|
||||
Utils.sendInnerMsg(InnerMsgCode.BgVideo_Ready, {
|
||||
compo: this.emoVideo2,
|
||||
extra: this.emoExtra2,
|
||||
});
|
||||
}
|
||||
emoNextEnded() {
|
||||
Utils.sendInnerMsg(InnerMsgCode.BgVideo_End, {
|
||||
compo: this.emoVideo2,
|
||||
extra: this.emoExtra2,
|
||||
});
|
||||
}
|
||||
removeEmoNextAudio() {
|
||||
if (this.emoVideo2 && this.emoVideo2.isPlaying) {
|
||||
this.emoVideo2.recycleVideo();
|
||||
}
|
||||
}
|
||||
|
||||
//region 复制到剪贴板
|
||||
/**复制文本到剪贴板 */
|
||||
copyToClipboard(text: string, cb?: Function) {
|
||||
logger.log("web 复制到剪贴板:", text);
|
||||
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
// 使用现代的 Clipboard API
|
||||
navigator.clipboard
|
||||
.writeText(text)
|
||||
.then(() => {
|
||||
logger.log("web 复制成功 (Clipboard API)");
|
||||
cb && cb(true);
|
||||
})
|
||||
.catch((err) => {
|
||||
logger.log("web 复制失败 (Clipboard API):", err);
|
||||
this.fallbackCopyToClipboard(text, cb);
|
||||
});
|
||||
} else {
|
||||
// 使用兼容性方案
|
||||
this.fallbackCopyToClipboard(text, cb);
|
||||
}
|
||||
}
|
||||
|
||||
/**兼容性复制方案 */
|
||||
private fallbackCopyToClipboard(text: string, cb?: Function) {
|
||||
const textArea = document.createElement("textarea");
|
||||
textArea.value = text;
|
||||
|
||||
// 避免滚动到底部
|
||||
textArea.style.top = "0";
|
||||
textArea.style.left = "0";
|
||||
textArea.style.position = "fixed";
|
||||
textArea.style.opacity = "0";
|
||||
|
||||
document.body.appendChild(textArea);
|
||||
textArea.focus();
|
||||
textArea.select();
|
||||
|
||||
try {
|
||||
const successful = document.execCommand("copy");
|
||||
if (successful) {
|
||||
logger.log("web 复制成功 (fallback)");
|
||||
cb && cb(true);
|
||||
} else {
|
||||
logger.log("web 复制失败 (fallback)");
|
||||
cb && cb(false);
|
||||
}
|
||||
} catch (err) {
|
||||
logger.log("web 复制异常 (fallback):", err);
|
||||
cb && cb(false);
|
||||
}
|
||||
|
||||
document.body.removeChild(textArea);
|
||||
}
|
||||
|
||||
//region 友盟+
|
||||
umaInit() {}
|
||||
//友盟统计是否开启
|
||||
umaSwt() {
|
||||
return false;
|
||||
}
|
||||
//友盟事件统计
|
||||
umaEvent(eventName: string, value: any = {}) {}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "bf263997-b1ef-4d36-9101-f8b4dc56c800",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e281b3a8-afd6-4850-8742-07d84d1be980",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -269,9 +269,9 @@ export default class HttpUnit {
|
||||
private loginCB: Function = null;
|
||||
public login(cb: Function = null) {
|
||||
this.loginCB = cb;
|
||||
SDKManager.login((_loginData) => {
|
||||
SDKManager.I.login((_loginData) => {
|
||||
logger.log("SDK登录成功", _loginData)
|
||||
SDKManager.getUserInfo((userInfo) => {
|
||||
SDKManager.I.getUserInfo((userInfo) => {
|
||||
logger.log("SDK获取用户信息成功", userInfo)
|
||||
// let serparam = {
|
||||
// platform: _loginData.platform,
|
||||
|
||||
@@ -120,24 +120,24 @@ export default class GameManager {
|
||||
}
|
||||
}
|
||||
//友盟记录关卡
|
||||
if (umRecords.length > 0 && SDKManager.umaSwt()){
|
||||
let umr = umRecords.join(',')
|
||||
HttpUnit.ins.sendLevelRecord({level_ids:umr}, (_data)=>{
|
||||
logger.log('友盟记录关卡',_data)
|
||||
let userId = HttpUnit.GetID()
|
||||
let curDate = Utils.GetNowFormatDay()
|
||||
for (let i = 0; i < umRecords.length; i++) {
|
||||
let lvId = umRecords[i]
|
||||
let _cfg = GameManager._levelCfgMap[lvId]
|
||||
SDKManager.umaEvent(SDKManager.Uma_Event_LvUnlock, {
|
||||
lvId: lvId,
|
||||
userId: userId,
|
||||
time: curDate,
|
||||
type: _cfg.unlock_type
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
// if (umRecords.length > 0 && SDKManager.I.umaSwt()){
|
||||
// let umr = umRecords.join(',')
|
||||
// HttpUnit.ins.sendLevelRecord({level_ids:umr}, (_data)=>{
|
||||
// logger.log('友盟记录关卡',_data)
|
||||
// let userId = HttpUnit.GetID()
|
||||
// let curDate = Utils.GetNowFormatDay()
|
||||
// for (let i = 0; i < umRecords.length; i++) {
|
||||
// let lvId = umRecords[i]
|
||||
// let _cfg = GameManager._levelCfgMap[lvId]
|
||||
// SDKManager.I.umaEvent(SDKManager.Uma_Event_LvUnlock, {
|
||||
// lvId: lvId,
|
||||
// userId: userId,
|
||||
// time: curDate,
|
||||
// type: _cfg.unlock_type
|
||||
// })
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
}
|
||||
/**设置关卡星级 */
|
||||
public static SetLevelStar(levelId: string, star: number) {
|
||||
|
||||
@@ -10,7 +10,6 @@ const { ccclass, property } = _decorator;
|
||||
export class GameEntry extends Component {
|
||||
start() {
|
||||
game.frameRate = 30; //游戏帧率
|
||||
SDKManager.I.initEmpty()
|
||||
PlayerDataManager.I.initEmpty()
|
||||
|
||||
assetManager.downloader.maxConcurrency = 20;
|
||||
|
||||
@@ -115,7 +115,7 @@ export class PreloadUI extends Component {
|
||||
|
||||
AudioManager.I.PlayMusic(Config18x.AudioConfig.MainBGM);
|
||||
|
||||
SDKManager.init();
|
||||
SDKManager.I.init();
|
||||
|
||||
this.preloadFiles();
|
||||
|
||||
|
||||
@@ -232,7 +232,7 @@ export class Web3PopPanel extends li_BaseView {
|
||||
onClickCopy() {
|
||||
const stringToCopy = this.address.string;
|
||||
|
||||
SDKManager.copyToClipboard(stringToCopy, (success: boolean) => {
|
||||
SDKManager.I.copyToClipboard(stringToCopy, (success: boolean) => {
|
||||
if (success) {
|
||||
TipsPanel.show("地址已复制到剪贴板");
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user