init
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "7f5d94a8-3fd8-4940-b9b4-0fc4544a6984",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
import { _decorator, Component, Node, tween, UIOpacity, Vec3, VideoPlayer } from 'cc';
|
||||
import Utils from '../Common/Utils';
|
||||
import { VideoRoleType } from '../Common/GlobalValue';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/**背景视频 */
|
||||
@ccclass('BgVideo')
|
||||
export class BgVideo extends Component {
|
||||
|
||||
private vp: VideoPlayer = null!;
|
||||
|
||||
private _isPlaying: boolean = false;
|
||||
public get isPlaying(): boolean {
|
||||
return this._isPlaying;
|
||||
}
|
||||
|
||||
private _vtype: VideoRoleType = VideoRoleType.None;
|
||||
public get vtype(): VideoRoleType {
|
||||
return this._vtype;
|
||||
}
|
||||
public set vtype(v: VideoRoleType) {
|
||||
this._vtype = v;
|
||||
}
|
||||
|
||||
private _remoteUrl: string = '';
|
||||
public set remoteUrl(url: string) {
|
||||
this._remoteUrl = url;
|
||||
this.vp.remoteURL = url;
|
||||
}
|
||||
|
||||
private _cbReady: Function | undefined = null;
|
||||
public set cbReady(cb: Function | undefined) {
|
||||
this._cbReady = cb;
|
||||
}
|
||||
|
||||
private _cbEnd: Function | undefined = null;
|
||||
public set cbEnd(cb: Function | undefined) {
|
||||
this._cbEnd = cb;
|
||||
}
|
||||
|
||||
protected onLoad(): void {
|
||||
this.vp = this.node.getComponent(VideoPlayer)!;
|
||||
this.moveOut();
|
||||
}
|
||||
|
||||
start() {
|
||||
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
// if (this._isPlaying && this.vtype == VideoRoleType.Idle) {
|
||||
// console.log("BgVideo 主视频时长:", this.vp.currentTime, this.vp.duration);
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
/**播放视频 */
|
||||
playVideo(remoteUrl:string, loop:boolean = false, autoIn:boolean = true) {
|
||||
console.log("BgVideo 播放视频:", this.node.position)
|
||||
this.vp.remoteURL = remoteUrl
|
||||
this.vp.loop = loop
|
||||
this.vp.stop()
|
||||
this.vp.play()
|
||||
this._isPlaying = true
|
||||
if (autoIn) {
|
||||
this.moveIn()
|
||||
}
|
||||
}
|
||||
|
||||
/**暂停视频 */
|
||||
pauseVideo() {
|
||||
console.log("BgVideo 暂停视频:", this._vtype)
|
||||
this.vp.pause()
|
||||
}
|
||||
/**继续播放 */
|
||||
replayVideo() {
|
||||
this.vp.play()
|
||||
}
|
||||
|
||||
moveIn() {
|
||||
this.node.position = new Vec3(0, 0, 0)
|
||||
// //测试代码
|
||||
// if (this._vtype == VideoRoleType.emo) {
|
||||
// this.node.position = new Vec3(0, -500, 0)
|
||||
// }
|
||||
}
|
||||
moveOut() {
|
||||
this.node.position = new Vec3(1000, 1000, 0)
|
||||
}
|
||||
|
||||
/**回收视频 */
|
||||
recycleVideo() {
|
||||
this.vp.stop()
|
||||
this.vp.remoteURL = ""
|
||||
this._isPlaying = false
|
||||
this.moveOut()
|
||||
// this.node.destroy()
|
||||
}
|
||||
|
||||
|
||||
onVideoEvent(event1:any, event2:any) {
|
||||
// console.log("bgvideo BgVideo组件 event", event2, this._vtype)
|
||||
if (event2 == "ready-to-play") {
|
||||
// if (!this._emoShow) {
|
||||
// this._emoShow = true;
|
||||
// this.removeEmoAudioNext()
|
||||
// }
|
||||
// this.setEmoReadyAudio(this.emo1)
|
||||
if (this._cbReady) {
|
||||
this._cbReady()
|
||||
}
|
||||
} else if (event2 == "completed") {
|
||||
if (this._cbEnd) {
|
||||
this._cbEnd()
|
||||
}
|
||||
} else if (event2 == "playing") {
|
||||
if (this._vtype == VideoRoleType.Idle) {
|
||||
if (this._cbEnd) { //主视频是循环播放的,没有completed事件,所以用playing事件来处理
|
||||
this._cbEnd()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "72cc3ead-c647-42b1-8c26-7a10d59d419e",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "f1136fde-852b-445f-b4e6-750712006155",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
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: '';//隐私协议
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "cccc5fab-681f-424a-8410-1d418257aaf9",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,332 @@
|
||||
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";
|
||||
|
||||
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
|
||||
private static _I: SDKManager = null;
|
||||
public static get I(): SDKManager {
|
||||
if (!SDKManager._I) {
|
||||
SDKManager._I = new SDKManager();
|
||||
SDKManager._I.init();
|
||||
}
|
||||
return SDKManager._I;
|
||||
}
|
||||
|
||||
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 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
|
||||
|
||||
//初始化SDK
|
||||
static init(cb: Function = null) {
|
||||
this.video_reward_map = {}
|
||||
this.share_reward_map = {}
|
||||
|
||||
console.log("平台值 wx:",window["wx"], typeof window["wx"])
|
||||
console.log("平台值 ks:",window["ks"], typeof window["ks"])
|
||||
console.log("平台值 tt:",window["tt"], typeof window["tt"])
|
||||
|
||||
if (typeof window["ks"] !== 'undefined') {
|
||||
this.sdk_channel = E_SDK_Channel.KS
|
||||
this.sdk = new KSSDK() //快手
|
||||
}else if (sys.platform === sys.Platform.WECHAT_GAME && typeof window["wx"] !== 'undefined') {
|
||||
this.sdk_channel = E_SDK_Channel.WX
|
||||
this.sdk = new WXSDK() //微信
|
||||
} else if (sys.platform === sys.Platform.BYTEDANCE_MINI_GAME && typeof window["tt"] !== 'undefined') {
|
||||
this.sdk_channel = E_SDK_Channel.BD
|
||||
this.sdk = new ByteDanceSDK() //抖音(头条)
|
||||
} else {
|
||||
this.sdk_channel = E_SDK_Channel.WEB
|
||||
this.sdk = new WebSDK()
|
||||
}
|
||||
|
||||
console.log("当前平台:",sys.platform, 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() {
|
||||
console.log("SDKManager 视频广告前")
|
||||
AudioManager.I.PauseMusic();
|
||||
}
|
||||
//看视频广告后返回游戏
|
||||
static video_ad_back() {
|
||||
console.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;
|
||||
}
|
||||
|
||||
|
||||
/**是否支持客服功能 */
|
||||
static KefuSupport() {
|
||||
return this.sdk.kefuSupport();
|
||||
}
|
||||
/**打开客服 */
|
||||
static OpenKefu() {
|
||||
this.sdk.openKefu();
|
||||
}
|
||||
|
||||
|
||||
//region 播放背景视频 cbMap = {cbReady, cbEnded}
|
||||
static PlayBgAudio(remoteUrl:string, vtype:VideoRoleType, loop:boolean = false, extra:any = {}) {
|
||||
this.sdk.playBgAudio(remoteUrl, vtype, loop, extra);
|
||||
}
|
||||
//添加要播放的表情视频
|
||||
static AddEmoAudio(remoteUrl:string, vtype:VideoRoleType, loop:boolean = false, extra:any = {}) {
|
||||
this.sdk.addEmoAudio(remoteUrl, vtype, loop, extra);
|
||||
}
|
||||
|
||||
|
||||
//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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "0bfc3e76-d69a-4005-9325-7a89d93359ea",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,583 @@
|
||||
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"
|
||||
|
||||
//广告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) => {
|
||||
console.log("抖音 检测侧边栏功能->", res)
|
||||
if (res.isExist == true) {
|
||||
if (ByteDanceSDK._SidebarState == 0) {
|
||||
ByteDanceSDK._SidebarState = 1
|
||||
}
|
||||
}
|
||||
cb && cb(res.isExist == true);
|
||||
},
|
||||
fail: (res) => {
|
||||
console.log("抖音 检测侧边栏功能失败->", res)
|
||||
cb && cb(false);
|
||||
}
|
||||
})
|
||||
}
|
||||
/**前往侧边栏 */
|
||||
public static GotoSidebar(cb:Function = null){
|
||||
console.log("抖音 正在前往侧边栏...")
|
||||
window["tt"].navigateToScene({
|
||||
scene: "sidebar",
|
||||
success(res) {
|
||||
console.log("抖音 前往侧边栏 成功")
|
||||
cb && cb(true);
|
||||
},
|
||||
fail(res) {
|
||||
console.log("抖音 前往侧边栏 失败", res)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//初始化
|
||||
init(cb: Function = null) {
|
||||
console.log("init 抖音 初始化...")
|
||||
// 保持屏幕常亮
|
||||
window["tt"].setKeepScreenOn({
|
||||
keepScreenOn: true,
|
||||
success(res) {
|
||||
},
|
||||
fail(res) {
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
//小游戏回到前台
|
||||
window['tt'].onShow((res)=>{
|
||||
console.log("抖音 小游戏回到前台->", res)
|
||||
if (!res) {
|
||||
return;
|
||||
}
|
||||
// console.log("启动参数:", res.query);
|
||||
// console.log("来源信息:", res.refererInfo);
|
||||
// console.log("场景值:", res.scene);
|
||||
// console.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") {
|
||||
console.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();
|
||||
console.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();
|
||||
console.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) {
|
||||
console.log("抖音 - 检测权限状态 succ:", JSON.stringify(res))
|
||||
if (autoKey == "scope.userInfo" && res.data['scope.userInfo']) {
|
||||
cb && cb(true)
|
||||
} else {
|
||||
cb && cb(false)
|
||||
}
|
||||
},
|
||||
fail(res:any) {
|
||||
console.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) {
|
||||
console.log("抖音 - 获取用户信息成功:", res);
|
||||
cb && cb({avatarUrl:res.userInfo.avatarUrl, nickName:res.userInfo.nickName}) //encryptedData
|
||||
},
|
||||
fail(res) {
|
||||
console.log("抖音 - 获取用户信息失败", res);
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
//region 登录
|
||||
login(cb: Function = null) {
|
||||
// cb && cb({ platform:2, code: null });
|
||||
window["tt"].login({
|
||||
force: false, //未登录时, 是否强制调起登录框
|
||||
success(res) {
|
||||
console.log(`抖音 - 登录成功 code=${res.code}, anonymousCode=${res.anonymousCode}`);
|
||||
cb && cb({ platform:2, code: res.code });
|
||||
},
|
||||
fail(res) {
|
||||
console.log(`抖音 - 登录失败`, res);
|
||||
cb && cb({ platform:2, code: null });
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
private init_banner() {
|
||||
if (AD_BANNER as any == "test") {
|
||||
console.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(() => {
|
||||
// console.log("init_banner 广告显示成功");
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// console.log("init_banner 广告组件出现问题", err);
|
||||
// });
|
||||
// })
|
||||
}
|
||||
|
||||
private init_splash() {
|
||||
|
||||
this.preload_splash()
|
||||
}
|
||||
|
||||
private preload_splash() {
|
||||
if (AD_SPLASH as any == "test") {
|
||||
console.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 => {
|
||||
console.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){
|
||||
console.log("bd_splash err:",err)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
private init_video() {
|
||||
if (AD_AWARD as any == "test") {
|
||||
console.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') {
|
||||
console.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
|
||||
console.log("插屏广告展示成功");
|
||||
})
|
||||
} else {
|
||||
console.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()
|
||||
console.log("主动拉起分享");
|
||||
let info:any = this.shareInfo();
|
||||
info.succ = rewardCB;
|
||||
|
||||
info.success = (res) => {
|
||||
console.log("抖音 主动拉起分享成功", res);
|
||||
}
|
||||
info.fail = (err) => {
|
||||
console.log("抖音 主动拉起分享失败", err);
|
||||
}
|
||||
// info.complete = (res) => {
|
||||
// console.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`
|
||||
console.log("抖音 正在删除上一个音频 ->", lastPath);
|
||||
fs.removeSavedFile({
|
||||
filePath: lastPath,
|
||||
success(res) {
|
||||
console.log("抖音 删除上一个音频成功", res);
|
||||
},
|
||||
fail(err) {
|
||||
console.log("抖音 删除上一个音频失败", err);
|
||||
},
|
||||
complete(res) {
|
||||
console.log("抖音 删除上一个音频完成", res);
|
||||
|
||||
//2.保存当前音频
|
||||
//这里需要每次保存时换一下名字的原因是:innerAudioContext设置路径时如果路径相同,会认为还是同一个音频,不会重新加载,所以需要每次保存时换一下名字
|
||||
self._iacIdx++;
|
||||
const audioPath = window['tt'].env.USER_DATA_PATH + `/ordernew${self._iacIdx}.mp3`
|
||||
console.log("抖音 正在保存本次音频 ->", audioPath);
|
||||
fs.writeFile({
|
||||
filePath: audioPath,
|
||||
data: substring,
|
||||
encoding: 'base64',
|
||||
success(res) {
|
||||
if (self._innerAudioContext == null){
|
||||
self._innerAudioContext = window['tt'].createInnerAudioContext();
|
||||
// 添加播放结束的回调
|
||||
self._innerAudioContext.onEnded(() => {
|
||||
console.log("抖音 AI语音播放结束")
|
||||
self._innerAudioContext.stop(); // 使用 stop 方法停止音频并重置播放状态
|
||||
self._innerAudioContext.destroy(); // 销毁音频实例
|
||||
self._innerAudioContext = null;
|
||||
});
|
||||
}
|
||||
console.log("抖音 播放base64音频", audioPath)
|
||||
self._innerAudioContext.src = audioPath;
|
||||
self._innerAudioContext.play(); // 开始播放音频
|
||||
},
|
||||
fail(err) {
|
||||
console.log("抖音 保存本次音频失败", err);
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//region版本更新检测
|
||||
//微信开发者工具上可以通过「编译模式」下的「下次编译模拟更新」开关来调试
|
||||
qiangzhiUpdata() {
|
||||
if (window['tt'].getUpdateManager == null) {
|
||||
console.log("抖音 没有更新管理器", window['tt'].getUpdateManager)
|
||||
return;
|
||||
}
|
||||
|
||||
const updateManager = window['tt'].getUpdateManager();
|
||||
|
||||
//监听向微信后台请求检查更新结果事件。微信在小程序每次启动(包括热启动)时自动检查更新,不需由开发者主动触发。
|
||||
updateManager.onCheckForUpdate((res) => {
|
||||
// 请求完新版本信息的回调
|
||||
console.log("抖音 检查是否有新版本:", res.hasUpdate)
|
||||
});
|
||||
|
||||
//监听小程序有版本更新事件。客户端主动触发下载(无需开发者触发),下载成功后回调
|
||||
updateManager.onUpdateReady(async () => {
|
||||
window['tt'].showModal({
|
||||
title: '更新提示',
|
||||
content: '新版本已经准备好,是否重启应用?',
|
||||
success: function (res) {
|
||||
if (res.confirm) {
|
||||
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
||||
updateManager.applyUpdate()
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
//监听小程序更新失败事件。小程序有新版本,客户端主动触发下载(无需开发者触发),下载失败(可能是网络原因等)时回调
|
||||
updateManager.onUpdateFailed(function (err) {
|
||||
console.log("抖音 新版本下载失败", err)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//客服功能是否支持
|
||||
kefuSupport() {
|
||||
console.log("抖音 不支持联系客服")
|
||||
return false;
|
||||
}
|
||||
//进入联系客服
|
||||
openKefu() {
|
||||
console.log("抖音 进入联系客服")
|
||||
}
|
||||
|
||||
|
||||
//播放背景视频
|
||||
playBgAudio(remoteUrl:string, loop:boolean = false, cbStart?: Function, cbEnded?: Function) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
//region 友盟+
|
||||
umaInit() {
|
||||
}
|
||||
//友盟统计是否开启
|
||||
umaSwt() {
|
||||
return false;
|
||||
}
|
||||
//友盟事件统计
|
||||
umaEvent(eventName: string, value: any = {}) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ae1fd2cf-a4c5-4d59-baec-dad3b25fe2d2",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,775 @@
|
||||
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";
|
||||
|
||||
//广告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;
|
||||
console.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(() => {
|
||||
console.log("快手 onHide回调:")
|
||||
if (this.ShareCb) {
|
||||
this.ShareSTime = new Date().getTime();
|
||||
console.log("分享时间差 记录:", this.ShareSTime);
|
||||
}
|
||||
});
|
||||
|
||||
this.init_video(); //初始化视频广告
|
||||
this.init_splash(); //初始化插屏广告
|
||||
this.init_banner(); //初始化Banner广告 弹窗广告
|
||||
this.qiangzhiUpdata(); //强制更新
|
||||
cb && cb();
|
||||
}
|
||||
|
||||
|
||||
//小游戏回到前台
|
||||
onWxShow(data: any) {
|
||||
console.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();
|
||||
console.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) {
|
||||
console.log("快手 - 检测权限状态 succ:", res)
|
||||
if (autoKey == "userInfo" && res.authSetting['scope.userInfo']) {
|
||||
cb && cb(true)
|
||||
} else {
|
||||
cb && cb(false)
|
||||
}
|
||||
},
|
||||
fail(res:any) {
|
||||
console.log("快手 - 检测权限状态 fail:", res)
|
||||
cb && cb(false)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取个人信息
|
||||
*/
|
||||
getUserInfo(cb:I_SDK_UserInfo_Callback = null) {
|
||||
var self = this;
|
||||
window['ks'].getSetting({
|
||||
success(res:any) {
|
||||
console.log("快手 - 获取授权信息成功:", res);
|
||||
let isScope = res.authSetting['scope.userInfo']
|
||||
if (isScope) {
|
||||
window['ks'].getUserInfo({
|
||||
success: (res2) => {
|
||||
console.log("快手 - 获取用户信息成功:", res2);
|
||||
cb && cb({avatarUrl:res2.userInfo.avatarUrl, nickName:res2.userInfo.nickName})
|
||||
},
|
||||
fail: (error) => {
|
||||
console.log("快手 - 获取用户信息失败:", error);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
//向用户发起授权请求
|
||||
window['ks'].authorize({
|
||||
scope: 'scope.userInfo',
|
||||
success: (res) => {
|
||||
console.log("快手 - 发起授权请求成功:", res);
|
||||
self.getUserInfo(cb)
|
||||
},
|
||||
fail: (error) => {
|
||||
console.log("快手 - 发起授权请求失败: ", error);
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
fail: (error) => {
|
||||
console.log("快手 - 获取授权信息失败: ", error);
|
||||
// cb && cb({avatarUrl:"", nickName:""})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//region 快手登录
|
||||
login(cb: Function = null) {
|
||||
window['ks'].login({
|
||||
success: (res) => {
|
||||
console.log('快手 - 登录成功', res.code);
|
||||
cb && cb({ platform:3, code: res.code });
|
||||
},
|
||||
fail(res: any) {
|
||||
console.log(`快手 login 调用失败`, res);
|
||||
cb && cb({ platform:3, code: null });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
//初始化视频广告
|
||||
private init_video() {
|
||||
if (wx_video_ad_unit_id as any == "test") {
|
||||
console.log("快手 激励广告id未配置,跳过此类型初始化")
|
||||
return
|
||||
}
|
||||
|
||||
this.wx_video = window['ks'].createRewardedVideoAd({
|
||||
adUnitId: wx_video_ad_unit_id
|
||||
});
|
||||
this.wx_video.onError((err) => {
|
||||
console.log('onError event emit', err);
|
||||
});
|
||||
this.wx_video.onClose(res => {
|
||||
console.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") {
|
||||
console.log("快手 插屏广告id未配置,跳过此类型初始化")
|
||||
return
|
||||
}
|
||||
|
||||
// 创建插屏广告实例,提前初始化
|
||||
if (window['ks'].createInterstitialAd){
|
||||
this.wx_splash = window['ks'].createInterstitialAd({
|
||||
adUnitId: wx_splash_ad_unit_id
|
||||
});
|
||||
this.wx_splash.onError((err) => {
|
||||
console.log('splash onError event emit', err);
|
||||
});
|
||||
this.wx_splash.onClose(res => {
|
||||
console.log('splash onClose event emit', res);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//初始化Banner
|
||||
private init_banner() {
|
||||
if (wx_banner_ad_unit_id as any == "test") {
|
||||
console.log("快手 横幅广告id未配置,跳过此类型初始化")
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//显示视频广告
|
||||
show_video(callback:Function, tag:number) {
|
||||
if (wx_video_ad_unit_id == 'test') {
|
||||
console.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){
|
||||
// 激励视频展示成功
|
||||
console.log(`快手 show rewarded video ad success, result is ${result}`)
|
||||
}).catch(function(error){
|
||||
// 激励视频展示失败
|
||||
console.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){
|
||||
// 插屏广告展示成功
|
||||
console.log(`快手 show interstitial ad success, result is ${result}`)
|
||||
}).catch(function(error){
|
||||
// 插屏广告展示失败
|
||||
console.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) {
|
||||
console.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) {
|
||||
console.log("显示游戏圈,快手暂不支持");
|
||||
return
|
||||
}
|
||||
}
|
||||
//隐藏游戏圈
|
||||
hide_gameClub() {
|
||||
console.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()) {
|
||||
console.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`
|
||||
console.log("快手 正在删除上一个音频 ->", lastPath);
|
||||
fs.removeSavedFile({
|
||||
filePath: lastPath,
|
||||
success(res) {
|
||||
console.log("快手 删除上一个音频成功", res);
|
||||
},
|
||||
fail(err) {
|
||||
console.log("快手 删除上一个音频失败", err);
|
||||
},
|
||||
complete(res) {
|
||||
console.log("快手 删除上一个音频完成", res);
|
||||
|
||||
//2.保存当前音频
|
||||
//这里需要每次保存时换一下名字的原因是:innerAudioContext设置路径时如果路径相同,会认为还是同一个音频,不会重新加载,所以需要每次保存时换一下名字
|
||||
self._iacIdx++;
|
||||
const audioPath = window['ks'].env.USER_DATA_PATH + `/ordernew${self._iacIdx}.mp3`
|
||||
console.log("快手 正在保存本次音频 ->", audioPath);
|
||||
fs.writeFile({
|
||||
filePath: audioPath,
|
||||
data: substring,
|
||||
encoding: 'base64',
|
||||
success(res) {
|
||||
if (self._innerAudioContext == null){
|
||||
self._innerAudioContext = window['ks'].createInnerAudioContext();
|
||||
// 添加播放结束的回调
|
||||
self._innerAudioContext.onEnded(() => {
|
||||
console.log("快手 AI语音播放结束")
|
||||
self._innerAudioContext.stop(); // 使用 stop 方法停止音频并重置播放状态
|
||||
self._innerAudioContext.destroy(); // 销毁音频实例
|
||||
self._innerAudioContext = null;
|
||||
});
|
||||
}
|
||||
console.log("快手 播放base64音频", audioPath)
|
||||
self._innerAudioContext.src = audioPath;
|
||||
self._innerAudioContext.play(); // 开始播放音频
|
||||
},
|
||||
fail(err) {
|
||||
console.log("快手 保存本次音频失败", err);
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
//region版本更新检测
|
||||
//微信开发者工具上可以通过「编译模式」下的「下次编译模拟更新」开关来调试
|
||||
qiangzhiUpdata() {
|
||||
if (window['ks'].getUpdateManager == null) {
|
||||
console.log("快手 没有更新管理器", window['ks'].getUpdateManager)
|
||||
return;
|
||||
}
|
||||
|
||||
const updateManager = window['ks'].getUpdateManager();
|
||||
|
||||
//监听向微信后台请求检查更新结果事件。微信在小程序每次启动(包括热启动)时自动检查更新,不需由开发者主动触发。
|
||||
updateManager.onCheckForUpdate((res) => {
|
||||
// 请求完新版本信息的回调
|
||||
console.log("快手 检查是否有新版本:", res.hasUpdate)
|
||||
});
|
||||
|
||||
//监听小程序有版本更新事件。客户端主动触发下载(无需开发者触发),下载成功后回调
|
||||
updateManager.onUpdateReady(async () => {
|
||||
const { confirm } = await window['ks'].showModal({
|
||||
title: '更新提示',
|
||||
content: '新版本已经准备好,是否重启应用?',
|
||||
});
|
||||
if (confirm) {
|
||||
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
||||
updateManager.applyUpdate();
|
||||
}
|
||||
});
|
||||
|
||||
//监听小程序更新失败事件。小程序有新版本,客户端主动触发下载(无需开发者触发),下载失败(可能是网络原因等)时回调
|
||||
updateManager.onUpdateFailed(function (err) {
|
||||
console.log("快手 新版本下载失败", err)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//客服功能是否支持
|
||||
kefuSupport() {
|
||||
console.log("快手 不支持联系客服")
|
||||
return false;
|
||||
}
|
||||
//进入联系客服
|
||||
openKefu() {
|
||||
console.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) {
|
||||
console.log("快手 不支持播放视频")
|
||||
return
|
||||
}
|
||||
if (this._bgVideo && this._bgShow) {
|
||||
this.playBgAudioNext(remoteUrl, vtype, loop, extra);
|
||||
return
|
||||
}
|
||||
let self = this;
|
||||
console.log("微信 播放背景视频组件1", remoteUrl);
|
||||
this.curPlayType = vtype
|
||||
if (!this._bgVideo) {
|
||||
this._bgVideo = this.createVideoHandle();
|
||||
// this._bgVideo.onPlay(() => {
|
||||
// console.log("微信 背景视频播放开始");
|
||||
// })
|
||||
this._bgVideo.onTimeUpdate((_tinfo:any) =>{
|
||||
// console.log("微信 背景视频播放进度", self._bgShow, _tinfo);
|
||||
if (!self._bgShow) {
|
||||
if (_tinfo && _tinfo.position > 0.01) {
|
||||
console.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();
|
||||
console.log("微信 创建背景视频组件2--->", remoteUrl);
|
||||
this.curPlayType = vtype
|
||||
let self = this;
|
||||
if (!this._bgTempVideo) {
|
||||
this._bgTempVideo = this.createVideoHandle();
|
||||
// this._bgTempVideo.onPlay(() => {
|
||||
// console.log("微信 临时背景视频播放开始");
|
||||
// })
|
||||
this._bgTempVideo.onTimeUpdate((_tinfo:any) =>{
|
||||
// console.log("微信 临时背景视频播放进度", self._bgTempShow, _tinfo);
|
||||
if (!self._bgTempShow) {
|
||||
if (_tinfo && _tinfo.position > 0.01) {
|
||||
console.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;
|
||||
console.log("微信 播放emo视频1", remoteUrl);
|
||||
this.curPlayType = vtype
|
||||
if (!this._emoVideo) {
|
||||
this._emoVideo = this.createVideoHandle();
|
||||
// this._emoVideo.onPlay(() => {
|
||||
// console.log("微信 背景视频播放开始");
|
||||
// })
|
||||
this._emoVideo.onTimeUpdate((_tinfo:any) =>{
|
||||
// console.log("微信 背景视频播放进度", self._emoShow, _tinfo);
|
||||
if (!self._emoShow) {
|
||||
if (_tinfo && _tinfo.position > 0.01) {
|
||||
console.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();
|
||||
console.log("微信 播放emo视频2--->", remoteUrl);
|
||||
this.curPlayType = vtype
|
||||
let self = this;
|
||||
if (!this._emoTempVideo) {
|
||||
this._emoTempVideo = this.createVideoHandle();
|
||||
// this._emoTempVideo.onPlay(() => {
|
||||
// console.log("微信 临时背景视频播放开始");
|
||||
// })
|
||||
this._emoTempVideo.onTimeUpdate((_tinfo:any) =>{
|
||||
// console.log("微信 临时背景视频播放进度", self._emoTempShow, _tinfo);
|
||||
if (!self._emoTempShow) {
|
||||
if (_tinfo && _tinfo.position > 0.01) {
|
||||
console.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
|
||||
}
|
||||
console.log("微信 视频适配信息", this.videoAdaInfo, size)
|
||||
return this.videoAdaInfo
|
||||
}
|
||||
|
||||
//设置暂停播放的主视频
|
||||
private vpWait: any = null;
|
||||
setBgAudioPause(wait:any) {
|
||||
console.log("微信 主视频暂停播放")
|
||||
this.vpWait = wait
|
||||
this.vpWait.pause()
|
||||
}
|
||||
replayBgAudioPause() {
|
||||
console.log("微信 主视频继续播放")
|
||||
if (this.vpWait) {
|
||||
this.vpWait.play()
|
||||
}
|
||||
}
|
||||
|
||||
//设置准备好要播放的表情视频
|
||||
private emoReady: any = null;
|
||||
setEmoReadyAudio(au: any) {
|
||||
console.log("微信 设置emo ready视频")
|
||||
if (this.emoReady) {
|
||||
this.emoReady.stop()
|
||||
this.videoMoveOut(this.emoReady)
|
||||
}
|
||||
this.emoReady = au;
|
||||
this.emoReady.pause()
|
||||
}
|
||||
//移除准备好要播放的表情视频
|
||||
removeEmoReadyAudio() {
|
||||
console.log("微信 移除emo ready视频")
|
||||
if (this.emoReady) {
|
||||
this.emoReady.stop()
|
||||
this.videoMoveOut(this.emoReady)
|
||||
}
|
||||
this.emoReady = null
|
||||
}
|
||||
//播放准备好要播放的表情视频
|
||||
doPlayEmoReadyAudio():boolean {
|
||||
if (this.emoReady) {
|
||||
console.log("微信 播放emo ready视频")
|
||||
this.emoReady.play()
|
||||
this.videoMoveIn(this.emoReady)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
//表情视频播放结束
|
||||
doEmoFinish() {
|
||||
console.log("微信emo ready视频播放结束")
|
||||
this.removeEmoReadyAudio()
|
||||
this.replayBgAudioPause()
|
||||
}
|
||||
|
||||
|
||||
//region 友盟+
|
||||
umaInit() {
|
||||
}
|
||||
//友盟统计是否开启
|
||||
umaSwt() {
|
||||
return false;
|
||||
}
|
||||
//友盟事件统计
|
||||
umaEvent(eventName: string, value: any = {}) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "6c186fa7-4295-4a83-a698-874a29a67c0d",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,296 @@
|
||||
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";
|
||||
|
||||
export class WebSDK{
|
||||
|
||||
//初始化
|
||||
init(cb: Function = null) {
|
||||
console.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);
|
||||
|
||||
console.log("web 播放base64音频", audioUrl)
|
||||
// 创建音频元素并播放
|
||||
if (this._audioInst == null) {
|
||||
this._audioInst = new Audio(audioUrl);
|
||||
} else {
|
||||
this._audioInst.src = audioUrl;
|
||||
}
|
||||
this._audioInst.play();
|
||||
|
||||
}
|
||||
|
||||
//客服功能是否支持
|
||||
kefuSupport() {
|
||||
console.log("web 不支持联系客服")
|
||||
return false;
|
||||
}
|
||||
//进入联系客服
|
||||
openKefu() {
|
||||
console.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
|
||||
}
|
||||
|
||||
console.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 友盟+
|
||||
umaInit() {
|
||||
}
|
||||
//友盟统计是否开启
|
||||
umaSwt() {
|
||||
return false;
|
||||
}
|
||||
//友盟事件统计
|
||||
umaEvent(eventName: string, value: any = {}) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "bf263997-b1ef-4d36-9101-f8b4dc56c800",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,929 @@
|
||||
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";
|
||||
|
||||
//广告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 WXSDK{
|
||||
|
||||
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 });
|
||||
WXSDK.g_InGameScene = window['wx'].getLaunchOptionsSync().scene;
|
||||
console.log('init 微信 - 进入游戏的场景值', WXSDK.g_InGameScene);
|
||||
|
||||
//显示分享按钮
|
||||
window['wx'].showShareMenu({
|
||||
withShareTicket: true,
|
||||
menus: ["shareAppMessage", "shareTimeline"],
|
||||
});
|
||||
window['wx'].onShareAppMessage(() => {
|
||||
return this.shareInfo();
|
||||
});
|
||||
window['wx'].onShareTimeline(() => {
|
||||
return this.shareInfo();
|
||||
})
|
||||
|
||||
//小游戏回到前台
|
||||
window['wx'].onShow(this.onWxShow.bind(this));
|
||||
//小游戏被隐藏 记个时间
|
||||
window['wx'].onHide(() => {
|
||||
if (this.ShareCb) {
|
||||
this.ShareSTime = new Date().getTime();
|
||||
console.log("分享时间差 记录:", this.ShareSTime);
|
||||
}
|
||||
});
|
||||
|
||||
this.init_video(); //初始化视频广告
|
||||
this.init_splash(); //初始化插屏广告
|
||||
this.init_banner(); //初始化Banner广告 横幅广告
|
||||
this.qiangzhiUpdata(); //检测更新
|
||||
cb && cb();
|
||||
}
|
||||
|
||||
|
||||
//小游戏回到前台
|
||||
onWxShow(data: any) {
|
||||
console.log("onWxShow:" + JSON.stringify(data))
|
||||
//返回小游戏场景值
|
||||
if (data && data.query && data.query.ShareCode) {
|
||||
GlobalValue.ShareTocusid = data.query.ShareCode
|
||||
}
|
||||
|
||||
if (this.ShareCb) {
|
||||
if (this.ShareSTime) {
|
||||
let nT = new Date().getTime();
|
||||
console.log("分享时间差 计算:",nT, this.ShareSTime);
|
||||
if (nT - this.ShareSTime > 1500) {
|
||||
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['wx'].getSetting({
|
||||
success(res:any) {
|
||||
console.log("微信 - 检测权限状态 succ:",JSON.stringify(res))
|
||||
if (autoKey == "userInfo" && res.authSetting['scope.userInfo']) {
|
||||
cb && cb(true)
|
||||
} else {
|
||||
cb && cb(false)
|
||||
}
|
||||
},
|
||||
fail(res:any) {
|
||||
console.log("微信 - 检测权限状态 fail:",JSON.stringify(res))
|
||||
cb && cb(false)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取个人信息
|
||||
*/
|
||||
getUserInfo(cb:I_SDK_UserInfo_Callback = null) {
|
||||
console.log("微信 - 正在获取用户信息...")
|
||||
var self = this;
|
||||
window['wx'].getUserInfo({
|
||||
success: (res) => {
|
||||
console.log("微信 - 获取用户信息成功:", res);
|
||||
cb && cb({avatarUrl:res.userInfo.avatarUrl, nickName:res.userInfo.nickName})
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log("微信 - 获取用户信息失败:", err);
|
||||
self.openUserAuthorize(cb);
|
||||
}
|
||||
})
|
||||
}
|
||||
//申请用户信息授权
|
||||
openUserAuthorize(cb: any) {
|
||||
var self = this;
|
||||
window['wx'].getSetting({
|
||||
scope: 'scope.userInfo',
|
||||
success(res:any) {
|
||||
console.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",
|
||||
}
|
||||
});
|
||||
console.log("微信 点击开始游戏授权用户信息")
|
||||
button.onTap((res) => {
|
||||
button.destroy();
|
||||
// if (res.userInfo) {
|
||||
// console.log(res.userInfo)
|
||||
// //此时可进行登录操作
|
||||
// cb && cb(res.userInfo)
|
||||
// }
|
||||
console.log("微信 点击Tap", res)
|
||||
self.getUserInfo(cb)
|
||||
});
|
||||
}
|
||||
},
|
||||
fail(err) {
|
||||
console.log('微信 - authorize fail', err);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//region 微信登录
|
||||
login(cb: Function = null) {
|
||||
window['wx'].login({
|
||||
success: (res) => {
|
||||
if (res.code) {
|
||||
console.log('微信 - 登录成功', res.code);
|
||||
cb && cb({ platform:1, code: res.code });
|
||||
} else {
|
||||
console.log('微信 - 登录失败', res.errMsg);
|
||||
cb && cb({ platform:1, code: null });
|
||||
}
|
||||
},
|
||||
fail(res: any) {
|
||||
console.log(`微信 login 调用失败`);
|
||||
console.log(res.anonymousCode)
|
||||
cb && cb({ platform:1, code: null });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
//初始化视频广告
|
||||
private init_video() {
|
||||
if (wx_video_ad_unit_id as any == "test") {
|
||||
console.log("微信 激励广告id未配置,跳过此类型初始化")
|
||||
return
|
||||
}
|
||||
|
||||
this.wx_video = window['wx'].createRewardedVideoAd({
|
||||
adUnitId: wx_video_ad_unit_id,
|
||||
disableFallbackSharePage: true // 是否禁用分享页,默认为false
|
||||
});
|
||||
this.wx_video.onLoad(() => {
|
||||
console.log('onLoad event emit');
|
||||
});
|
||||
this.wx_video.onError((err) => {
|
||||
console.log('onError event emit', err);
|
||||
});
|
||||
this.wx_video.onClose(res => {
|
||||
console.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") {
|
||||
console.log("微信 插屏广告id未配置,跳过此类型初始化")
|
||||
return
|
||||
}
|
||||
// 创建插屏广告实例,提前初始化
|
||||
if (window['wx'].createInterstitialAd){
|
||||
this.wx_splash = window['wx'].createInterstitialAd({
|
||||
adUnitId: wx_splash_ad_unit_id
|
||||
});
|
||||
this.wx_splash.onLoad(() => {
|
||||
console.log('splash onLoad event emit');
|
||||
});
|
||||
this.wx_splash.onError((err) => {
|
||||
console.log('splash onError event emit', err);
|
||||
});
|
||||
this.wx_splash.onClose(res => {
|
||||
console.log('splash onClose event emit', res);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//初始化Banner
|
||||
private init_banner() {
|
||||
if (wx_banner_ad_unit_id as any == "test") {
|
||||
console.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') {
|
||||
console.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 => {
|
||||
console.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];
|
||||
console.log("分享:", rand1, rand2);
|
||||
return {
|
||||
title: text,
|
||||
query: "ShareCode=" + "user_default", //ModelPlayer.I.getPlayerId(),
|
||||
imageUrl: picmap.url,
|
||||
imageUrlId: picmap.id,
|
||||
}
|
||||
}
|
||||
//主动拉起分享
|
||||
show_share(rewardCB?:Function) {
|
||||
console.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) {
|
||||
console.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;
|
||||
|
||||
console.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() {
|
||||
console.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()) {
|
||||
console.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`
|
||||
console.log("微信 正在删除上一个音频 ->", lastPath);
|
||||
fs.removeSavedFile({
|
||||
filePath: lastPath,
|
||||
success(res) {
|
||||
console.log("微信 删除上一个音频成功", res);
|
||||
},
|
||||
fail(err) {
|
||||
console.log("微信 删除上一个音频失败", err);
|
||||
},
|
||||
complete(res) {
|
||||
console.log("微信 删除上一个音频完成", res);
|
||||
|
||||
//2.保存当前音频
|
||||
//这里需要每次保存时换一下名字的原因是:innerAudioContext设置路径时如果路径相同,会认为还是同一个音频,不会重新加载,所以需要每次保存时换一下名字
|
||||
self._iacIdx++;
|
||||
const audioPath = window['wx'].env.USER_DATA_PATH + `/ordernew${self._iacIdx}.mp3`
|
||||
console.log("微信 正在保存本次音频 ->", audioPath);
|
||||
fs.writeFile({
|
||||
filePath: audioPath,
|
||||
data: substring,
|
||||
encoding: 'base64',
|
||||
success(res) {
|
||||
if (self._innerAudioContext == null){
|
||||
self._innerAudioContext = window['wx'].createInnerAudioContext();
|
||||
// 添加播放结束的回调
|
||||
self._innerAudioContext.onEnded(() => {
|
||||
console.log("微信 AI语音播放结束")
|
||||
self._innerAudioContext.stop(); // 使用 stop 方法停止音频并重置播放状态
|
||||
self._innerAudioContext.destroy(); // 销毁音频实例
|
||||
self._innerAudioContext = null;
|
||||
});
|
||||
}
|
||||
console.log("微信 播放base64音频", audioPath)
|
||||
self._innerAudioContext.src = audioPath;
|
||||
self._innerAudioContext.play(); // 开始播放音频
|
||||
},
|
||||
fail(err) {
|
||||
console.log("微信 保存本次音频失败", err);
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
//region版本更新检测
|
||||
//微信开发者工具上可以通过「编译模式」下的「下次编译模拟更新」开关来调试
|
||||
qiangzhiUpdata() {
|
||||
const updateManager = window['wx'].getUpdateManager();
|
||||
|
||||
//监听向微信后台请求检查更新结果事件。微信在小程序每次启动(包括热启动)时自动检查更新,不需由开发者主动触发。
|
||||
updateManager.onCheckForUpdate((res) => {
|
||||
// 请求完新版本信息的回调
|
||||
console.log("微信 检查是否有新版本:", res.hasUpdate)
|
||||
});
|
||||
|
||||
//监听小程序有版本更新事件。客户端主动触发下载(无需开发者触发),下载成功后回调
|
||||
updateManager.onUpdateReady(function () {
|
||||
window['wx'].showModal({
|
||||
title: '更新提示',
|
||||
content: '新版本已经准备好,是否重启应用?',
|
||||
success: function (res) {
|
||||
if (res.confirm) {
|
||||
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
||||
updateManager.applyUpdate()
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
//监听小程序更新失败事件。小程序有新版本,客户端主动触发下载(无需开发者触发),下载失败(可能是网络原因等)时回调
|
||||
updateManager.onUpdateFailed(function (err) {
|
||||
console.log("微信 新版本下载失败", err)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//客服功能是否支持
|
||||
kefuSupport() {
|
||||
if (window["wx"].openCustomerServiceConversation) {
|
||||
return true;
|
||||
}
|
||||
console.log("微信 不支持联系客服")
|
||||
return false;
|
||||
}
|
||||
//进入联系客服
|
||||
openKefu () {
|
||||
let wx = window["wx"];
|
||||
if (wx) {
|
||||
if (!wx.openCustomerServiceConversation) {
|
||||
return;
|
||||
}
|
||||
wx.openCustomerServiceConversation({
|
||||
success: res => {
|
||||
const { path, query } = res;
|
||||
console.log("微信 进入客服成功", path, query);
|
||||
},
|
||||
fail: res => {
|
||||
console.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;
|
||||
console.log("微信 播放背景视频组件1", remoteUrl);
|
||||
this.curPlayType = vtype
|
||||
if (!this._bgVideo) {
|
||||
this._bgVideo = this.createVideoHandle();
|
||||
// this._bgVideo.onPlay(() => {
|
||||
// console.log("微信 背景视频播放开始");
|
||||
// })
|
||||
this._bgVideo.onTimeUpdate((_tinfo:any) =>{
|
||||
// console.log("微信 背景视频播放进度", self._bgShow, _tinfo);
|
||||
if (!self._bgShow) {
|
||||
if (_tinfo && _tinfo.position > 0.01) {
|
||||
console.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();
|
||||
console.log("微信 创建背景视频组件2--->", remoteUrl);
|
||||
this.curPlayType = vtype
|
||||
let self = this;
|
||||
if (!this._bgTempVideo) {
|
||||
this._bgTempVideo = this.createVideoHandle();
|
||||
// this._bgTempVideo.onPlay(() => {
|
||||
// console.log("微信 临时背景视频播放开始");
|
||||
// })
|
||||
this._bgTempVideo.onTimeUpdate((_tinfo:any) =>{
|
||||
// console.log("微信 临时背景视频播放进度", self._bgTempShow, _tinfo);
|
||||
if (!self._bgTempShow) {
|
||||
if (_tinfo && _tinfo.position > 0.01) {
|
||||
console.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;
|
||||
console.log("微信 播放emo视频1", remoteUrl);
|
||||
this.curPlayType = vtype
|
||||
if (!this._emoVideo) {
|
||||
this._emoVideo = this.createVideoHandle();
|
||||
// this._emoVideo.onPlay(() => {
|
||||
// console.log("微信 背景视频播放开始");
|
||||
// })
|
||||
this._emoVideo.onTimeUpdate((_tinfo:any) =>{
|
||||
// console.log("微信 背景视频播放进度", self._emoShow, _tinfo);
|
||||
if (!self._emoShow) {
|
||||
if (_tinfo && _tinfo.position > 0.01) {
|
||||
console.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();
|
||||
console.log("微信 播放emo视频2--->", remoteUrl);
|
||||
this.curPlayType = vtype
|
||||
let self = this;
|
||||
if (!this._emoTempVideo) {
|
||||
this._emoTempVideo = this.createVideoHandle();
|
||||
// this._emoTempVideo.onPlay(() => {
|
||||
// console.log("微信 临时背景视频播放开始");
|
||||
// })
|
||||
this._emoTempVideo.onTimeUpdate((_tinfo:any) =>{
|
||||
// console.log("微信 临时背景视频播放进度", self._emoTempShow, _tinfo);
|
||||
if (!self._emoTempShow) {
|
||||
if (_tinfo && _tinfo.position > 0.01) {
|
||||
console.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
|
||||
}
|
||||
console.log("微信 视频适配信息", this.videoAdaInfo, size)
|
||||
return this.videoAdaInfo
|
||||
}
|
||||
|
||||
//设置暂停播放的主视频
|
||||
private vpWait: any = null;
|
||||
setBgAudioPause(wait:any) {
|
||||
console.log("微信 主视频暂停播放")
|
||||
this.vpWait = wait
|
||||
this.vpWait.pause()
|
||||
}
|
||||
replayBgAudioPause() {
|
||||
console.log("微信 主视频继续播放")
|
||||
if (this.vpWait) {
|
||||
this.vpWait.play()
|
||||
}
|
||||
}
|
||||
|
||||
//设置准备好要播放的表情视频
|
||||
private emoReady: any = null;
|
||||
setEmoReadyAudio(au: any) {
|
||||
console.log("微信 设置emo ready视频")
|
||||
if (this.emoReady) {
|
||||
this.emoReady.stop()
|
||||
this.videoMoveOut(this.emoReady)
|
||||
}
|
||||
this.emoReady = au;
|
||||
this.emoReady.pause()
|
||||
}
|
||||
//移除准备好要播放的表情视频
|
||||
removeEmoReadyAudio() {
|
||||
console.log("微信 移除emo ready视频")
|
||||
if (this.emoReady) {
|
||||
this.emoReady.stop()
|
||||
this.videoMoveOut(this.emoReady)
|
||||
}
|
||||
this.emoReady = null
|
||||
}
|
||||
//播放准备好要播放的表情视频
|
||||
doPlayEmoReadyAudio():boolean {
|
||||
if (this.emoReady) {
|
||||
console.log("微信 播放emo ready视频")
|
||||
this.emoReady.play()
|
||||
this.videoMoveIn(this.emoReady)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
//表情视频播放结束
|
||||
doEmoFinish() {
|
||||
console.log("微信emo ready视频播放结束")
|
||||
this.removeEmoReadyAudio()
|
||||
this.replayBgAudioPause()
|
||||
}
|
||||
|
||||
|
||||
//region 微信同声传译
|
||||
private rrmgr: any = null;
|
||||
startRecordRecognition() {
|
||||
console.log("微信 同声传译111")
|
||||
if (!this.rrmgr) {
|
||||
const plugin = requirePlugin("WechatSI");
|
||||
this.rrmgr = plugin.getRecordRecognitionManager();
|
||||
console.log("微信 同声传译222")
|
||||
|
||||
// 监听识别结果
|
||||
this.rrmgr.onRecognize = (res) => {
|
||||
console.log("微信 同声传译识别结果:", res.result);
|
||||
};
|
||||
|
||||
// 监听录音结束
|
||||
this.rrmgr.onStop = (res) => {
|
||||
console.log("微信 同声传译录音结束", res);
|
||||
};
|
||||
}
|
||||
this.rrmgr.start({ lang: "zh_CN" });
|
||||
console.log("微信 同声传译333")
|
||||
}
|
||||
stopRecordRecognition() {
|
||||
if (this.rrmgr) {
|
||||
this.rrmgr.stop();
|
||||
console.log("微信 同声传译444")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//region 友盟+
|
||||
//初始化友盟+
|
||||
umaInit() {
|
||||
window['wx'].uma.init({
|
||||
appKey:'67c969b99a16fe6dcd5bfec5',
|
||||
useOpenid:true,// default true
|
||||
autoGetOpenid:true,
|
||||
debug:true,
|
||||
uploadUserInfo:true// 上传用户信息,上传后可以看到有用户头像和昵称的分享信息
|
||||
})
|
||||
console.log("微信 uma 初始化");
|
||||
}
|
||||
//友盟统计是否开启
|
||||
umaSwt() {
|
||||
return true;
|
||||
}
|
||||
//友盟事件统计
|
||||
umaEvent(eventName: string, value: any = {}) {
|
||||
window['wx'].uma.trackEvent(eventName, value);
|
||||
console.log("微信 uma 统计:", eventName, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e281b3a8-afd6-4850-8742-07d84d1be980",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "d985ef27-1772-49d9-a3df-95c4d434fba2",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { _decorator, Component, EditBox, Label, macro, Node, view } from 'cc';
|
||||
import GameRootUI from './GameRootUI';
|
||||
const { ccclass, property, requireComponent } = _decorator;
|
||||
|
||||
//输入框事件监听
|
||||
@ccclass('EditBoxEvent')
|
||||
// @requireComponent(EditBox) //装饰器,表示这个组件必须包含EditBox组件
|
||||
export class EditBoxEvent extends Component {
|
||||
|
||||
private eb: EditBox = null!; //输入框组件
|
||||
|
||||
onLoad() {
|
||||
}
|
||||
|
||||
start() {
|
||||
this.eb = this.node.getComponent(EditBox)!;
|
||||
// this.node.on('editing-did-began', this.onEditDidBegan, this);
|
||||
this.node.on(EditBox.EventType.EDITING_DID_BEGAN, this.onEditDidBegan, this);
|
||||
this.node.on(EditBox.EventType.EDITING_DID_ENDED, this.onEditDidEnded, this);
|
||||
this.node.on(EditBox.EventType.EDITING_RETURN, this.onEditingReturn, this);
|
||||
console.log("EditBoxEvent: start.")
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
onEditDidBegan(editbox, customEventData) {
|
||||
console.log("EditBoxEvent: 开始编辑...")
|
||||
// view.setOrientation(macro.ORIENTATION_LANDSCAPE); //设置横屏
|
||||
// console.log("窗口大小 开始:", view.getVisibleSize(), GameRootUI.MainCamera)
|
||||
|
||||
}
|
||||
|
||||
onEditDidEnded(editbox, customEventData) {
|
||||
console.log("EditBoxEvent: 结束编辑.")
|
||||
// view.setOrientation(macro.ORIENTATION_LANDSCAPE); //设置横屏
|
||||
// console.log("窗口大小 结束:", view.getVisibleSize(), GameRootUI.MainCamera)
|
||||
}
|
||||
|
||||
onEditingReturn(editbox, customEventData) {
|
||||
console.log("EditBoxEvent: 按下返回.")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "630cbad4-2995-47f6-8eb8-8844e8a356d5",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import { _decorator, Button, EventTouch, Node, Vec3 } from "cc";
|
||||
import AudioManager from "../Manager/AudioManager";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
let _vec3 = new Vec3();
|
||||
|
||||
@ccclass('GButton')
|
||||
export class GButton {
|
||||
/**
|
||||
* 添加绑定事件
|
||||
* @param node
|
||||
* @param func 点击结束回调方法
|
||||
* @param obj 上下文
|
||||
* @param buttonType 点击事件类型(处理音效使用)
|
||||
* @param backStart 点击开始回调
|
||||
* @param backCancle 点击取消回调
|
||||
* @returns
|
||||
*/
|
||||
public static BandClick(node: Node, func: Function, obj: any, buttonType=10000, backStart: Function = null, backCancle: Function = null, clickScale: boolean = true): void {
|
||||
if (!node) {
|
||||
//hg_utils.hgLog("GButton, bandClick, failed by node is null");
|
||||
return;
|
||||
}
|
||||
|
||||
if (buttonType == null) {
|
||||
buttonType = 10000;
|
||||
}
|
||||
|
||||
if (!node['oldScale']) {
|
||||
node['oldScale'] = node.scale.clone();
|
||||
}
|
||||
|
||||
node.on(Node.EventType.TOUCH_START, (ev: EventTouch) => {
|
||||
// let bs = node.getComponent(Button);
|
||||
// if (!bs || (bs && bs.interactable == true)) {
|
||||
// backStart && backStart.call(obj, ev);
|
||||
// }
|
||||
if (clickScale) {
|
||||
node.scale = Vec3.multiplyScalar(_vec3, node['oldScale'], 1.05);
|
||||
}
|
||||
if (backStart) {
|
||||
backStart.call(obj, ev);
|
||||
}
|
||||
}, obj);
|
||||
node.on(Node.EventType.TOUCH_CANCEL, (ev: EventTouch) => {
|
||||
if (clickScale) {
|
||||
node.scale = (node['oldScale'] as Vec3).clone();
|
||||
}
|
||||
if (backCancle) {
|
||||
backCancle.call(obj, ev);
|
||||
}
|
||||
}, obj);
|
||||
node.on(Node.EventType.TOUCH_END, (ev: EventTouch) => {
|
||||
if (clickScale) {
|
||||
node.scale = (node['oldScale'] as Vec3).clone();
|
||||
}
|
||||
//当前节点不是button,或button且不在禁用状态才可以执行点击回调
|
||||
let bs = node.getComponent(Button);
|
||||
if (!bs || (bs && bs.interactable == true)) {
|
||||
func.call(obj, ev);
|
||||
}
|
||||
//点击音效处理
|
||||
if (buttonType > 0) {
|
||||
AudioManager.I.PlayEffect(buttonType); //音效
|
||||
}
|
||||
}, obj);
|
||||
}
|
||||
/**
|
||||
* 移除绑定事件
|
||||
* @param node
|
||||
*/
|
||||
public static RemoveClick(node: Node, func?: Function) {
|
||||
if (node.isValid) {
|
||||
node.off(Node.EventType.TOUCH_START, func);
|
||||
node.off(Node.EventType.TOUCH_END, func);
|
||||
node.off(Node.EventType.TOUCH_CANCEL, func);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 先移除再绑定
|
||||
*/
|
||||
public static RemoveAndBandClick(node: Node, func: Function, obj: any = null, buttonType = null, backStart: Function = null, backCancle: Function = null, clickScale: boolean = true): void {
|
||||
obj = obj || node;
|
||||
GButton.RemoveClick(node);
|
||||
GButton.BandClick(node, func, obj, buttonType, backStart, backCancle, clickScale);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "d31f5542-1059-4930-b661-7cce067875bd",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
import { _decorator, assetManager, Camera, Canvas, Component, director, DynamicAtlasManager, instantiate, macro, Node, sys, tween, UIOpacity, Vec3 } from "cc";
|
||||
import { CommonConfig } from "../Config/CommonConfig";
|
||||
import ResManager from "../Manager/ResManager";
|
||||
import Utils from "./Utils";
|
||||
|
||||
const { ccclass, property, executeInEditMode, disallowMultiple } = _decorator;
|
||||
|
||||
//游戏根目录 每个场景都要加一下
|
||||
@ccclass
|
||||
// @executeInEditMode
|
||||
@disallowMultiple
|
||||
export default class GameRootUI extends Component {
|
||||
public static I: GameRootUI = null;
|
||||
|
||||
//当前场景摄像机
|
||||
private static _MainCamera: Camera = null;
|
||||
public static get MainCamera(): Camera {
|
||||
return GameRootUI._MainCamera
|
||||
}
|
||||
public static set MainCamera(value: Camera){
|
||||
GameRootUI._MainCamera = value
|
||||
}
|
||||
|
||||
public LayerNodeGroups = {} //界面组
|
||||
@property(Node)
|
||||
UIRoot: Node = null
|
||||
@property(Node)
|
||||
UILayerMod: Node = null
|
||||
@property
|
||||
public DefaultUI: string = "" //默认打开的界面
|
||||
|
||||
onLoad() {
|
||||
GameRootUI.I = this;
|
||||
}
|
||||
|
||||
start() {
|
||||
|
||||
//创建界面层
|
||||
for (const key in CommonConfig.UILayerGroup) {
|
||||
if (isNaN(Number(key))) {
|
||||
let newNode = instantiate(this.UILayerMod);
|
||||
newNode.name = key
|
||||
this.UIRoot.addChild(newNode)
|
||||
newNode.setPosition(Vec3.ZERO)
|
||||
newNode.setScale(Vec3.ONE)
|
||||
let l_idx = CommonConfig.UILayerGroup[key]
|
||||
newNode.setSiblingIndex(Number(l_idx))
|
||||
this.LayerNodeGroups[key] = newNode
|
||||
}
|
||||
}
|
||||
|
||||
//默认打开的界面
|
||||
if (this.DefaultUI.length > 0) {
|
||||
ResManager.I.loadSubpackagePrefab(this.DefaultUI, (res)=>{
|
||||
|
||||
let viewSP = res.getComponent(res.name);
|
||||
viewSP && viewSP.openUIData && viewSP.openUIData(null);
|
||||
|
||||
this.AddUIToLayer(res, CommonConfig.UILayerGroup.Layer_ui1);
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected update(dt: number): void {
|
||||
GameRootUI.I.CheckDisableOperTime(dt)
|
||||
}
|
||||
|
||||
|
||||
//手动创建时需要调用一下初始化
|
||||
public InitByCreate(_UIRoot: Node, _UILayerMod: Node, _DefaultUI: string) {
|
||||
this.UIRoot = _UIRoot
|
||||
this.UILayerMod = _UILayerMod
|
||||
this.DefaultUI = _DefaultUI
|
||||
}
|
||||
|
||||
//添加一个界面到某个层上
|
||||
public AddUIToLayer(ui:Node, e_layer:CommonConfig.UILayerGroup, zorder:number = 0){
|
||||
if (ui == null)
|
||||
return
|
||||
var n_layer = CommonConfig.UILayerGroup[e_layer]
|
||||
if (this.LayerNodeGroups[n_layer] != null){
|
||||
this.LayerNodeGroups[n_layer].addChild(ui)
|
||||
ui.setSiblingIndex(zorder)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//禁用操作界面----------------------------------------------------------------------------
|
||||
private static DisableOperUI: Node = null;
|
||||
private static DisableOperSwt: boolean = false;
|
||||
private static DisableOperDura: number = 0;
|
||||
private static DisableOperTime: number = 0;
|
||||
public static InitDisableOperUI(isshow: boolean) {
|
||||
if (GameRootUI.DisableOperUI == null){
|
||||
ResManager.I.loadSubpackagePrefab("UI/Cross/DisableOper_UI", (res:Node)=>{
|
||||
if (!GameRootUI.DisableOperUI) {
|
||||
GameRootUI.DisableOperUI = res
|
||||
director.getScene().addChild(res);
|
||||
director.addPersistRootNode(res);
|
||||
res.setSiblingIndex(9999)
|
||||
let croot = GameRootUI.DisableOperUI.getChildByName("croot")
|
||||
croot.active = false
|
||||
}
|
||||
|
||||
if (isshow) {
|
||||
GameRootUI.DisableOper(GameRootUI.DisableOperDura)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
/**开启禁用操作
|
||||
* @param dura 禁用时间 单位秒
|
||||
*/
|
||||
public static DisableOper(dura: number) {
|
||||
if (GameRootUI.DisableOperDura < dura){
|
||||
GameRootUI.DisableOperDura = dura
|
||||
}
|
||||
if (GameRootUI.DisableOperUI == null){
|
||||
GameRootUI.InitDisableOperUI(true)
|
||||
return
|
||||
}
|
||||
|
||||
Utils.Log("禁用操作 开启")
|
||||
GameRootUI.DisableOperSwt = true
|
||||
let croot = GameRootUI.DisableOperUI.getChildByName("croot")
|
||||
croot.active = true
|
||||
}
|
||||
/**关闭禁用操作 */
|
||||
public static EnableOper() {
|
||||
GameRootUI.DisableOperSwt = false
|
||||
GameRootUI.DisableOperDura = 0
|
||||
GameRootUI.DisableOperTime = 0
|
||||
if (GameRootUI.DisableOperUI){
|
||||
let croot = GameRootUI.DisableOperUI.getChildByName("croot")
|
||||
croot.active = false
|
||||
}
|
||||
Utils.Log("禁用操作 关闭")
|
||||
}
|
||||
private CheckDisableOperTime(dt: number) {
|
||||
if (!GameRootUI.DisableOperSwt)
|
||||
return
|
||||
GameRootUI.DisableOperTime += dt;
|
||||
if (GameRootUI.DisableOperTime >= GameRootUI.DisableOperDura){
|
||||
GameRootUI.EnableOper();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//过场界面----------------------------------------------------------------------------
|
||||
public static CrossUI: Node = null;
|
||||
public static InitCrossUI(isshow: boolean, cb = null) {
|
||||
if (GameRootUI.CrossUI == null){
|
||||
ResManager.I.loadSubpackagePrefab("UI/Cross/Cross_UI", (res:Node)=>{
|
||||
if (!GameRootUI.CrossUI) {
|
||||
GameRootUI.CrossUI = res
|
||||
director.getScene().addChild(res);
|
||||
director.addPersistRootNode(res);
|
||||
res.setSiblingIndex(9999)
|
||||
let croot = GameRootUI.CrossUI.getChildByName("croot")
|
||||
croot.active = false
|
||||
}
|
||||
|
||||
if (isshow) {
|
||||
GameRootUI.ShowCrossUI(cb)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
public static ShowCrossUI(cb = null) {
|
||||
// if (true) {
|
||||
// return
|
||||
// }
|
||||
|
||||
if (GameRootUI.CrossUI == null){
|
||||
GameRootUI.InitCrossUI(true)
|
||||
return
|
||||
}
|
||||
|
||||
// //设置摄像机
|
||||
// let canvas = GameRootUI.CrossUI.getComponent(Canvas)
|
||||
// canvas.cameraComponent = GameRootUI.MainCamera
|
||||
|
||||
//自动隐藏
|
||||
// Utils.Log("Cross 显示切换界面")
|
||||
let croot = GameRootUI.CrossUI.getChildByName("croot")
|
||||
croot.active = true
|
||||
let opa = croot.getComponent(UIOpacity)
|
||||
opa.opacity = 255
|
||||
tween(opa)
|
||||
.delay(0.3)
|
||||
.to(0.3, {opacity: 0})
|
||||
.call(()=>{
|
||||
croot.active = false
|
||||
// Utils.Log("Cross 隐藏切换界面")
|
||||
})
|
||||
.start()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "9fcf429c-5b25-4ade-89cb-6180e71f9a72",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import { _decorator } from "cc";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
//全局变量
|
||||
@ccclass
|
||||
export default class GlobalValue {
|
||||
static IsTest = false; //测试环境
|
||||
/**是否开启GM */
|
||||
static GMSwtitch = false;
|
||||
/**关卡数据中途缓存开关 */
|
||||
static LvHuancun = true;
|
||||
/**npc使用视频显示 */
|
||||
static NpcVideoMod = true;
|
||||
|
||||
/**分享关注id */
|
||||
static ShareTocusid = "share_tocusid";
|
||||
public static m_DomainData: any = {};
|
||||
// public static m_loginData = {};
|
||||
public static g_ChannelCfg = {};
|
||||
|
||||
/**规则说明内容 */
|
||||
public static RuleStr =
|
||||
`现在开始相亲!游戏规则如下:
|
||||
1. 你需要参考“关卡提示”,了解对方喜欢/厌恶的话题,投其所好,与对方聊天,说出让对方“心动”的对话。
|
||||
|
||||
2. 单次对话评分在 70 分以上即为心动对话,满足 5 次即可通关,游戏结束并解锁 1 星“通关”结局。
|
||||
|
||||
3. 对话中包含至少 1 次 90 分以上的对话,则可以解锁 2 星“恋人”结局。
|
||||
|
||||
4. 对话中包含至少 1 次 100 分的满分对话,则可以解锁 3 星“结婚”结局。
|
||||
|
||||
5. 对话次数耗尽,但仍然没有通关时,则视为相亲失败,解锁 0 星“失败”结局。
|
||||
|
||||
6. 如果出现 30 分及以下的对话,那么游戏会提前结束,视为相亲失败,解锁 0 星“失败”结局。
|
||||
|
||||
7. 默认拥有 10 次对话机会,可通过分享/观看广告增加对话机会,每次相亲中,最多可对话 25 次。
|
||||
|
||||
8. 可以通过友好地与对方交流喜好来获取高分。
|
||||
|
||||
9. 试着诱导让对方说出“愿意交往”,“愿意结婚”等表达交往意愿的对话来获取满分。`
|
||||
|
||||
|
||||
/**广告弹窗文本 加相亲次数 */
|
||||
public static XiangQinAdTipsStr = "每天只有 3 次相亲次数,请谨慎使用。每日可分享 1 次游戏,获得 1 次相亲次数,观看广告可获得 2 次相亲次数,最多可观看 3 次,每日 5:00 刷新相亲次数以及奖励获取次数。"
|
||||
|
||||
public static g_InGameScene = 0;//小程序获取当前进页面的来源
|
||||
public static g_InviteCode = ''; //玩家是否是通过邀请号进入的游
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**人物视频类型 */
|
||||
export enum VideoRoleType {
|
||||
None,
|
||||
/**待机动作 循环 */
|
||||
Idle,
|
||||
/**表情动作 */
|
||||
emo,
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "0fa2fb18-9099-4544-957d-40caaae7f806",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,792 @@
|
||||
import { _decorator, sys } from "cc";
|
||||
import { SDKManager } from "../Channel/SDKManager";
|
||||
import GlobalValue from "./GlobalValue";
|
||||
import { I_UserInfo } from "../Config/CommonConfig";
|
||||
import SubManager from "../../Sub/SubManager";
|
||||
import Utils from "./Utils";
|
||||
import { InnerMsgCode } from "../Config/InnerMsgCode";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/**
|
||||
* http通讯
|
||||
*/
|
||||
@ccclass
|
||||
export default class HttpUnit {
|
||||
//业务接口
|
||||
static readonly ServerHttpHost = "https://xqmnyx.vip.hnhxzkj.com/api/"; //正式
|
||||
// static readonly ServerHttpHost = "https://test.xqmnyx.vip.hnhxzkj.com/api/"; //测试
|
||||
|
||||
//socket通讯
|
||||
static readonly SocketHost = "wss://www.confessioncontract.com/game/ai/response/"; //正式
|
||||
// static readonly SocketHost = "wss://www.confessioncontract.com/test/game/ai/response/"; //测试
|
||||
|
||||
static readonly BGMUrl = "https://hxzgame.vip.hnhxzkj.com/lzx/XiangQin/BGM/"; //关卡音乐地址
|
||||
static readonly ZhenCangUrl = "https://hxzgame.vip.hnhxzkj.com/lzx/XiangQin/ZhenCang/"; //私家珍藏图片地址
|
||||
static readonly BgVideoUrl = "https://hxzgame.vip.hnhxzkj.com/lzx/XiangQin/BgVideo/"; //视频背景地址
|
||||
|
||||
static PlayerToken = ""; //登录时获取的token
|
||||
static LoginState = 0; //登录状态 0未登录 1登录中 2已登录
|
||||
static UserInfo:I_UserInfo = null; //用户数据
|
||||
|
||||
//后台设置
|
||||
//ad_chat_times:看广告加聊天次数 register_chat_times:注册赠送聊天次数
|
||||
//reset_day_ad:每日重置看广告次数 reset_day_share:每日重置分享次数 share_chat_times:分享可加聊天次数
|
||||
//ad_tickets_times:看广告可加相亲次数 share_tickets_times:分享可加相亲次数
|
||||
static SerSetting:any = {};
|
||||
|
||||
//单例
|
||||
private static I: HttpUnit;
|
||||
public static get ins(): HttpUnit {
|
||||
if (this.I == null) {
|
||||
this.I = new HttpUnit();
|
||||
}
|
||||
return this.I;
|
||||
}
|
||||
public constructor() {
|
||||
|
||||
}
|
||||
public jsonToQueryString(json: any) {
|
||||
var str = '';
|
||||
if (typeof json == "object") {
|
||||
str = "?";
|
||||
for (var k in json) {
|
||||
if (str != "?") {
|
||||
str += "&";
|
||||
}
|
||||
str += k + "=" + json[k];
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
private objectToFormData(obj: Object): FormData {
|
||||
const formData = new FormData();
|
||||
for (const key in obj) {
|
||||
if (obj.hasOwnProperty(key)) {
|
||||
const value = obj[key];
|
||||
if (Array.isArray(value)) {
|
||||
for (const item of value) {
|
||||
formData.append(key, item);
|
||||
}
|
||||
} else {
|
||||
formData.append(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return formData;
|
||||
}
|
||||
private async quest(xhr: XMLHttpRequest, method: "GET" | "POST" | "PUT" = "GET", data: Object, formData: boolean = false) {
|
||||
return new Promise((resolve, reason) => {
|
||||
xhr.onreadystatechange = () => {
|
||||
if (xhr.readyState == 4) {
|
||||
if (xhr.status >= 200 && xhr.status < 300) {
|
||||
// console.log("[Http] 返回", xhr.response);
|
||||
resolve(JSON.parse(xhr.response));
|
||||
} else {
|
||||
reason(xhr.status)
|
||||
}
|
||||
}
|
||||
};
|
||||
xhr.onerror = (error) => {
|
||||
console.error("http request onerror");
|
||||
SubManager.ShowPrompt("网络错误,请检查网络连接");
|
||||
reason(error)
|
||||
};
|
||||
xhr.ontimeout = (e) => {
|
||||
console.error("http request timeout");
|
||||
SubManager.ShowPrompt("网络错误,请检查网络连接");
|
||||
reason(e)
|
||||
}
|
||||
//根据POST和GET方式,选择是否发送msg数据
|
||||
if (formData) {
|
||||
xhr.send(this.objectToFormData(data));
|
||||
} else {
|
||||
if (method == 'POST') {
|
||||
xhr.send(JSON.stringify(data));
|
||||
} else if (method == 'PUT') {
|
||||
xhr.send(JSON.stringify(data));
|
||||
} else {
|
||||
xhr.send();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**是否已登录成功 */
|
||||
public static IsLogin(): boolean {
|
||||
return HttpUnit.LoginState == 2;
|
||||
}
|
||||
|
||||
/**获取背景视频url */
|
||||
public static GetBgVideoUrl(bgname: string): string {
|
||||
// let videoPath = "http://www.confessioncontract.com/data/video/confession-contract/hanako_standby.mp4"
|
||||
let videoPath = `${HttpUnit.BgVideoUrl}${bgname}.mp4`
|
||||
return videoPath
|
||||
|
||||
}
|
||||
|
||||
/**获取心动最大次数 */
|
||||
public static GetXindongMaxCount() {
|
||||
return 5;
|
||||
}
|
||||
/**获取最大相亲次数 */
|
||||
public static GetXiangqinMaxTickets() {
|
||||
//每天重置相亲次数
|
||||
let num1 = HttpUnit.SerSetting.reset_game_day_match ? HttpUnit.SerSetting.reset_game_day_match.value : 5;
|
||||
num1 = parseInt(num1) || 0;
|
||||
//看广告加的相亲次数
|
||||
let num2 = HttpUnit.SerSetting.ad_tickets_times ? HttpUnit.SerSetting.ad_tickets_times.value : 3;
|
||||
num2 = parseInt(num2) || 0;
|
||||
//分享加的相亲次数
|
||||
let num3 = HttpUnit.SerSetting.share_tickets_times ? HttpUnit.SerSetting.share_tickets_times.value : 3;
|
||||
num3 = parseInt(num3) || 0;
|
||||
return num1 + num2 + num3;
|
||||
}
|
||||
/**获取可相亲次数 */
|
||||
public static GetXiangqinTickets() {
|
||||
if (!HttpUnit.UserInfo) {
|
||||
return 0
|
||||
}
|
||||
let num = HttpUnit.UserInfo.ticket || 0;
|
||||
return num;
|
||||
}
|
||||
/**获取可分享次数 - 相亲次数 */
|
||||
public static GetXiangqinShareNum() {
|
||||
if (!HttpUnit.UserInfo) {
|
||||
return 0
|
||||
}
|
||||
let num = HttpUnit.UserInfo.game_share_num || 0;
|
||||
return num;
|
||||
}
|
||||
/**获取可看广告次数 - 相亲次数 */
|
||||
public static GetXiangqinAdNum() {
|
||||
if (!HttpUnit.UserInfo) {
|
||||
return 0
|
||||
}
|
||||
let num = HttpUnit.UserInfo.game_ad_num || 0;
|
||||
return num;
|
||||
}
|
||||
/**获取可分享次数 - 聊天次数 */
|
||||
public static GetTalkShareNum() {
|
||||
if (!HttpUnit.UserInfo) {
|
||||
return 0
|
||||
}
|
||||
let num = HttpUnit.UserInfo.level_share_num || 0;
|
||||
return num;
|
||||
}
|
||||
/**获取可看广告次数 - 聊天次数 */
|
||||
public static GetTalkAdNum() {
|
||||
if (!HttpUnit.UserInfo) {
|
||||
return 0
|
||||
}
|
||||
let num = HttpUnit.UserInfo.level_ad_num || 0;
|
||||
return num;
|
||||
}
|
||||
/**获取看广告增加的聊天次数 */
|
||||
public static GetTalkAdAddNum() {
|
||||
let num = HttpUnit.SerSetting.ad_chat_times ? HttpUnit.SerSetting.ad_chat_times.value : 0;
|
||||
num = parseInt(num) || 0;
|
||||
return num;
|
||||
}
|
||||
/**获取分享增加的聊天次数 */
|
||||
public static GetTalkShareAddNum() {
|
||||
let num = HttpUnit.SerSetting.share_chat_times ? HttpUnit.SerSetting.share_chat_times.value : 0;
|
||||
num = parseInt(num) || 0;
|
||||
return num;
|
||||
}
|
||||
/**获取看广告增加的相亲次数 */
|
||||
public static GetXiangqinAdAddNum() {
|
||||
let num = HttpUnit.SerSetting.ad_tickets_times ? HttpUnit.SerSetting.ad_tickets_times.value : 0;
|
||||
num = parseInt(num) || 0;
|
||||
return num;
|
||||
}
|
||||
/**获取分享增加的相亲次数 */
|
||||
public static GetXiangqinShareAddNum() {
|
||||
let num = HttpUnit.SerSetting.share_tickets_times ? HttpUnit.SerSetting.share_tickets_times.value : 0;
|
||||
num = parseInt(num) || 0;
|
||||
return num;
|
||||
}
|
||||
/**获取昵称 */
|
||||
public static GetNickName() {
|
||||
if (!HttpUnit.UserInfo) {
|
||||
return "游客"
|
||||
}
|
||||
let num = HttpUnit.UserInfo.nickname || "游客";
|
||||
return num;
|
||||
}
|
||||
/**获取ID */
|
||||
public static GetID() {
|
||||
if (!HttpUnit.UserInfo) {
|
||||
return 0
|
||||
}
|
||||
let num = HttpUnit.UserInfo.id || 0;
|
||||
return num;
|
||||
}
|
||||
/**获取抖音侧边栏奖励是否已领取 */
|
||||
public static IsBDSidebarReceive() {
|
||||
if (!HttpUnit.UserInfo) {
|
||||
return false
|
||||
}
|
||||
let isget = HttpUnit.UserInfo.is_receive == 1;
|
||||
return isget;
|
||||
}
|
||||
/**获取友盟关卡记录 */
|
||||
public static GetLevelRecord() {
|
||||
if (!HttpUnit.UserInfo) {
|
||||
return []
|
||||
}
|
||||
let levels = HttpUnit.UserInfo.levels || [];
|
||||
return levels;
|
||||
}
|
||||
/**获取可免费获取珍藏次数 */
|
||||
public static GetZhencangFreeCount() {
|
||||
if (!HttpUnit.UserInfo) {
|
||||
return 0
|
||||
}
|
||||
let num = HttpUnit.UserInfo.free_private_collection || 0;
|
||||
return num;
|
||||
}
|
||||
/**获取珍藏红点是否显示 */
|
||||
public static IsHaveZhencangRedpoint() {
|
||||
if (!HttpUnit.UserInfo) {
|
||||
return false
|
||||
}
|
||||
let isget = HttpUnit.UserInfo.private_collection_mark == 1;
|
||||
return isget;
|
||||
}
|
||||
/**获取回忆红点是否显示 */
|
||||
public static IsHaveHuiyiRedpoint() {
|
||||
if (!HttpUnit.UserInfo) {
|
||||
return false
|
||||
}
|
||||
let isget = HttpUnit.UserInfo.heartbeat_memories_mark == 1;
|
||||
return isget;
|
||||
}
|
||||
|
||||
|
||||
//region 登录
|
||||
private loginCB: Function = null;
|
||||
public login(cb: Function = null) {
|
||||
this.loginCB = cb;
|
||||
SDKManager.login((_loginData) => {
|
||||
console.log("SDK登录成功", _loginData)
|
||||
SDKManager.getUserInfo((userInfo) => {
|
||||
console.log("SDK获取用户信息成功", userInfo)
|
||||
// let serparam = {
|
||||
// platform: _loginData.platform,
|
||||
// code: _loginData.code,
|
||||
// user_info: {nickName:userInfo.nickName, avatarUrl:userInfo.avatarUrl}
|
||||
// }
|
||||
|
||||
_loginData.nickname = userInfo.nickName;
|
||||
_loginData.avatar = userInfo.avatarUrl;
|
||||
|
||||
if (GlobalValue.IsTest) {
|
||||
console.log("登录测试环境")
|
||||
this.loginSer({platform:0, code:12345}, this.initData.bind(this))
|
||||
} else {
|
||||
if (_loginData.code == null) {
|
||||
let uuid = sys.localStorage.getItem('uuid');
|
||||
if (!uuid) {
|
||||
uuid = Date.now(); //当前时间戳
|
||||
sys.localStorage.setItem('uuid', uuid);
|
||||
}
|
||||
_loginData.code = uuid;
|
||||
_loginData.platform = 0
|
||||
// _loginData.code = 123455 //测试代码
|
||||
}
|
||||
console.log("登录正式环境 loginData.code: ", _loginData)
|
||||
this.loginSer(_loginData, this.initData.bind(this))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
private initData(playerData) {
|
||||
// playerData = playerData || {};
|
||||
this.loginCB && this.loginCB(playerData);
|
||||
|
||||
}
|
||||
//登录服务器
|
||||
private async loginSer(msg, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("login", msg, "POST", true);
|
||||
console.log("登录----> 玩家数据:", msg, data)
|
||||
|
||||
if (data && data.code == 1) {
|
||||
HttpUnit.PlayerToken = data.data.token
|
||||
HttpUnit.LoginState = 2
|
||||
console.log("HttpUnit.PlayerToken:", HttpUnit.PlayerToken)
|
||||
//获取玩家信息
|
||||
// this.getUserInfo(cb);
|
||||
HttpUnit.UserInfo = data.data.user_info;
|
||||
//获取配置信息
|
||||
this.getCommSetting();
|
||||
cb && cb(data.data.user_info);
|
||||
}else{
|
||||
console.log("登陆失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`登陆失败,${data.msg}`);
|
||||
} else {
|
||||
SubManager.ShowPrompt(`登陆失败,服务器异常`);
|
||||
}
|
||||
cb && cb(null);
|
||||
}
|
||||
}
|
||||
//获取关卡列表数据
|
||||
public async getLevelList(cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("game/levels", {}, "POST", true);
|
||||
console.log("关卡数据:", data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("获取关卡数据失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**开始关卡*/
|
||||
public async levelStart(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("game/start", msg, "POST", true);
|
||||
console.log("开始新关卡:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("开始关卡失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**推进关卡*/
|
||||
public async sendUserTalk(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("game/propel", msg, "POST", true);
|
||||
console.log("推进关卡:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("推进关卡失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
cb && cb(null);
|
||||
}
|
||||
}
|
||||
/**结束关卡*/
|
||||
public async sendLevelFinish(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("game/end", msg, "POST", true);
|
||||
console.log("结束关卡:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("结束关卡失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**增加次数,更新关卡*/
|
||||
public async addTalkCnt(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("game/update", msg, "POST", true);
|
||||
console.log("更新关卡:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("更新关卡失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**获取AI语音*/
|
||||
public async getAIVoice(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("game/voice", msg, "POST", true);
|
||||
console.log("获取AI语音:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("获取AI语音失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**获取当前聊天状态*/
|
||||
public async getTalkStage(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("game/status", msg, "POST", true);
|
||||
console.log("获取当前聊天状态:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("获取当前聊天状态失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
//非三星通关时继续关卡
|
||||
public async sendGameContinue(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("game/continue", msg, "POST", true);
|
||||
console.log("非三星通关时继续关卡:", data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("非三星通关时继续关卡失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//重新获取用户信息
|
||||
public async getUserData(cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/info", {}, "GET", true);
|
||||
console.log("重新获取用户信息数据:", data)
|
||||
if (data && data.code == 1) {
|
||||
HttpUnit.UserInfo = data.data;
|
||||
Utils.sendInnerMsg(InnerMsgCode.Data_Redpoint, {})
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("重新获取用户信息数据失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
//用户看广告
|
||||
public async setUserAd(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/ad", msg, "POST", true);
|
||||
console.log("看广告数据:", data)
|
||||
if (data && data.code == 1) {
|
||||
HttpUnit.UserInfo = data.data;
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("看广告数据失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
//用户分享
|
||||
public async setUserShare(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/share", msg, "POST", true);
|
||||
console.log("用户分享数据:", data)
|
||||
if (data && data.code == 1) {
|
||||
HttpUnit.UserInfo = data.data;
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("用户分享数据失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
//获取常用配置
|
||||
public async getCommSetting(cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/setting", {}, "GET", true);
|
||||
console.log("获取常用配置数据:", data)
|
||||
if (data && data.code == 1) {
|
||||
HttpUnit.SerSetting = {};
|
||||
for (let i = 0; i < data.data.length; i++) {
|
||||
let item = data.data[i];
|
||||
HttpUnit.SerSetting[item.key] = item;
|
||||
}
|
||||
cb && cb();
|
||||
}else{
|
||||
console.log("获取常用配置数据失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
//看广告解锁关卡
|
||||
public async levelUnlock(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/unlock_level", msg, "POST", true);
|
||||
console.log("看广告解锁关卡:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("看广告解锁关卡失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
//获取抖音侧边栏奖励
|
||||
public async getBDSidebarReward(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/receive_award", msg, "POST", true);
|
||||
console.log("获取抖音侧边栏奖励:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
HttpUnit.UserInfo = data.data;
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("获取抖音侧边栏奖励失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
//添加友盟关卡记录
|
||||
public async sendLevelRecord(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/add_level_record", msg, "POST", true);
|
||||
console.log("添加友盟关卡记录:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
HttpUnit.UserInfo = data.data;
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("添加友盟关卡记录失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
//获得甜蜜暴击效果
|
||||
public async sendTalkStrength(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("game/strength", msg, "POST", true);
|
||||
console.log("获得甜蜜暴击效果:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("获得甜蜜暴击效果失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
//撤回一次聊天
|
||||
public async sendTalkChehui(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("game/cancel", msg, "POST", true);
|
||||
console.log("撤回一次聊天:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("撤回一次聊天失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
//关卡提示事件上报
|
||||
public async sendTipRecord(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/add_record_tip", msg, "POST", true);
|
||||
console.log("关卡提示事件上报:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("关卡提示事件上报失败:"+ data);
|
||||
// if (data && data.msg) {
|
||||
// SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
// }
|
||||
}
|
||||
}
|
||||
//获取AI回复提示语
|
||||
public async getAIAutoAns(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("game/tips", msg, "POST", true);
|
||||
console.log("获取AI回复提示语:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("获取AI回复提示语失败:"+ data);
|
||||
// if (data && data.msg) {
|
||||
// SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
// }
|
||||
}
|
||||
}
|
||||
/**获取历史聊天记录*/
|
||||
public async getTalkJilu(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("game/get_history", msg, "POST", true);
|
||||
console.log("获取历史聊天记录:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("获取历史聊天记录失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**私家珍藏上报 */
|
||||
public async sendZhencangId(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/set_private_collection", msg, "POST", true);
|
||||
console.log("私家珍藏上报:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("私家珍藏上报失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**获取私家珍藏列表 limit:每页条数 page:当前页 type:类型 0待领取 1已领取 level_id:关卡ID*/
|
||||
public async getZhencangList(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/get_private_collection", msg, "POST", true);
|
||||
console.log("获取私家珍藏列表:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("获取私家珍藏列表失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**领取私家珍藏指定奖励*/
|
||||
public async getZhencangReward(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/private_collection_award", msg, "POST", true);
|
||||
console.log("领取私家珍藏指定奖励:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
HttpUnit.UserInfo = data.data;
|
||||
Utils.sendInnerMsg(InnerMsgCode.Data_Redpoint, {})
|
||||
}else{
|
||||
console.log("领取私家珍藏指定奖励失败:", data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**清除私家珍藏红点*/
|
||||
public async readRedpointZhencang(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/clear_private_collection_mark", msg, "POST", true);
|
||||
console.log("清除私家珍藏红点:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
HttpUnit.UserInfo = data.data;
|
||||
Utils.sendInnerMsg(InnerMsgCode.Data_Redpoint, {})
|
||||
}else{
|
||||
console.log("清除私家珍藏红点失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**清除心动回忆红点*/
|
||||
public async readRedpointHuiyi(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/clear_heartbeat_memories_mark", msg, "POST", true);
|
||||
console.log("清除心动回忆红点:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
HttpUnit.UserInfo = data.data;
|
||||
Utils.sendInnerMsg(InnerMsgCode.Data_Redpoint, {})
|
||||
}else{
|
||||
console.log("清除心动回忆红点失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**重新开始关卡时,结束上次进度并上报服务器*/
|
||||
public async sendLevelRestartReport(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("game/restart_report", msg, "POST", true);
|
||||
console.log("关卡结束上次进度:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("关卡结束上次进度失败:"+ data);
|
||||
if (data && data.msg) {
|
||||
SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**心动回忆数据埋点*/
|
||||
public async sendEventTujian(msg:any, cb: Function = null) {
|
||||
let data: any = await HttpUnit.ins.api("user/click_img_event", msg, "POST", true);
|
||||
console.log("心动回忆数据埋点:", msg, data)
|
||||
if (data && data.code == 1) {
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("心动回忆数据埋点失败:"+ data);
|
||||
// if (data && data.msg) {
|
||||
// SubManager.ShowPrompt(`数据异常,${data.msg}`);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//region api
|
||||
public async api(path: string, data: any, method: "GET" | "POST" | "PUT" = "GET", bLock: boolean = false, isFormData: boolean = false) {
|
||||
|
||||
let url = HttpUnit.ServerHttpHost + path;
|
||||
// console.log("[Http] 请求Url:",url, " 方式:", method, " Authorization:", GlobalValue.PlayerToken, " 数据:", JSON.stringify(data) );
|
||||
bLock && this.lock();
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.timeout = 10000;
|
||||
// xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
// if (cc.sys.isNative) {
|
||||
// xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
// }
|
||||
// xhr.setRequestHeader('authorization', Config.TOKEN);
|
||||
//发送数据
|
||||
if (method == 'GET') {
|
||||
url = url + encodeURI(this.jsonToQueryString(data));
|
||||
xhr.open(method, url, true);
|
||||
if (sys.isNative) {
|
||||
xhr.setRequestHeader("Accept-Encoding", "gzip,deflate");
|
||||
xhr.setRequestHeader("content-type", "text/html;charset=utf-8");
|
||||
}
|
||||
} else {
|
||||
xhr.open(method, url, true);
|
||||
xhr.setRequestHeader("Content-type", "application/json");
|
||||
}
|
||||
xhr.setRequestHeader('Authorization', "Bearer " + HttpUnit.PlayerToken);
|
||||
let self = this;
|
||||
return new Promise((resolve, reason) => {
|
||||
self.quest(xhr, method, data, isFormData).then(value => {
|
||||
bLock && self.unlock();
|
||||
resolve(value);
|
||||
}).catch(err => {
|
||||
bLock && self.unlock();
|
||||
resolve(null);
|
||||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 发送请求
|
||||
* @param url 接口地址
|
||||
* @param data 消息字符串 (json格式)
|
||||
* @param method 请求方式
|
||||
* @param bLock 是否锁定屏幕
|
||||
* @param formData 是否formData
|
||||
* @returns
|
||||
*/
|
||||
public async send(url: string, data: any, method: "GET" | "POST" | "PUT" = "GET", bLock: boolean = false, formData: boolean = false) {
|
||||
// console.log("[Http] 请求Url:",url, " 方式:", method, " 数据:", data);
|
||||
bLock && this.lock();
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.timeout = 10000;
|
||||
if (method == 'GET') {
|
||||
url = url + encodeURI(this.jsonToQueryString(data));
|
||||
xhr.open(method, url, true);
|
||||
if (sys.isNative) {
|
||||
xhr.setRequestHeader("Accept-Encoding", "gzip,deflate");
|
||||
xhr.setRequestHeader("content-type", "text/html;charset=utf-8");
|
||||
}
|
||||
} else {
|
||||
xhr.open(method, url, true);
|
||||
xhr.setRequestHeader("Content-type", "application/json");
|
||||
}
|
||||
let self = this;
|
||||
return new Promise((resolve, reason) => {
|
||||
self.quest(xhr, method, data, formData).then(value => {
|
||||
bLock && self.unlock();
|
||||
resolve(value);
|
||||
}).catch(err => {
|
||||
bLock && self.unlock();
|
||||
resolve(null);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
/**解锁屏幕 */
|
||||
private unlock() {
|
||||
// LockScreenUI.ins.unShowloading();
|
||||
// Config.loading.hide2();
|
||||
}
|
||||
|
||||
/**锁屏 */
|
||||
private lock() {
|
||||
// Config.loading.show2();
|
||||
// LockScreenUI.ins.Showloading('网络加载中请稍后...');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "52115c35-aa3a-43c5-b66a-dce8559f819c",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "fd851b67-a13d-46d3-afdc-da282fc40abc",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
/******************************************
|
||||
* @doc 列表Item组件.
|
||||
* 说明:
|
||||
* 1、此组件须配合List组件使用。(配套的配套的..)
|
||||
* @end
|
||||
******************************************/
|
||||
const { ccclass, property, disallowMultiple, menu, executionOrder } = _decorator;
|
||||
import { Node, Component, Enum, Sprite, SpriteFrame, tween, _decorator, EventHandler, Tween, Button, UITransform, Vec3 } from 'cc';
|
||||
import { DEV } from 'cc/env';
|
||||
import ScrollViewList from './ScrollViewList';
|
||||
|
||||
enum SelectedType {
|
||||
NONE = 0,
|
||||
TOGGLE = 1,
|
||||
SWITCH = 2,
|
||||
}
|
||||
|
||||
@ccclass
|
||||
@disallowMultiple()
|
||||
@executionOrder(-5001) //先于List
|
||||
export default class ScrollViewListItem extends Component {
|
||||
//图标
|
||||
@property({ type: Sprite, tooltip: DEV ? '图标' : '' })
|
||||
icon: Sprite = null!;
|
||||
//标题
|
||||
@property({ type: Node, tooltip: DEV ? '标题' : '标题'})
|
||||
title: Node = null!;
|
||||
//选择模式
|
||||
@property({
|
||||
type: Enum(SelectedType),
|
||||
tooltip: DEV ? '选择模式' : '选择模式'
|
||||
})
|
||||
selectedMode: SelectedType = SelectedType.NONE;
|
||||
//被选标志
|
||||
@property({
|
||||
type: Node, tooltip: DEV ? '被选标识' : '被选标识',
|
||||
visible() { return this.selectedMode > SelectedType.NONE }
|
||||
})
|
||||
selectedFlag: Node = null!;
|
||||
//被选择的SpriteFrame
|
||||
@property({
|
||||
type: SpriteFrame, tooltip: DEV ? '被选择的SpriteFrame' : '被选择的SpriteFrame',
|
||||
visible() { return this.selectedMode == SelectedType.SWITCH }
|
||||
})
|
||||
selectedSpriteFrame: SpriteFrame = null!;
|
||||
//未被选择的SpriteFrame
|
||||
_unselectedSpriteFrame: SpriteFrame = null!;
|
||||
//自适应尺寸
|
||||
@property({
|
||||
tooltip: DEV ? '自适应尺寸(宽或高)' : '自适应尺寸(宽或高)',
|
||||
})
|
||||
adaptiveSize: boolean = false;
|
||||
//选择
|
||||
_selected: boolean = false;
|
||||
set selected(val: boolean) {
|
||||
this._selected = val;
|
||||
Tween
|
||||
if (!this.selectedFlag)
|
||||
return;
|
||||
switch (this.selectedMode) {
|
||||
case SelectedType.TOGGLE:
|
||||
this.selectedFlag.active = val;
|
||||
break;
|
||||
case SelectedType.SWITCH:
|
||||
let sp: Sprite = this.selectedFlag.getComponent(Sprite)!;
|
||||
if (sp) {
|
||||
sp.spriteFrame = val ? this.selectedSpriteFrame : this._unselectedSpriteFrame;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
get selected() {
|
||||
return this._selected;
|
||||
}
|
||||
//按钮组件
|
||||
private _btnCom: any;
|
||||
get btnCom() {
|
||||
if (!this._btnCom)
|
||||
this._btnCom = this.node.getComponent(Button);
|
||||
return this._btnCom;
|
||||
}
|
||||
//依赖的List组件
|
||||
public list!: ScrollViewList;
|
||||
//是否已经注册过事件
|
||||
private _eventReg = false;
|
||||
//序列id
|
||||
public listId!: number;
|
||||
|
||||
onLoad() {
|
||||
// //没有按钮组件的话,selectedFlag无效
|
||||
// if (!this.btnCom)
|
||||
// this.selectedMode == SelectedType.NONE;
|
||||
//有选择模式时,保存相应的东西
|
||||
if (this.selectedMode == SelectedType.SWITCH) {
|
||||
let com: Sprite = this.selectedFlag.getComponent(Sprite)!;
|
||||
this._unselectedSpriteFrame = com.spriteFrame!;
|
||||
}
|
||||
}
|
||||
|
||||
onNodeDestroy() {
|
||||
let t: any = this;
|
||||
t.node.off(Node.EventType.SIZE_CHANGED, t._onSizeChange, t);
|
||||
}
|
||||
|
||||
_registerEvent() {
|
||||
let t: any = this;
|
||||
if (!t._eventReg) {
|
||||
if (t.btnCom && t.list.selectedMode > 0) {
|
||||
t.btnCom.clickEvents.unshift(t.createEvt(this, 'onClickThis'));
|
||||
}
|
||||
if (t.adaptiveSize) {
|
||||
t.node.on(Node.EventType.SIZE_CHANGED, t._onSizeChange, this);
|
||||
}
|
||||
t._eventReg = true;
|
||||
}
|
||||
}
|
||||
|
||||
_onSizeChange() {
|
||||
this.list._onItemAdaptive(this.node);
|
||||
}
|
||||
/**
|
||||
* 创建事件
|
||||
* @param {cc.Component} component 组件脚本
|
||||
* @param {string} handlerName 触发函数名称
|
||||
* @param {cc.Node} node 组件所在node(不传的情况下取component.node)
|
||||
* @returns cc.Component.EventHandler
|
||||
*/
|
||||
createEvt(component: Component, handlerName: string, node: Node = null!) {
|
||||
if (!component || !component.isValid)
|
||||
return;//有些异步加载的,节点以及销毁了。
|
||||
component['comName'] = component['comName'] || component.name.match(/\<(.*?)\>/g).pop().replace(/\<|>/g, '');
|
||||
let evt = new EventHandler();
|
||||
evt.target = node || component.node;
|
||||
evt.component = component['comName'];
|
||||
evt.handler = handlerName;
|
||||
return evt;
|
||||
}
|
||||
|
||||
showAni(aniType: number, callFunc: Function, del: boolean) {
|
||||
let t: any = this;
|
||||
let twe: Tween<Node>;
|
||||
let ut: UITransform = t.node.getComponent(UITransform);
|
||||
switch (aniType) {
|
||||
case 0: //向上消失
|
||||
twe = tween(t.node)
|
||||
.to(.2, { scale: new Vec3(.7, .7) })
|
||||
.by(.3, { position: new Vec3(0, ut.height * 2) });
|
||||
break;
|
||||
case 1: //向右消失
|
||||
twe = tween(t.node)
|
||||
.to(.2, { scale: new Vec3(.7, .7) })
|
||||
.by(.3, { position: new Vec3(ut.width * 2, 0) });
|
||||
break;
|
||||
case 2: //向下消失
|
||||
twe = tween(t.node)
|
||||
.to(.2, { scale: new Vec3(.7, .7) })
|
||||
.by(.3, { position: new Vec3(0, ut.height * -2) });
|
||||
break;
|
||||
case 3: //向左消失
|
||||
twe = tween(t.node)
|
||||
.to(.2, { scale: new Vec3(.7, .7) })
|
||||
.by(.3, { position: new Vec3(ut.width * -2, 0) });
|
||||
break;
|
||||
default: //默认:缩小消失
|
||||
twe = tween(t.node)
|
||||
.to(.3, { scale: new Vec3(.1, .1) });
|
||||
break;
|
||||
}
|
||||
|
||||
if (callFunc || del) {
|
||||
twe.call(() => {
|
||||
if (del) {
|
||||
t.list._delSingleItem(t.node);
|
||||
for (let n: number = t.list.displayData.length - 1; n >= 0; n--) {
|
||||
if (t.list.displayData[n].id == t.listId) {
|
||||
t.list.displayData.splice(n, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
callFunc();
|
||||
});
|
||||
}
|
||||
twe.start();
|
||||
}
|
||||
|
||||
onClickThis() {
|
||||
this.list.selectedId = this.listId;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "1c274f61-58c2-4e59-bfb2-93c9eb201361",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
import { InnerMsgCode } from "../Config/InnerMsgCode";
|
||||
import Utils from "./Utils";
|
||||
|
||||
/**长连接*/
|
||||
export default class SocketUnit {
|
||||
private socket: WebSocket | null = null;
|
||||
private isConnected: boolean = false;
|
||||
private reconnetSwt: boolean = false; //重连开关
|
||||
private reconnectCount: number = 0; //重连次数
|
||||
private reconnectMaxCount: number = 3; //最大重连次数
|
||||
private reconnectInterval: number = 1500; //重连间隔时间 ms
|
||||
private reconnectTimer : number = null; //重连定时器
|
||||
private reSendData : any = null; //重连时需要重发的数据
|
||||
private url: string = ""; //连接地址
|
||||
|
||||
private dataReceivedCallback: (data: any) => void = () => { };
|
||||
|
||||
// 连接到服务器
|
||||
public connect(url: string): void {
|
||||
if (this.isConnected) {
|
||||
console.log("SocketUnit: Already connected.");
|
||||
return;
|
||||
}
|
||||
|
||||
this.url = url;
|
||||
this.socket = new WebSocket(url);
|
||||
console.log("SocketUnit: Connecting to -> " + url);
|
||||
|
||||
// 连接成功
|
||||
this.socket.onopen = () => {
|
||||
this.isConnected = true;
|
||||
console.log("SocketUnit: Connection succ.");
|
||||
if (this.reconnetSwt) {
|
||||
console.log("SocketUnit: socket重连成功.");
|
||||
this.stopReconnect();
|
||||
if (this.reSendData) {
|
||||
this.sendData(this.reSendData);
|
||||
this.reSendData = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 接收到消息
|
||||
this.socket.onmessage = (event) => {
|
||||
// console.log("SocketUnit: Received data: ", event);
|
||||
if (this.dataReceivedCallback) {
|
||||
this.dataReceivedCallback(event);
|
||||
}
|
||||
};
|
||||
|
||||
// 连接关闭
|
||||
this.socket.onclose = () => {
|
||||
this.isConnected = false;
|
||||
console.log("SocketUnit: Connection closed.");
|
||||
};
|
||||
|
||||
// 发生错误
|
||||
this.socket.onerror = (error) => {
|
||||
console.error("SocketUnit: WebSocket error:", error);
|
||||
this.isConnected = false;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
// 断开连接
|
||||
public disconnect(): void {
|
||||
if (this.socket && this.isConnected) {
|
||||
this.socket.close();
|
||||
this.isConnected = false;
|
||||
}
|
||||
this.stopReconnect()
|
||||
}
|
||||
|
||||
// 发送数据
|
||||
public sendData(data: string): void {
|
||||
// console.log("SocketUnit: sendData", data);
|
||||
if (this.socket && this.isConnected) {
|
||||
this.socket.send(data);
|
||||
} else {
|
||||
console.error("SocketUnit: Socket is not connected.");
|
||||
this.reSendData = data;
|
||||
this.beginReconnect()
|
||||
}
|
||||
}
|
||||
|
||||
// 设置数据接收回调
|
||||
public onDataReceived(callback: (data: string) => void): void {
|
||||
this.dataReceivedCallback = callback;
|
||||
}
|
||||
|
||||
// 获取连接状态
|
||||
public get isConnectedStatus(): boolean {
|
||||
return this.isConnected;
|
||||
}
|
||||
|
||||
//断线重连
|
||||
private beginReconnect(): void {
|
||||
if (this.reconnetSwt) {
|
||||
return
|
||||
}
|
||||
this.reconnetSwt = true;
|
||||
this.reconnectCount = 0;
|
||||
|
||||
if (this.reconnectTimer == null) {
|
||||
this.reconnectTimer = setInterval(() => {
|
||||
if (this.reconnectCount > this.reconnectMaxCount) {
|
||||
this.reconnectCount = 0;
|
||||
this.stopReconnect();
|
||||
Utils.sendInnerMsg(InnerMsgCode.UI_Socket_Timeout)
|
||||
return;
|
||||
}
|
||||
this._doReconnect();
|
||||
}, this.reconnectInterval);
|
||||
}
|
||||
}
|
||||
private _doReconnect(): void {
|
||||
this.reconnectCount++
|
||||
this.connect(this.url);
|
||||
}
|
||||
// 停止重连
|
||||
private stopReconnect(): void {
|
||||
if (this.reconnectTimer != null) {
|
||||
clearInterval(this.reconnectTimer);
|
||||
this.reconnectTimer = null;
|
||||
}
|
||||
this.reconnetSwt = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "15cf30e1-81e1-4254-ace3-a2647836d26e",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,301 @@
|
||||
import { _decorator, Color, isValid, Label, Node, RichText, Size, Sprite, UITransform, Vec3, view } from "cc";
|
||||
import li_EventManager from "./li_EventManager";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass
|
||||
export default class Utils {
|
||||
//log日志
|
||||
public static Log(msg: string | any, ...subst: any[]) {
|
||||
let IsLocalCSChanel = true
|
||||
if (IsLocalCSChanel) {
|
||||
console.log(msg, subst)
|
||||
}
|
||||
}
|
||||
//警告日志
|
||||
public static Warning(msg: string | any, ...subst: any[]) {
|
||||
let IsLocalCSChanel = true
|
||||
if (IsLocalCSChanel) {
|
||||
console.warn(msg, subst)
|
||||
}
|
||||
}
|
||||
//错误日志
|
||||
public static Error(msg: string | any, ...subst: any[]) {
|
||||
let IsLocalCSChanel = true
|
||||
if (IsLocalCSChanel) {
|
||||
console.error(msg, subst)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//解析节点
|
||||
public static parseNode = function (node: Node, oriObj?: any) {
|
||||
if (!node || !node.children) return;
|
||||
oriObj = oriObj || node;
|
||||
let chs = node.children;
|
||||
for (let i = 0; i < chs.length; i++) {
|
||||
let ch = chs[i];
|
||||
let chName = ch.name;
|
||||
if (chName && chName.length > 0) {
|
||||
try {
|
||||
oriObj[chName] = ch;
|
||||
} catch (error) {
|
||||
//hg_utils.hgLog("chName err:", chName);
|
||||
}
|
||||
}
|
||||
Utils.parseNode(ch, oriObj);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//更换父节点,保留原有的坐标和旋转
|
||||
public static changeNodeParent(node:Node, parentNode:Node) {
|
||||
let world_Q = node.getWorldRotation()
|
||||
let world_pos = node.getWorldPosition()//原来的世界坐标
|
||||
node.setParent(parentNode)
|
||||
node.setRotation(world_Q);
|
||||
node.setWorldPosition(world_pos)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 封装setString方法
|
||||
*/
|
||||
static setString(node: Node, str: string | number) {
|
||||
if (!isValid(node)) return;
|
||||
let lb:any = node.getComponent(Label);
|
||||
if (!lb) return;
|
||||
if(str == null) {str = ""}
|
||||
str += ""
|
||||
lb.string = str;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加富文本
|
||||
* @param node
|
||||
* @param str
|
||||
* @param outLine
|
||||
* @param width
|
||||
* @returns
|
||||
*/
|
||||
static addRichText(node: Node, str: string, outLine: string | null = null, width: number | null = 2,max: number = 0) {
|
||||
if (!node) return;
|
||||
let comp = node.getComponent(RichText);
|
||||
if (!comp) return;
|
||||
str = Utils.replaceAll(str, "</>", "</color>");
|
||||
str = str.replace(/\<\/font\>/g, '</color>');
|
||||
str = Utils.replaceAll(str, "'>", ">");
|
||||
str = Utils.replaceAll(str, "<font", "<");
|
||||
str = Utils.replaceAll(str, "color='", "color=");
|
||||
str = Utils.replaceAll(str, "<br>", "\n");
|
||||
if (outLine) {
|
||||
str = `<outline color=${outLine} width=${width}>${str}</outline>`;
|
||||
}
|
||||
comp.string = str;
|
||||
// let csize:UITransform = comp.node.getComponent(UITransform)!
|
||||
// comp.maxWidth = Math.min(csize.width,max) ;
|
||||
}
|
||||
static replaceAll(str: string, ch1: string, ch2: string) {
|
||||
while (str.indexOf(ch1) >= 0) {
|
||||
str = str.replace(ch1, ch2);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
/**截取字符串,超过长度的用...代替
|
||||
* @param str 要处理的字符串
|
||||
* @param labelLimit 字符串长度限制
|
||||
* @param repStr 超过长度后代替的字符串
|
||||
*/
|
||||
static clampAiAnswer(ansStr: string, labelLimit:number, repStr:string = "...") {
|
||||
// let labelLimit = 20 //字符串长度限制
|
||||
let tempStr: string = "";
|
||||
let tempLen: number = 0;
|
||||
for (let i = 0; i < ansStr.length; i++) {
|
||||
tempLen += ansStr.charCodeAt(i) > 255 ? 2 : 1;
|
||||
if (tempLen > labelLimit) {
|
||||
return tempStr + repStr;
|
||||
}
|
||||
tempStr += ansStr.charAt(i);
|
||||
}
|
||||
return ansStr;
|
||||
}
|
||||
|
||||
|
||||
/**设置节点置灰 */
|
||||
static setNodeGray(node: Node, isGray: boolean, extra: any={}) {
|
||||
if (!isValid(node)) return;
|
||||
//图片
|
||||
let sp:Sprite = node.getComponent(Sprite);
|
||||
if (sp) {
|
||||
sp.grayscale = isGray;
|
||||
}
|
||||
// //文字
|
||||
// let lb:Label = node.getComponent(Label);
|
||||
// if (lb) {
|
||||
// if (isGray) {
|
||||
// lb.color = extra.labClrGray ? extra.labClrGray : Color.GRAY;
|
||||
// } else {
|
||||
// lb.color = extra.labClrWhite ? extra.labClrWhite : Color.WHITE;
|
||||
// }
|
||||
// }
|
||||
//对子节点执行同样操作
|
||||
let children = node.children;
|
||||
for (let i = 0; i < children.length; i++) {
|
||||
Utils.setNodeGray(children[i], isGray, extra);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**适配背景图
|
||||
* @method node 背景图节点
|
||||
* @param mod 适配模式 1=按高度适配 2=按宽度适配
|
||||
*/
|
||||
public static adjustBgPixelRatio(node:Node, mod:number = 1) {
|
||||
let windowSize = view.getVisibleSize();
|
||||
let bgTf = node.getComponent(UITransform)
|
||||
if (bgTf) {
|
||||
if (mod == 1 && bgTf.height < windowSize.height) {
|
||||
let scale = windowSize.height / bgTf.height
|
||||
bgTf.height = bgTf.height * scale
|
||||
bgTf.width = bgTf.width * scale
|
||||
} else if (mod == 2 && bgTf.width < windowSize.width) {
|
||||
let scale = windowSize.width / bgTf.width
|
||||
bgTf.height = bgTf.height * scale
|
||||
bgTf.width = bgTf.width * scale
|
||||
}
|
||||
}
|
||||
}
|
||||
/**适配背景图 按比例缩放 屏幕比设计分辨率小时缩小,反之则不缩放
|
||||
* @param node 背景图节点
|
||||
* @param mod 适配模式 1=按高度适配 2=按宽度适配
|
||||
*/
|
||||
public static adjustBgScaleRatio(node:Node, mod:number = 1) {
|
||||
let windowSize = view.getVisibleSize();
|
||||
let designSize = view.getDesignResolutionSize();
|
||||
if (mod == 1 && windowSize.height < designSize.height) {
|
||||
let scale = windowSize.height / designSize.height
|
||||
node.scale = new Vec3(scale, scale, 1)
|
||||
} else if (mod == 2 && windowSize.width < designSize.width) {
|
||||
let scale = windowSize.width / designSize.width
|
||||
node.scale = new Vec3(scale, scale, 1)
|
||||
}
|
||||
}
|
||||
/**获取屏幕分辨率和设计分辨率的比例
|
||||
* @method mod 适配模式 1=按高度适配 2=按宽度适配
|
||||
*/
|
||||
public static getScaleRatio(mod:number = 1) {
|
||||
let windowSize = view.getVisibleSize();
|
||||
let designSize = view.getDesignResolutionSize();
|
||||
// console.log("游戏分辨率:", windowSize, designSize);
|
||||
if (mod == 1) {
|
||||
return windowSize.height / designSize.height
|
||||
} else {
|
||||
return windowSize.width / designSize.width
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @method 浅复制一个对象
|
||||
* @param source 需要浅复制的对象
|
||||
* 合并对象,如果excludes中没有指明需要排除的字段,target也含有相同的字段,则会被object同名字段值覆盖掉
|
||||
* @param object
|
||||
* @param excludes 需要排除的字段
|
||||
*/
|
||||
static applyIf(object: any, target: any = {}, excludes: Array<string> = []): Object {
|
||||
if (!target) target = {};
|
||||
for (let key in object) {
|
||||
if (object.hasOwnProperty(key)) {
|
||||
if (excludes.indexOf(key) < 0) {
|
||||
target[key] = object[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
/**
|
||||
* @method 浅复制一个对象
|
||||
* @param source 需要浅复制的对象
|
||||
* @return 返回一个新的对象
|
||||
* @log 1. vincent,2018-12-18, func、date、reg 和 err 类型不能正常拷贝
|
||||
*/
|
||||
static easyCopy(source: Object): Object {
|
||||
const newObject = [];
|
||||
return Utils.applyIf(source);
|
||||
}
|
||||
/**复制一个数据表 */
|
||||
static clone(data:any) {
|
||||
return Utils.easyCopy(data);
|
||||
}
|
||||
|
||||
|
||||
/**发送内部事件 */
|
||||
public static sendInnerMsg(innerId: number, param?: any) {
|
||||
li_EventManager.I.onInnerEL(innerId, param);
|
||||
}
|
||||
/**注册内部事件 */
|
||||
public static addInnerEL(innerId: number, i_target, i_callback: Function,) {
|
||||
li_EventManager.I.addInnerEL(innerId, i_callback, i_target);
|
||||
}
|
||||
/**移除内部事件 */
|
||||
public static removeInnerEL(innerId: number, i_target, i_callback: Function) {
|
||||
li_EventManager.I.removeInnerEL(innerId, i_callback, i_target)
|
||||
}
|
||||
|
||||
|
||||
//获取随机数
|
||||
public static getRandomInt(i_start:number, i_end:number) : number {
|
||||
i_start = Math.ceil(i_start);
|
||||
i_end = Math.floor(i_end);
|
||||
return Math.floor(Math.random() * (i_end - i_start + 1)) + i_start;
|
||||
}
|
||||
//数字转字符串,指定位数,位数不足前面补0
|
||||
public static PrefixInt(num, length) {
|
||||
return (Array(length).join('0') + num).slice(-length);
|
||||
}
|
||||
//数字保留几位小数
|
||||
public static DecimalPlaces(num:number, weishu:number) {
|
||||
return num.toFixed(weishu);
|
||||
}
|
||||
|
||||
|
||||
/**获取屏幕分辨率 */
|
||||
public static GetWinSize():Size {
|
||||
return view.getVisibleSize()
|
||||
}
|
||||
|
||||
|
||||
/**获取当前日期,格式YYYY-MM-DD */
|
||||
public static GetNowFormatDay(nowDate: Date | null = null, char: string = "-") {
|
||||
if (nowDate == null) {
|
||||
nowDate = new Date();
|
||||
}
|
||||
let day = nowDate.getDate();
|
||||
let month = nowDate.getMonth() + 1;//注意月份需要+1
|
||||
let year = nowDate.getFullYear();
|
||||
//补全0,并拼接
|
||||
return year + char + Utils.completeDate(month) + char + Utils.completeDate(day);
|
||||
}
|
||||
//补全0
|
||||
private static completeDate(value: number) {
|
||||
return value < 10 ? "0" + value : value;
|
||||
}
|
||||
|
||||
|
||||
//打印消耗时间===================================================================================================
|
||||
private static _eplTime = 0;
|
||||
/**记录当前时间 */
|
||||
public static ProfilerTimeRecord() {
|
||||
Utils._eplTime = new Date().getTime();
|
||||
}
|
||||
/**打印消耗时间 */
|
||||
public static ProfilerTimePrint(key:string = "") {
|
||||
let time = new Date().getTime();
|
||||
let timecha = time - Utils._eplTime;
|
||||
console.log(`${key}消耗时间:${timecha}毫秒`);
|
||||
Utils._eplTime = time;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "871cd90f-732a-4a11-bdbf-bfbcfe6f6163",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
import { _decorator, Node } from 'cc';
|
||||
import li_Component from './li_Component';
|
||||
import Utils from './Utils';
|
||||
import { ViewManager } from '../Manager/ViewManager';
|
||||
|
||||
//界面基类
|
||||
@ccclass
|
||||
export default class li_BaseView extends li_Component {
|
||||
private isScriptComponent = true;//标记判断使用(勿删)
|
||||
|
||||
//命名为根节点,实际上是编辑器里可以看到的最上层节点,实际使用时需要getParent来获取根节点
|
||||
@property({ type: Node, visible: true, displayName: '界面根节点' })
|
||||
protected m_rootNode: Node = null;
|
||||
protected objNodes: any = null;
|
||||
|
||||
|
||||
//----以下接口由子类实现-----------------------------
|
||||
onLoadCT() {
|
||||
}
|
||||
|
||||
|
||||
onLoad() {
|
||||
if (this.m_rootNode == null) {
|
||||
this.m_rootNode = this.node;
|
||||
}
|
||||
|
||||
this.onLoadCT();
|
||||
}
|
||||
|
||||
parseNode() {
|
||||
// this.objNodes = {};
|
||||
// Utils.parseNode(this.node, this.objNodes);
|
||||
// let self = this;
|
||||
// setTimeout(() => {
|
||||
// self.bindBtnClose();
|
||||
// }, 10);
|
||||
}
|
||||
|
||||
private bindBtnClose() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected getRootNode() {
|
||||
// if (this.node) {
|
||||
// let node = this.node;
|
||||
// let parent = node.getParent();
|
||||
// let groundParent = parent && parent.getParent();
|
||||
// while (groundParent) {
|
||||
// node = parent;
|
||||
// parent = groundParent;
|
||||
// groundParent = parent && parent.getParent();
|
||||
// }
|
||||
// return node;
|
||||
// }
|
||||
}
|
||||
|
||||
public close() {
|
||||
ViewManager.I.closeView(this.m_rootNode ? this.m_rootNode : this.node);
|
||||
}
|
||||
|
||||
protected onClose() {
|
||||
// hg_utils.sendInnerMsg(InnerMsgCode.ViewClose)
|
||||
this.close();
|
||||
}
|
||||
|
||||
//实际移除界面
|
||||
protected removeView(): void {
|
||||
if (this.m_rootNode) {
|
||||
this.m_rootNode.destroy();
|
||||
this.m_rootNode.removeFromParent();
|
||||
this.m_rootNode = null
|
||||
}
|
||||
}
|
||||
|
||||
// protected doClose(): void {
|
||||
// this.removeView();
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "24b87ef5-896c-4e31-8af9-6532aeaa8bcd",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { _decorator, Component } from "cc";
|
||||
import li_EventManager from "./li_EventManager";
|
||||
|
||||
const { ccclass } = _decorator;
|
||||
|
||||
@ccclass
|
||||
export default class hg_Component extends Component {
|
||||
protected m_config = {};
|
||||
public ExitViewFunc = null;
|
||||
|
||||
|
||||
//----以下接口由子类实现-----------------------------
|
||||
openUIDataCT(data) {
|
||||
}
|
||||
|
||||
|
||||
onDestroy() {
|
||||
li_EventManager.I.removeAllInnerEL(this);
|
||||
li_EventManager.I.removeAllNetEL(this);
|
||||
this.ExitViewFunc && this.ExitViewFunc();
|
||||
this.onNodeDestroy();
|
||||
this.onSceenDestroy();
|
||||
// li_EventManager.I.onInnerEL(InnerMsgCode.Node_Destroy_Release, this.node);
|
||||
}
|
||||
/**页面传值接收方法 */
|
||||
openUIData(data) {
|
||||
if (data && data.ExitViewFunc) {
|
||||
this.ExitViewFunc = data.ExitViewFunc;
|
||||
}
|
||||
|
||||
//设置截图背景纹理
|
||||
if (data && data.screenShotTex){
|
||||
// let blurMask = this.node.getComponentInChildren(BlurMask);
|
||||
// if (blurMask){
|
||||
// blurMask.setScreenShotTexture(data.screenShotTex)
|
||||
// }
|
||||
}
|
||||
|
||||
this.openUIDataCT(data)
|
||||
}
|
||||
onNodeDestroy() {
|
||||
}
|
||||
onSceenDestroy() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "ca2072cc-d85a-44b8-977d-a8e1314bc220",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
import { _decorator } from "cc";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
//事件管理器
|
||||
@ccclass
|
||||
export default class li_EventManager {
|
||||
private static _Instance: li_EventManager = null;
|
||||
private _netEvent: object = {};
|
||||
private _innerEvent: object = {};
|
||||
|
||||
public static get I(): li_EventManager {
|
||||
if (!li_EventManager._Instance) {
|
||||
li_EventManager._Instance = new li_EventManager();
|
||||
}
|
||||
return li_EventManager._Instance;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**监听网络事件 */
|
||||
public onNetEL(netCodeId: number | string, ...param: any[]) {
|
||||
if (netCodeId) {
|
||||
let handlerArray = this._netEvent[netCodeId];
|
||||
if (!handlerArray) {
|
||||
return;
|
||||
}
|
||||
for (let i = 0; i < handlerArray.length; i++) {
|
||||
const func = handlerArray[i];
|
||||
if (func) {
|
||||
if (func.i_target) {
|
||||
func.apply(func.i_target, param);
|
||||
} else {
|
||||
func(param[0], param[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**添加网络事件 */
|
||||
public addNetEL(netCodeId: number | string, i_callback: any, i_target: any = null): void {
|
||||
if (this._netEvent[netCodeId] == null) {
|
||||
this._netEvent[netCodeId] = [];
|
||||
}
|
||||
i_callback.i_target = i_target;
|
||||
this._netEvent[netCodeId].push(i_callback);
|
||||
}
|
||||
/**移除网络事件 */
|
||||
public removeNetEL(netCodeId: number | string, i_callback: any) {
|
||||
let handlerArray = this._netEvent[netCodeId];
|
||||
if (!handlerArray) return;
|
||||
let index = handlerArray.indexOf(i_callback);
|
||||
if (index >= 0) {
|
||||
handlerArray.splice(index, 1);
|
||||
for (let idx in handlerArray) {
|
||||
if (handlerArray[+idx] == i_callback) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
i_callback.i_target = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**监听本地事件 */
|
||||
public onInnerEL(innerId: number | string, ...param: any[]) {
|
||||
if (this._innerEvent[innerId] == null) {
|
||||
return;
|
||||
}
|
||||
let handlerArray: Array<any> = this._innerEvent[innerId];
|
||||
let i: number = 0;
|
||||
let length: number = handlerArray.length;
|
||||
let handler: Array<any> = null;
|
||||
while (i < length) {
|
||||
handler = handlerArray[i];
|
||||
if (handler == null) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
if ((handler[1] && handler[1]["isValid"] && handler[1]["isValid"] == false) ||
|
||||
(handler[1] && handler[1]["node"] && handler[1]["node"]["isValid"] && handler[1]["node"]["isValid"] == false)) {
|
||||
//当前事件的节点以失效或销毁(事件未移除)
|
||||
handlerArray.splice(i, 1);
|
||||
} else {
|
||||
try {
|
||||
handler[0].apply(handler[1], param);
|
||||
} catch (e) {
|
||||
console.error("innerErr:" + e.stack);
|
||||
}
|
||||
}
|
||||
if (handlerArray.length != length) {
|
||||
length = handlerArray.length;
|
||||
i--;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
/**添加本地事件 */
|
||||
public addInnerEL(innerId: number | string, i_callback: Function, obj: any): void {
|
||||
let handlerArray: Array<any> = this._innerEvent[innerId];
|
||||
if (handlerArray == null) {
|
||||
handlerArray = [];
|
||||
this._innerEvent[innerId] = handlerArray;
|
||||
}
|
||||
//检测是否已经存在
|
||||
for (let i = 0; i < handlerArray.length; i++) {
|
||||
if (handlerArray[i] == null || (handlerArray[i][0] == i_callback && handlerArray[i][1] == obj)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
this._innerEvent[innerId].push([i_callback, obj]);
|
||||
}
|
||||
/**移除本地事件 */
|
||||
public removeInnerEL(innerId: number | string, i_callback: Function, obj: any) {
|
||||
let handlerArray: Array<any> = this._innerEvent[innerId];
|
||||
if (!handlerArray) return;
|
||||
for (let i = 0; i < handlerArray.length; i++) {
|
||||
if (handlerArray[i] == null || (handlerArray[i][0] == i_callback && handlerArray[i][1] == obj)) {
|
||||
handlerArray.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (handlerArray.length == 0) {
|
||||
handlerArray[innerId] = null;
|
||||
delete this._innerEvent[innerId];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 移除某一对象的所有内部监听
|
||||
* @param listenerObj 侦听函数所属对象
|
||||
*/
|
||||
public removeAllInnerEL(listenerObj: any): void {
|
||||
let keys = Object.keys(this._innerEvent);
|
||||
for (let i: number = 0, len = keys.length; i < len; i++) {
|
||||
let type = keys[i];
|
||||
let arr: Array<any> = this._innerEvent[type];
|
||||
if (arr) {
|
||||
for (let j = 0; j < arr.length; j++) {
|
||||
if (arr[j][1] == listenerObj) {
|
||||
arr.splice(j, 1);
|
||||
j--;
|
||||
}
|
||||
}
|
||||
if (arr.length == 0) {
|
||||
delete this._innerEvent[type];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 移除某一对象的所有网络监听
|
||||
* @param listenerObj 侦听函数所属对象
|
||||
*/
|
||||
public removeAllNetEL(listenerObj: any): void {
|
||||
let keys = Object.keys(this._netEvent);
|
||||
for (let i: number = 0, len = keys.length; i < len; i++) {
|
||||
let type = keys[i];
|
||||
let arr: Array<any> = this._netEvent[type];
|
||||
if (arr) {
|
||||
for (let j = 0; j < arr.length; j++) {
|
||||
if (arr[j].i_target == listenerObj) {
|
||||
arr.splice(j, 1);
|
||||
j--;
|
||||
}
|
||||
}
|
||||
if (arr.length == 0) {
|
||||
delete this._netEvent[type];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**移除所有监听 */
|
||||
public removeAllEL() {
|
||||
this._netEvent = {};
|
||||
this._innerEvent = {};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "82b74a90-b0a5-42bd-be17-e5600e03eff5",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "c5863dd7-8d33-4742-ad79-4863dc1f79b6",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,262 @@
|
||||
|
||||
/**
|
||||
* 公共配置文件
|
||||
*/
|
||||
|
||||
export const G_GlobalNode: string = '__GLobal_Node';
|
||||
|
||||
export namespace CommonConfig {
|
||||
//本地保存
|
||||
export enum StorageConfigUtil {
|
||||
BaseData = 'li_' + 1000, // 登录相关
|
||||
Channel = 2000, //渠道相关
|
||||
}
|
||||
export enum StorageConfig {
|
||||
SETTING_SHAKEON = StorageConfigUtil.BaseData + 1,
|
||||
SETTING_MUSIC = StorageConfigUtil.BaseData + 2,
|
||||
SETTING_SOUND = StorageConfigUtil.BaseData + 3,
|
||||
GAME_CITY = StorageConfigUtil.BaseData + 4, //所在省
|
||||
GAME_RANK_CITY = StorageConfigUtil.BaseData + 5, //省排行数据 AI
|
||||
GAME_RANK_USER = StorageConfigUtil.BaseData + 6, //玩家排行数据 AI
|
||||
GAME_RANK_CDTIME = StorageConfigUtil.BaseData + 7, //上次排行数据刷新时间戳 AI
|
||||
GAME_SCORE = StorageConfigUtil.BaseData + 8, //玩家积分
|
||||
GAME_SKIN_ID = StorageConfigUtil.BaseData + 9, //当前选择的皮肤id
|
||||
GAME_PASSLV = StorageConfigUtil.BaseData + 10, //已完成关卡
|
||||
DAILYCHALLENGE_PASSLV = StorageConfigUtil.BaseData + 11, //已完成每日挑战关卡
|
||||
TOOL_KAIKONG = StorageConfigUtil.BaseData + 12, //开孔工具使用过
|
||||
TOOL_RENYIZHI = StorageConfigUtil.BaseData + 13, //任意指工具使用过
|
||||
TOOL_RENYIGUAN = StorageConfigUtil.BaseData + 14, //任意罐工具使用过
|
||||
DD_REGISTTIME = StorageConfigUtil.BaseData + 15, //注册时间字符串
|
||||
DD_LEVELOPER = StorageConfigUtil.BaseData + 16, //进入关卡且首次进度>0时(或第一次操作)
|
||||
GUIDE_MAIN = StorageConfigUtil.BaseData + 17, //主界面引导是否完成
|
||||
GUIDE_TALK = StorageConfigUtil.BaseData + 18, //聊天界面引导是否完成
|
||||
|
||||
DOUYIN_SIDEBAR = StorageConfigUtil.Channel + 1, //抖音渠道侧边栏奖励是否领取
|
||||
}
|
||||
|
||||
|
||||
//UI层级
|
||||
export enum UILayerGroup {
|
||||
Layer_ground = 0,
|
||||
Layer_ui1 = 1,
|
||||
Layer_ui2 = 2,
|
||||
Layer_dialog = 3,
|
||||
Layer_tips = 4,
|
||||
Layer_top = 5,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**关卡配置信息 */
|
||||
export interface I_LevelConfig {
|
||||
/**是关卡场景图资源的名称,注意关卡选择界面选中关卡后展示的场景图资源也是这个 */
|
||||
bgImage: string;
|
||||
/**后续进入关卡后,关卡中需要播放的音乐资源名称 */
|
||||
bgm: string;
|
||||
/**在关卡中,聊天历史信息展示里,角色使用的头像,圆形 80*80 */
|
||||
characterAvatar: string;
|
||||
/**关卡中,提示信息界面里需要展示的角色性格文本 */
|
||||
characterDisposition: string;
|
||||
/**角色聊天切换的表情立绘,这个暂时先不处理,后面我们需要和你沟通下,资源改成英文名看你怎么匹配(Ai 返回的判断还是中文的) */
|
||||
characterEmojiSet: string;
|
||||
/**关卡中,提示信息界面,喜好话题部分需要展示的文本信息 */
|
||||
characterFavoriteTopic: string;
|
||||
/**角色待机资源名称 */
|
||||
characterStandbyPortrait: string;
|
||||
/**角色默认立绘资源名称 */
|
||||
characterFullLengthPortrait: string;
|
||||
/**关卡提示信息界面里使用的角色半身胸像 */
|
||||
characterHalfLengthPortrait: string;
|
||||
/**关卡提示信息界面里,厌恶话题的展示文本信息 */
|
||||
characterHateTopic: string;
|
||||
/**角色名称,注意在关卡选择界面还有关卡中的聊天窗,关卡提示信息界面这几个地方都涉及展示 */
|
||||
characterName: string;
|
||||
/**角色职业设定信息,关卡提示信息界面里的职业部分展示 */
|
||||
characterRole: string;
|
||||
/**关卡选择界面里展示的关卡介绍文本信息 */
|
||||
description: string;
|
||||
/**关卡中对话得到高分后,额外向玩家展示的鼓励信息 */
|
||||
encourageMessage: string;
|
||||
/**结算图片 关卡 0 星,挑战失败的情况下在结算界面展示的 CG 资源名称 */
|
||||
failureCG: string;
|
||||
/**结算图片 关卡 1 星,挑战成功的情况下在结算界面展示的 CG 资源名称 */
|
||||
oneStarCG: string;
|
||||
/**结算图片 关卡 2 星,挑战成功的情况下在结算界面展示的 CG 资源名称 */
|
||||
twoStarCG: string;
|
||||
/**结算图片 关卡 3 星,那么需要展示的 CG 资源对应的名称 */
|
||||
threeStarCG: string;
|
||||
/**关卡中,对话得分特别低的情况下,额外给出的向玩家展示的鼓励信息 */
|
||||
hateMessage: string;
|
||||
/**关卡选择界面,菱形的头像资源名称 */
|
||||
icon: string;
|
||||
/**唯一的关卡 id 信息 */
|
||||
id: string;
|
||||
/**关卡是否已解锁,注意锁定状态仍然能够选择关卡,关卡选择界面中的背景和立绘需要切换做展示,但是玩家不能开启游戏哈 */
|
||||
is_unlock: boolean;
|
||||
/**npc名称 */
|
||||
name: string;
|
||||
/**关卡展示顺序 */
|
||||
no: number;
|
||||
/**关卡解锁需要通关的前置关卡 id 信息,对应id字段 */
|
||||
preLevelId: string;
|
||||
/**进入关卡后,角色发出给到玩家的开场白信息(历史聊天记录页面中也需要显示,一定是角色发出的第一句话) */
|
||||
prologueMessage: string;
|
||||
/**玩家在关卡中,点击随机填充按钮,需要随机选取一句,在输入框中填入,注意填入后不发送,玩家可修改,最终发送的信息还是以玩家点击发送按钮时,填入的信息为主 */
|
||||
randomInputPool: string[];
|
||||
/**关卡进行中的record_id,有值时要先获取一下之前的存档 */
|
||||
record_id: string;
|
||||
/**关卡历史最高分 */
|
||||
score: number;
|
||||
/**关卡历史最高星级 */
|
||||
star: number;
|
||||
/**关卡中,关卡提示信息界面里底部展示的提示信息文本,目前测试数据和关卡介绍信息一致,但后续会区分开来 */
|
||||
tips: string;
|
||||
/**Npc结算对话 3星时 */
|
||||
threeStarSummary: string;
|
||||
/**Npc结算对话 2星时 */
|
||||
twoStarSummary: string;
|
||||
/**Npc结算对话 1星时 */
|
||||
oneStarSummary: string;
|
||||
/**Npc结算对话 0星时 */
|
||||
failureSummary: string;
|
||||
/**Npc表情立绘 害羞 */
|
||||
characterShyPortrait: string;
|
||||
/**Npc表情立绘 厌恶 */
|
||||
characterHatePortrait: string;
|
||||
/**Npc表情立绘 开心 */
|
||||
characterHappyPortrait: string;
|
||||
/**关卡解锁类型 -1=未解锁 0=自动解锁 1=游戏通关解锁 2=手动解锁 */
|
||||
unlock_type: number;
|
||||
/**私家珍藏图片列表 */
|
||||
photoAwards: I_ZhengCangConfig[];
|
||||
/**关卡是否打过 */
|
||||
is_played: boolean;
|
||||
}
|
||||
|
||||
/**私家珍藏配置数据 */
|
||||
export interface I_ZhengCangConfig {
|
||||
/**图片名 */
|
||||
giftImgName: string;
|
||||
/**故事文本列表 */
|
||||
giftStory: string[];
|
||||
/**简述 */
|
||||
giftSummary: string;
|
||||
/**唯一id */
|
||||
id: number;
|
||||
/**对应关卡id */
|
||||
levelId: string;
|
||||
}
|
||||
|
||||
|
||||
/**关卡对话数据 */
|
||||
export interface I_LevelStepData {
|
||||
/**当前聊天次数 */
|
||||
current_cnt: number;
|
||||
/**结束评分 */
|
||||
end_star: number;
|
||||
/**关卡id */
|
||||
id: string;
|
||||
/**最大聊天次数 */
|
||||
max_cnt: number;
|
||||
/**当前状态 0:成功 1:进行中 2:失败 3:剩余聊天次数不足 */
|
||||
status: number;
|
||||
/**可用总聊天次数 */
|
||||
total_cnt: number;
|
||||
/**心动次数 */
|
||||
heartbeat_cnt: number;
|
||||
/**剩余可看广告次数 */
|
||||
ad_num: number;
|
||||
/**剩余可分享次数 */
|
||||
share_num: number;
|
||||
/**剩余可撤回次数 */
|
||||
can_use_cancel_cnt: number;
|
||||
/**剩余可暴击次数 */
|
||||
can_use_strength_cnt: number;
|
||||
/**暴击是否生效 */
|
||||
is_strength_take_effect: boolean;
|
||||
/**甜蜜暴击已用次数 */
|
||||
first_strength?: number;
|
||||
/**撤回已用次数 */
|
||||
first_cancel?: number;
|
||||
}
|
||||
|
||||
|
||||
/**npc长连接中的回复 */
|
||||
export interface I_NpcTalkBack {
|
||||
/**ai表情 */
|
||||
aiEmoji:string;
|
||||
/**ai回复 */
|
||||
aiResponse:string;
|
||||
/**ai评分 */
|
||||
aiScore:number;
|
||||
/**ai基础评分 */
|
||||
aiBaseScore:number;
|
||||
/**ai额外加分 */
|
||||
aiAdditionalScore:number;
|
||||
/**是否完成 */
|
||||
isFinished:boolean;
|
||||
/**聊天次数 */
|
||||
sourceCnt:number;
|
||||
/**玩家发的文本 */
|
||||
userInput: string;
|
||||
/**评价 -1=未生成 0=心动 1=普通 2=厌恶 */
|
||||
judgement: number;
|
||||
}
|
||||
|
||||
|
||||
/**对话历史记录数据 */
|
||||
export interface I_TalkRecordInfo {
|
||||
/**对话内容 */
|
||||
talk: string;
|
||||
/**是否是玩家自己 */
|
||||
isMe: boolean;
|
||||
/**评分 小于0时不显示 */
|
||||
score: number;
|
||||
/**基础分 */
|
||||
scoreBase: number;
|
||||
/**额外加分 */
|
||||
scoreAdditional: number;
|
||||
}
|
||||
|
||||
|
||||
/**玩家信息数据 */
|
||||
export interface I_UserInfo {
|
||||
id: number;
|
||||
score: number;
|
||||
status: number;
|
||||
/**头像url */
|
||||
avatar: string;
|
||||
/**昵称 */
|
||||
nickname: string;
|
||||
/**剩余进入关卡次数 */
|
||||
ticket: number;
|
||||
/**剩余可看广告次数 - 进入关卡 */
|
||||
game_ad_num: number;
|
||||
/**剩余可分享次数 - 进入关卡 */
|
||||
game_share_num: number;
|
||||
/**剩余可看广告次数 - 聊天 */
|
||||
level_ad_num: number;
|
||||
/**剩余可分享次数 - 聊天 */
|
||||
level_share_num: number;
|
||||
/**抖音侧边栏奖励是否已领取 0未领取 1已领取 */
|
||||
is_receive: number;
|
||||
/**友盟关卡记录 */
|
||||
levels: any[];
|
||||
/**私家珍藏红点标记 0不显示 1显示 */
|
||||
private_collection_mark: number;
|
||||
/**心动回忆红点标记 0不显示 1显示 */
|
||||
heartbeat_memories_mark: number;
|
||||
/**剩余可免费获取珍藏的次数 */
|
||||
free_private_collection: number;
|
||||
// [property: string]: any;
|
||||
}
|
||||
|
||||
/**心动回忆数据 */
|
||||
export interface I_HuiyiInfo {
|
||||
/**关卡id */
|
||||
lvId: string;
|
||||
/**星数 */
|
||||
star: number;
|
||||
/**是否解锁 */
|
||||
unlock: boolean;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "6c96f9fa-f617-4268-a8ca-51b0a5d4749f",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
//消息枚举
|
||||
export enum InnerMsgCode {
|
||||
GM_UI_Close, //关闭GM界面
|
||||
SceneLayerBgUp, //刷新场景背景图
|
||||
UI_Talk_Back, //从聊天界面返回
|
||||
UI_BD_Sidebar, //抖音侧边栏状态刷新
|
||||
UI_Socket_Timeout, //socket超时
|
||||
UI_TalkStageUp, //更改聊天阶段
|
||||
UI_ResartGame, //重新开始游戏
|
||||
UI_ShowPrompt, //显示飘字提示
|
||||
UI_Tj_huiyi_Pic, //显示回忆大图
|
||||
UI_Tj_huiyi_Lv, //前往回忆对应关卡
|
||||
|
||||
Data_UserInfo_Up, //用户信息更新
|
||||
Data_NpcTalkBack, //NPC对话返回
|
||||
Data_LevelStarUp, //刷新关卡星级
|
||||
Data_ChehuiUp, //撤回消息
|
||||
Data_BDSidebarReward, //抖音侧边栏奖励领取消息
|
||||
Data_Redpoint, //红点刷新消息
|
||||
Data_ZhencangUp, //私家珍藏更新消息
|
||||
|
||||
BgVideo_Ready, //背景视频准备完成
|
||||
BgVideo_End, //背景视频播放完毕
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "1bc13137-7eab-49f4-8e92-41fd6d4ee2eb",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import { _decorator } from "cc";
|
||||
import Utils from "../Common/Utils";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
//配置表管理器
|
||||
@ccclass('Resource')
|
||||
export default class Resource {
|
||||
|
||||
static instance: Resource = null;
|
||||
private _config = {};//策划数值表
|
||||
|
||||
static getInstance() {
|
||||
if (!this.instance) this.init();
|
||||
return this.instance;
|
||||
}
|
||||
//初始化
|
||||
static init() {
|
||||
if (!this.instance) {
|
||||
this.instance = new Resource();
|
||||
(window as any).Resource = this;
|
||||
}
|
||||
}
|
||||
|
||||
/**加载子包时添加 */
|
||||
static addSubJsonConfig(name, tab) {
|
||||
let _instance = this.getInstance();
|
||||
if (!_instance._config) _instance._config = {};
|
||||
if (!_instance._config[name]) _instance._config[name] = {};
|
||||
let json_SS, json_key1, json_key2
|
||||
for (const key in tab) {
|
||||
json_SS = tab[key];
|
||||
if (!json_key1){
|
||||
json_key1 = json_SS.id ? "id" : "ID" //默认用id
|
||||
}
|
||||
json_key2 = json_SS[json_key1]
|
||||
_instance._config[name][json_key2] = json_SS;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表数据
|
||||
* @param table 表名
|
||||
*/
|
||||
static getConfig(table: string) {
|
||||
if (!table) {
|
||||
Utils.Log('策划数值表名为空!', table);
|
||||
return null;
|
||||
}
|
||||
let _instance = this.getInstance();
|
||||
if (!_instance._config) _instance._config = {};
|
||||
if (!_instance._config[table]) {
|
||||
// _instance._config[table] = {};
|
||||
Utils.Error("配置表未找到:", table)
|
||||
return null;
|
||||
}
|
||||
let config_D = _instance._config[table];
|
||||
return config_D;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "34d91d70-8aac-44b4-9b4a-1a60185b2235",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.2.0",
|
||||
"importer": "directory",
|
||||
"imported": true,
|
||||
"uuid": "3ee266d2-ad99-4c4b-ac1d-ad22ff39a0f1",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
import { _decorator, Node, AudioClip, AudioSource, director, assetManager } from "cc";
|
||||
import PlayerDataManager from "./PlayerDataManager";
|
||||
import ResManager from "./ResManager";
|
||||
import Resource from "../Config/Resource";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
//音频管理器
|
||||
@ccclass('AudioManager')
|
||||
export default class AudioManager {
|
||||
|
||||
private _audoSource: AudioSource;
|
||||
private curBgId: number = -1; //当前播放中的背景乐id 用于记录
|
||||
private lastBgId: number = -1; //上次播放的背景乐id 用于音乐开关切换时播放
|
||||
private curBgId_confirm: number = -1; //当前播放中的背景乐id 实际播放
|
||||
|
||||
|
||||
private static _I: AudioManager = null;
|
||||
public static get I(): AudioManager {
|
||||
if (!AudioManager._I) {
|
||||
AudioManager._I = new AudioManager();
|
||||
AudioManager._I.init();
|
||||
}
|
||||
return AudioManager._I;
|
||||
}
|
||||
|
||||
private init(){
|
||||
let audioMgr = new Node();
|
||||
audioMgr.name = '__audioMgr__';
|
||||
director.getScene().addChild(audioMgr);
|
||||
director.addPersistRootNode(audioMgr);
|
||||
this._audoSource = audioMgr.addComponent(AudioSource);
|
||||
}
|
||||
|
||||
|
||||
/**播放音效 */
|
||||
PlayEffect(sound, volume:number=1.0) {
|
||||
if (!sound) return;
|
||||
if (!PlayerDataManager.I.IsSoundOn) {
|
||||
return;
|
||||
}
|
||||
|
||||
let cfgs = Resource.getConfig("Sound")
|
||||
if (!cfgs[sound]) return;
|
||||
|
||||
let path = `Sound/${cfgs[sound].AssetName}`
|
||||
console.log("PlayEffect:", sound, path)
|
||||
ResManager.I.getBundleAudio(path, (res: AudioClip)=>{
|
||||
this._audoSource.playOneShot(res, volume)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**播放背景乐 */
|
||||
PlayMusic(sound, loop:boolean = true, volume:number=1.0) {
|
||||
if (!sound || sound == this.curBgId_confirm) return;
|
||||
|
||||
let cfgs = Resource.getConfig("Music")
|
||||
if (!cfgs[sound]) return;
|
||||
|
||||
this.lastBgId = sound;
|
||||
|
||||
if (!PlayerDataManager.I.IsMusicOn) {
|
||||
return; //这个放在记录后面判断,防止开关打开时,没有记录
|
||||
}
|
||||
|
||||
this.StopMusic()
|
||||
this.curBgId = sound;
|
||||
this.curBgId_confirm = sound;
|
||||
let path = `Music/${cfgs[sound].AssetName}`
|
||||
console.log("PlayMusic:", sound, path)
|
||||
ResManager.I.getBundleAudio(path, (res: AudioClip)=>{
|
||||
this._audoSource.clip = res
|
||||
this._audoSource.play()
|
||||
this._audoSource.volume = volume
|
||||
this._audoSource.loop = loop
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**播放远程背景乐 */
|
||||
PlayRemoteMusic(url, loop:boolean = true, volume:number=1.0) {
|
||||
console.log(`下载远程背景乐: url= ${url}`)
|
||||
assetManager.loadRemote<AudioClip>(url, { ext: '.mp3'}, (err, res: AudioClip) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
console.log(`播放远程背景乐: res= ${res}`)
|
||||
this.StopMusic()
|
||||
this._audoSource.clip = res
|
||||
this._audoSource.play()
|
||||
this._audoSource.volume = volume
|
||||
this._audoSource.loop = loop
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**停止播放背景乐 */
|
||||
StopMusic(){
|
||||
this._audoSource.stop()
|
||||
this.curBgId = -1
|
||||
this.curBgId_confirm = -1
|
||||
}
|
||||
|
||||
// 重新播放背景乐
|
||||
ReplayMusic(){
|
||||
if (this.curBgId > -1)
|
||||
return
|
||||
if (this.lastBgId < 0)
|
||||
return
|
||||
|
||||
this.PlayMusic(this.lastBgId)
|
||||
}
|
||||
|
||||
/**暂停播放背景乐 */
|
||||
PauseMusic(){
|
||||
this._audoSource.pause()
|
||||
}
|
||||
|
||||
|
||||
/**继续播放背景乐 */
|
||||
ResumeMusic(){
|
||||
this._audoSource.play()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "06da91f8-e0f7-4750-a5c3-4ecfb135e827",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,572 @@
|
||||
import { _decorator, Node, v2 } from "cc";
|
||||
import { I_LevelConfig, I_LevelStepData, I_NpcTalkBack, I_TalkRecordInfo, I_ZhengCangConfig } from "../Config/CommonConfig";
|
||||
import SocketUnit from "../Common/SocketUnit";
|
||||
import Utils from "../Common/Utils";
|
||||
import { InnerMsgCode } from "../Config/InnerMsgCode";
|
||||
import SubManager from "../../Sub/SubManager";
|
||||
import HttpUnit from "../Common/HttpUnit";
|
||||
import { SDKManager } from "../Channel/SDKManager";
|
||||
import { VideoRoleType } from "../Common/GlobalValue";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
|
||||
/**聊天状态 */
|
||||
export enum E_TalkStatusType {
|
||||
succ = 0, //成功
|
||||
talking = 1, //对话中
|
||||
fail = 2, //失败
|
||||
noCount = 3, //次数不足
|
||||
}
|
||||
|
||||
|
||||
/**对话阶段 */
|
||||
export enum E_TalkStage {
|
||||
/**开场白 */
|
||||
prologue,
|
||||
/**我的对话 */
|
||||
myTalk,
|
||||
/**等待NPC回复 */
|
||||
waitNpcTalk,
|
||||
/**NPC对话 */
|
||||
npcTalk,
|
||||
/**NPC固定话术 */
|
||||
npcFixedTalk,
|
||||
/**更新对话状态 */
|
||||
upTalkStatus,
|
||||
}
|
||||
|
||||
|
||||
//游戏管理器
|
||||
@ccclass('GameManager')
|
||||
export default class GameManager {
|
||||
|
||||
private static _I: GameManager = null;
|
||||
public static get I(): GameManager {
|
||||
if (!GameManager._I) {
|
||||
GameManager._I = new GameManager();
|
||||
GameManager._I.init();
|
||||
}
|
||||
return GameManager._I;
|
||||
}
|
||||
|
||||
private init(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
//region长连接相关
|
||||
private _socket: SocketUnit = null;
|
||||
/**连接长连接 */
|
||||
public connetSorcket(record_id:string){
|
||||
this.disconnectSocket();
|
||||
this._socket = new SocketUnit();
|
||||
// this._socket.connect(`ws://47.119.190.199:20190/game/ai/response/${record_id}`);
|
||||
let socketUrl = `${HttpUnit.SocketHost}${record_id}`
|
||||
this._socket.connect(socketUrl);
|
||||
this._socket.onDataReceived((data: any) => {
|
||||
let resData = JSON.parse(data.data)
|
||||
if (GameManager.curStage != E_TalkStage.waitNpcTalk) return
|
||||
if (resData.isFinished) {
|
||||
console.log("npc回复:", resData)
|
||||
GameManager.CurNpcTalkData = resData
|
||||
Utils.sendInnerMsg(InnerMsgCode.Data_NpcTalkBack, resData || {})
|
||||
}
|
||||
})
|
||||
}
|
||||
/**断开长连接 */
|
||||
public disconnectSocket(){
|
||||
if (this._socket){
|
||||
this._socket.disconnect();
|
||||
}
|
||||
this._socket = null;
|
||||
}
|
||||
/**获取npc回复 */
|
||||
public getNpcTalkBack(data: any){
|
||||
if (this._socket){
|
||||
let str = JSON.stringify(data)
|
||||
this._socket.sendData(str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//region关卡配置
|
||||
private static _levelCfgArray: I_LevelConfig[] = [];
|
||||
private static _levelCfgMap: {[key: string]: I_LevelConfig} = {};
|
||||
private static _zhencangMap: {[key: string]: I_ZhengCangConfig} = {};
|
||||
/**设置关卡配置数据 */
|
||||
public static SetLevelCfg(levelCfg: any[]) {
|
||||
GameManager._levelCfgArray = levelCfg;
|
||||
let info:any = null;
|
||||
let umRecords = [] //友盟解锁关卡记录
|
||||
let recordLvs = HttpUnit.GetLevelRecord(); //友盟已记录的关卡
|
||||
for (let i = 0; i < levelCfg.length; i++) {
|
||||
info = levelCfg[i];
|
||||
GameManager._levelCfgMap[info.id] = info;
|
||||
//判断是否已记录
|
||||
if (info.is_unlock) {
|
||||
if (recordLvs.indexOf(info.id) == -1){
|
||||
umRecords.push(info.id)
|
||||
}
|
||||
}
|
||||
//私家珍藏配置
|
||||
if (info.photoAwards) {
|
||||
for (let j = 0; j < info.photoAwards.length; j++) {
|
||||
let photoAwards = info.photoAwards[j];
|
||||
photoAwards.levelId = info.id;
|
||||
GameManager._zhencangMap[photoAwards.id+""] = photoAwards;
|
||||
}
|
||||
}
|
||||
}
|
||||
//友盟记录关卡
|
||||
if (umRecords.length > 0 && SDKManager.umaSwt()){
|
||||
let umr = umRecords.join(',')
|
||||
HttpUnit.ins.sendLevelRecord({level_ids:umr}, (_data)=>{
|
||||
console.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
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
/**设置关卡星级 */
|
||||
public static SetLevelStar(levelId: string, star: number) {
|
||||
let cfg = GameManager._levelCfgMap[levelId];
|
||||
if (cfg) {
|
||||
cfg.star = star;
|
||||
}
|
||||
}
|
||||
|
||||
/**获取关卡配置 */
|
||||
public static getLevelCfg(levelId: string): I_LevelConfig {
|
||||
return GameManager._levelCfgMap[levelId];
|
||||
}
|
||||
/**获取关卡配置列表 */
|
||||
public static getLevelCfgList(): I_LevelConfig[] {
|
||||
return GameManager._levelCfgArray;
|
||||
}
|
||||
|
||||
/**获取npc表情图片 */
|
||||
public static GetNpcEmoPic(emoStr: string): any {
|
||||
let rolePath = ""
|
||||
let emoName = ""
|
||||
let videoType = VideoRoleType.None
|
||||
let lvCfg = GameManager.getLevelCfg(GameManager.CurLevelId);
|
||||
if (emoStr == "" || emoStr == null) {
|
||||
rolePath = `role/${lvCfg.characterFullLengthPortrait}` //循环,图片没有待机,用default,视频用待机
|
||||
emoName = lvCfg.characterStandbyPortrait
|
||||
videoType = VideoRoleType.Idle
|
||||
|
||||
}else if (emoStr.includes("害羞")) {
|
||||
rolePath = `emo_1/${lvCfg.characterShyPortrait}`
|
||||
emoName = lvCfg.characterShyPortrait
|
||||
videoType = VideoRoleType.emo
|
||||
} else if (emoStr.includes("开心")) {
|
||||
rolePath = `emo_2/${lvCfg.characterHappyPortrait}`
|
||||
emoName = lvCfg.characterHappyPortrait
|
||||
videoType = VideoRoleType.emo
|
||||
} else if (emoStr.includes("厌恶")) {
|
||||
rolePath = `emo_3/${lvCfg.characterHatePortrait}`
|
||||
emoName = lvCfg.characterHatePortrait
|
||||
videoType = VideoRoleType.emo
|
||||
} else {
|
||||
rolePath = `role/${lvCfg.characterFullLengthPortrait}` //默认表情
|
||||
emoName = lvCfg.characterFullLengthPortrait
|
||||
videoType = VideoRoleType.emo
|
||||
}
|
||||
return {rolePath:rolePath, emoName:emoName, videoType:videoType};
|
||||
}
|
||||
|
||||
|
||||
//regionAI语音开关
|
||||
private static _AIVoiceSwt: boolean = false;
|
||||
/**设置是否显示AI语音 */
|
||||
public static set AIVoiceSwt(value: boolean) {
|
||||
GameManager._AIVoiceSwt = value;
|
||||
}
|
||||
/**获取是否显示AI语音 */
|
||||
public static get AIVoiceSwt(): boolean {
|
||||
return GameManager._AIVoiceSwt;
|
||||
}
|
||||
|
||||
|
||||
//region当前关卡ID
|
||||
private static _curLevelId: string = "";
|
||||
/**设置当前关卡ID */
|
||||
public static set CurLevelId(value: string) {
|
||||
GameManager._curLevelId = value;
|
||||
}
|
||||
/**获取当前关卡ID */
|
||||
public static get CurLevelId(): string {
|
||||
return GameManager._curLevelId;
|
||||
}
|
||||
|
||||
|
||||
//region流程id
|
||||
private static _recordId: string = "";
|
||||
/**设置当前关卡流程ID */
|
||||
public static set RecordId(value: string) {
|
||||
GameManager._recordId = value;
|
||||
}
|
||||
/**获取当前关卡流程ID */
|
||||
public static get RecordId(): string {
|
||||
return GameManager._recordId;
|
||||
}
|
||||
|
||||
|
||||
//region当前步骤数据
|
||||
private static _curLevelData: I_LevelStepData = null;
|
||||
/**设置当前步骤数据 */
|
||||
public static set CurLevelData(value: I_LevelStepData) {
|
||||
GameManager._curLevelData = value;
|
||||
}
|
||||
/**获取当前步骤数据 */
|
||||
public static get CurLevelData(): I_LevelStepData {
|
||||
return GameManager._curLevelData;
|
||||
}
|
||||
|
||||
|
||||
//region NPC回复数据
|
||||
private static _curNpcTalkData: I_NpcTalkBack = null;
|
||||
private static _npcTalkDataAry: I_NpcTalkBack[] = [];
|
||||
/**设置当前NPC回复数据 */
|
||||
public static set CurNpcTalkData(value: I_NpcTalkBack) {
|
||||
GameManager._curNpcTalkData = value;
|
||||
GameManager._npcTalkDataAry.push(value);
|
||||
}
|
||||
/**获取当前NPC回复数据 */
|
||||
public static get CurNpcTalkData(): I_NpcTalkBack {
|
||||
return GameManager._curNpcTalkData;
|
||||
}
|
||||
/**移除最后一条NPC回复数据 */
|
||||
public static removeLastNpcTalkData() {
|
||||
if (GameManager._npcTalkDataAry.length > 0) {
|
||||
let talkData = GameManager._npcTalkDataAry.pop();
|
||||
//心动次数也要减
|
||||
if (talkData.judgement == 0) {
|
||||
if (GameManager.xindongCishu > 0) {
|
||||
GameManager.xindongCishu = GameManager.xindongCishu - 1
|
||||
}
|
||||
}
|
||||
if (talkData.aiScore >= 90) {
|
||||
if (GameManager.jidongCishu > 0) {
|
||||
GameManager.jidongCishu = GameManager.jidongCishu - 1
|
||||
}
|
||||
}
|
||||
if (talkData.aiScore >= 100) {
|
||||
if (GameManager.gandongCishu > 0) {
|
||||
GameManager.gandongCishu = GameManager.gandongCishu - 1
|
||||
}
|
||||
}
|
||||
}
|
||||
if (GameManager._npcTalkDataAry.length == 0) {
|
||||
GameManager._curNpcTalkData = null;
|
||||
} else {
|
||||
GameManager._curNpcTalkData = GameManager._npcTalkDataAry[GameManager._npcTalkDataAry.length - 1];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//region 当前NPC话术文本
|
||||
private static _curNpcFixedTalkText: string = "";
|
||||
/**设置当前NPC话术文本 */
|
||||
public static set CurNpcFixedTalkText(value: string) {
|
||||
GameManager._curNpcFixedTalkText = value;
|
||||
}
|
||||
/**获取当前NPC话术文本 */
|
||||
public static get CurNpcFixedTalkText(): string {
|
||||
return GameManager._curNpcFixedTalkText;
|
||||
}
|
||||
|
||||
|
||||
//region关卡步骤评分
|
||||
private static stepScoreList: number[] = [];
|
||||
/**设置关卡步骤评分 */
|
||||
public static AddStepScore(score: number) {
|
||||
GameManager.stepScoreList.push(score);
|
||||
}
|
||||
/**移除最后一步骤评分 */
|
||||
public static RemoveLastSetpScore() {
|
||||
let cellLen = GameManager.stepScoreList.length;
|
||||
if (cellLen > 0) {
|
||||
GameManager.stepScoreList.pop();
|
||||
}
|
||||
}
|
||||
/**清空关卡步骤评分 */
|
||||
public static ClearStepScore() {
|
||||
GameManager.stepScoreList = [];
|
||||
}
|
||||
/**获取最新得分 */
|
||||
public static getCurStepScore(): number {
|
||||
if (GameManager.stepScoreList.length == 0) return 0;
|
||||
return GameManager.stepScoreList[GameManager.stepScoreList.length - 1];
|
||||
}
|
||||
/**获取关卡当前评分
|
||||
* @returns [总分,平均分]
|
||||
*/
|
||||
public static getGameScore(): [number,number] {
|
||||
let totalScore = 0;
|
||||
let totalStep = 0;
|
||||
GameManager.stepScoreList.forEach((score) => {
|
||||
totalScore += score;
|
||||
totalStep++;
|
||||
})
|
||||
let scoreRate = totalStep > 0 ? Math.floor(totalScore / totalStep) : 0;
|
||||
return [totalScore, scoreRate];
|
||||
}
|
||||
|
||||
|
||||
//region对话记录
|
||||
private static talkRecordList: I_TalkRecordInfo[] = [];
|
||||
/**添加对话记录 */
|
||||
public static AddTalkRecord(record: I_TalkRecordInfo) {
|
||||
GameManager.talkRecordList.push(record);
|
||||
}
|
||||
/**移除最后一条对话记录 */
|
||||
public static RemoveLastRoundTalkRecord() {
|
||||
let cellLen = GameManager.talkRecordList.length;
|
||||
if (cellLen > 1) {
|
||||
for (let i=cellLen-1; i>=0; i--) {
|
||||
let talkCell = GameManager.talkRecordList.pop();
|
||||
if (talkCell.isMe) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**清空对话记录 */
|
||||
public static ClearTalkRecord() {
|
||||
GameManager.talkRecordList = [];
|
||||
}
|
||||
/**获取对话记录 */
|
||||
public static get TalkRecordList(): I_TalkRecordInfo[] {
|
||||
return GameManager.talkRecordList;
|
||||
}
|
||||
|
||||
|
||||
//region 当前对话阶段
|
||||
private static _curStage: E_TalkStage = E_TalkStage.prologue;
|
||||
/**获取当前对话阶段 */
|
||||
public static get curStage(): E_TalkStage {
|
||||
return GameManager._curStage;
|
||||
}
|
||||
/**设置当前对话阶段 */
|
||||
public static TurnToStage(value: E_TalkStage, force: boolean = false) {
|
||||
if (GameManager._curStage == value && !force) return;
|
||||
GameManager._curStage = value;
|
||||
Utils.sendInnerMsg(InnerMsgCode.UI_TalkStageUp, {})
|
||||
}
|
||||
|
||||
|
||||
//region 已用对话轮次
|
||||
private static _srouceCnt: number = 0;
|
||||
/**获取已用对话轮次 */
|
||||
public static get srouceCnt(): number {
|
||||
return GameManager._srouceCnt;
|
||||
}
|
||||
/**设置已用对话轮次 */
|
||||
public static set srouceCnt(value: number) {
|
||||
GameManager._srouceCnt = value;
|
||||
}
|
||||
|
||||
//region 心动次数 70分
|
||||
private static _xindongCishu: number = 0;
|
||||
/**获取心动次数 */
|
||||
public static get xindongCishu(): number {
|
||||
return GameManager._xindongCishu;
|
||||
}
|
||||
/**设置心动次数 */
|
||||
public static set xindongCishu(value: number) {
|
||||
GameManager._xindongCishu = value;
|
||||
}
|
||||
|
||||
//region 激动次数 90分
|
||||
private static _jidongCishu: number = 0;
|
||||
/**获取心动次数 */
|
||||
public static get jidongCishu(): number {
|
||||
return GameManager._jidongCishu;
|
||||
}
|
||||
/**设置心动次数 */
|
||||
public static set jidongCishu(value: number) {
|
||||
GameManager._jidongCishu = value;
|
||||
}
|
||||
|
||||
//region 感动次数 100分
|
||||
private static _gandongCishu: number = 0;
|
||||
/**获取心动次数 */
|
||||
public static get gandongCishu(): number {
|
||||
return GameManager._gandongCishu;
|
||||
}
|
||||
/**设置心动次数 */
|
||||
public static set gandongCishu(value: number) {
|
||||
GameManager._gandongCishu = value;
|
||||
}
|
||||
|
||||
//region npc固定话术喜欢次数
|
||||
private static _npcFixTalkCountXihuan: number = 0;
|
||||
/**获取npc固定话术喜欢次数 */
|
||||
public static get npcFixTalkCountXihuan(): number {
|
||||
return GameManager._npcFixTalkCountXihuan;
|
||||
}
|
||||
/**设置npc固定话术喜欢次数 */
|
||||
public static set npcFixTalkCountXihuan(value: number) {
|
||||
GameManager._npcFixTalkCountXihuan = value;
|
||||
}
|
||||
|
||||
//region npc固定话术讨厌次数
|
||||
private static _npcFixTalkCountTaoyan: number = 0;
|
||||
/**获取npc固定话术讨厌次数 */
|
||||
public static get npcFixTalkCountTaoyan(): number {
|
||||
return GameManager._npcFixTalkCountTaoyan;
|
||||
}
|
||||
/**设置npc固定话术讨厌次数 */
|
||||
public static set npcFixTalkCountTaoyan(value: number) {
|
||||
GameManager._npcFixTalkCountTaoyan = value;
|
||||
}
|
||||
|
||||
|
||||
//region 结束关卡
|
||||
/**结束关卡 */
|
||||
public static EndGame() {
|
||||
GameManager.I.disconnectSocket();
|
||||
GameManager.ClearStepScore()
|
||||
GameManager.ClearTalkRecord()
|
||||
GameManager.CurLevelId = ""
|
||||
GameManager.RecordId = ""
|
||||
GameManager.CurLevelData = null
|
||||
GameManager.CurNpcTalkData = null
|
||||
GameManager._npcTalkDataAry = []
|
||||
GameManager.srouceCnt = 0
|
||||
GameManager.xindongCishu = 0
|
||||
GameManager.jidongCishu = 0
|
||||
GameManager.gandongCishu = 0
|
||||
GameManager.npcFixTalkCountXihuan = 0
|
||||
GameManager.npcFixTalkCountTaoyan = 0
|
||||
GameManager._curStage = E_TalkStage.prologue
|
||||
}
|
||||
|
||||
|
||||
//region 重新开始关卡
|
||||
/**重新开始关卡 */
|
||||
public static RestartGame() {
|
||||
if (GameManager.CurLevelId == "") {
|
||||
return
|
||||
}
|
||||
GameManager._restartGameStep1()
|
||||
}
|
||||
//重开步骤1 刷新用户数据
|
||||
private static _restartGameStep1() {
|
||||
HttpUnit.ins.getUserData((userData) => {
|
||||
GameManager._restartGameStep2()
|
||||
})
|
||||
}
|
||||
//重开步骤2 刷新关卡数据
|
||||
private static _restartGameStep2() {
|
||||
HttpUnit.ins.getLevelList((levelList) => {
|
||||
if (levelList) {
|
||||
GameManager.SetLevelCfg(levelList)
|
||||
GameManager._restartGameStep3()
|
||||
}
|
||||
})
|
||||
}
|
||||
//重开步骤3 判断条件
|
||||
private static _restartGameStep3() {
|
||||
if (HttpUnit.GetXiangqinTickets() <= 0) {
|
||||
SubManager.ShowPrompt("今日相亲次数已用完");
|
||||
return;
|
||||
}
|
||||
let level_id = GameManager.CurLevelId
|
||||
HttpUnit.ins.levelStart({level_id:level_id}, (data) => {
|
||||
GameManager.EndGame()
|
||||
GameManager.CurLevelId = level_id
|
||||
GameManager.CurLevelData = data.level
|
||||
GameManager.RecordId = data.record_id
|
||||
GameManager.I.connetSorcket(data.record_id) //连接socket
|
||||
Utils.sendInnerMsg(InnerMsgCode.UI_ResartGame, {})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//region 可领取的私家珍藏列表
|
||||
private static _zhencangCanget: any[] = []
|
||||
/**可领取的私家珍藏列表 */
|
||||
static get zhencangCanget() {
|
||||
return this._zhencangCanget
|
||||
}
|
||||
/**刷新可领取的私家珍藏列表 */
|
||||
static refreshZhencangCanget() {
|
||||
HttpUnit.ins.getZhencangList({limit:10, page:1, type:0}, (data) => {
|
||||
if (data) {
|
||||
this._zhencangCanget = data.data || []
|
||||
Utils.sendInnerMsg(InnerMsgCode.Data_ZhencangUp, {})
|
||||
}
|
||||
})
|
||||
}
|
||||
/**解锁一个私家珍藏id */
|
||||
static UnlockZhencang(record_id:string, levelId: string) {
|
||||
console.log("解锁私家珍藏:", record_id, levelId)
|
||||
HttpUnit.ins.getZhencangList({limit:999, page:1, type:1}, (data) => {
|
||||
if (data){
|
||||
this._doUnlockZhencang(data.data, record_id, levelId)
|
||||
}
|
||||
})
|
||||
}
|
||||
//解锁私家珍藏 zclist:已解锁列表 record_id:本次聊天id levelId:关卡id
|
||||
private static _doUnlockZhencang(zclist:any, record_id:string, levelId: string) {
|
||||
zclist = zclist || []
|
||||
|
||||
let cangetList = GameManager.zhencangCanget
|
||||
let lvCfg = this.getLevelCfg(levelId)
|
||||
let lockAry:any[] = [] //未解锁的私家珍藏列表
|
||||
for (let i=0; i<lvCfg.photoAwards.length; i++) {
|
||||
let item = lvCfg.photoAwards[i]
|
||||
let ishave = false //是否已解锁
|
||||
//先看可领取列表里有没有
|
||||
if (!ishave) {
|
||||
for (let j=0; j<cangetList.length; j++) {
|
||||
let zc = cangetList[j]
|
||||
if (zc.img == item.id) {
|
||||
ishave = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
//再看已解锁列表里有没有
|
||||
if (!ishave) {
|
||||
for (let j=0; j<zclist.length; j++) {
|
||||
let zc = zclist[j]
|
||||
if (zc.img == item.id) {
|
||||
ishave = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!ishave) {
|
||||
lockAry.push(item)
|
||||
}
|
||||
}
|
||||
if (lockAry.length > 0) {
|
||||
let randIdx = Utils.getRandomInt(0, lockAry.length-1)
|
||||
let item = lockAry[randIdx]
|
||||
HttpUnit.ins.sendZhencangId({record_id:record_id, level_id:levelId, img:item.id}, (_data) => {
|
||||
if (_data) {
|
||||
console.log("获得珍藏卡:", item)
|
||||
GameManager.refreshZhencangCanget()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
/**获取珍藏配置信息 */
|
||||
public static getZhencangCfg(zcId: string) {
|
||||
return GameManager._zhencangMap[zcId+""];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "d43c28d8-5808-43a8-8b84-1f0bbf7f5fa4",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import { _decorator, Node, AudioClip, AudioSource, director, PhysicsSystem2D, EPhysics2DDrawFlags, Vec2, PHYSICS_2D_PTM_RATIO, v2 } from "cc";
|
||||
import PlayerDataManager from "./PlayerDataManager";
|
||||
import ResManager from "./ResManager";
|
||||
import Resource from "../Config/Resource";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
//物理系统管理器
|
||||
//通过编辑器主菜单中的 项目 -> 项目设置 -> 功能裁剪 切换物理模块的使用。轻量 Builtin 物理系统和强大的 Box2D 物理系统
|
||||
@ccclass('PhysicsManager')
|
||||
export default class PhysicsManager {
|
||||
|
||||
private static _I: PhysicsManager = null;
|
||||
public static get I(): PhysicsManager {
|
||||
if (!PhysicsManager._I) {
|
||||
PhysicsManager._I = new PhysicsManager();
|
||||
PhysicsManager._I.init();
|
||||
}
|
||||
return PhysicsManager._I;
|
||||
}
|
||||
|
||||
private init(){
|
||||
// const system = PhysicsSystem2D.instance;
|
||||
// system.fixedTimeStep = 1/30;// 物理步长,默认 fixedTimeStep 是 1/60
|
||||
// system.velocityIterations = 8;// 每次更新物理系统处理速度的迭代次数,默认为 10
|
||||
// system.positionIterations = 8;// 每次更新物理系统处理位置的迭代次数,默认为 10
|
||||
|
||||
// this.setPhysicsEnable(false)
|
||||
}
|
||||
|
||||
|
||||
//设置是否开启物理系统
|
||||
public setPhysicsEnable(swt: boolean) {
|
||||
PhysicsSystem2D.instance.enable = swt; //是否启用物理系统
|
||||
}
|
||||
|
||||
//设置物理调试信息是否显示
|
||||
public setDrawFalgEnable(swt: boolean) {
|
||||
if (swt) {
|
||||
this.setPhysicsEnable(true);
|
||||
PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.Shape | EPhysics2DDrawFlags.Joint
|
||||
} else {
|
||||
PhysicsSystem2D.instance.debugDrawFlags = EPhysics2DDrawFlags.None;
|
||||
}
|
||||
}
|
||||
|
||||
//设置重力方向
|
||||
public setPhysicsGravity(dir: Vec2) {
|
||||
PhysicsSystem2D.instance.gravity = v2(dir.x * PHYSICS_2D_PTM_RATIO, dir.y * PHYSICS_2D_PTM_RATIO);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "76c070bf-f7c6-41ca-9d75-83f35bb97ab8",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
import { _decorator, sys } from "cc";
|
||||
import Utils from "../Common/Utils";
|
||||
import { CommonConfig } from "../Config/CommonConfig";
|
||||
import AudioManager from "./AudioManager";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('PlayerDataManager')
|
||||
export default class PlayerDataManager {
|
||||
private static _I: PlayerDataManager = null;
|
||||
public static get I(): PlayerDataManager {
|
||||
if (!PlayerDataManager._I) {
|
||||
PlayerDataManager._I = new PlayerDataManager();
|
||||
PlayerDataManager._I.init()
|
||||
}
|
||||
return PlayerDataManager._I;
|
||||
}
|
||||
|
||||
private isShakeOn: boolean = true; //震动
|
||||
private isMusicOn: boolean = true; //音乐
|
||||
private isSoundOn: boolean = true; //音效
|
||||
private guideMainFinished: boolean = false; //主界面引导是否完成
|
||||
private guideTalkFinished: boolean = false; //聊天界面引导是否完成
|
||||
|
||||
|
||||
public get IsShakeOn() : boolean {return this.isShakeOn;}
|
||||
public get IsMusicOn() : boolean {return this.isMusicOn;}
|
||||
public get IsSoundOn() : boolean {return this.isSoundOn;}
|
||||
public get GuideMainFinished() : boolean {return this.guideMainFinished;}
|
||||
public get GuideTalkFinished() : boolean {return this.guideTalkFinished;}
|
||||
|
||||
|
||||
private init(){
|
||||
this.InitPlayerData();
|
||||
}
|
||||
public initEmpty(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
private InitPlayerData() {
|
||||
// this.isShakeOn = PlayerDataManager.getForKey(CommonConfig.StorageConfig.SETTING_SHAKEON, true)
|
||||
// this.isMusicOn = PlayerDataManager.getForKey(CommonConfig.StorageConfig.SETTING_MUSIC, true)
|
||||
// this.isSoundOn = PlayerDataManager.getForKey(CommonConfig.StorageConfig.SETTING_SOUND, true)
|
||||
this.guideMainFinished = PlayerDataManager.getForKey(CommonConfig.StorageConfig.GUIDE_MAIN, false)
|
||||
this.guideTalkFinished = PlayerDataManager.getForKey(CommonConfig.StorageConfig.GUIDE_TALK, false)
|
||||
console.log("InitPlayerData", `guideMain=${this.guideMainFinished}, guideTalk=${this.guideTalkFinished}`)
|
||||
}
|
||||
|
||||
|
||||
public SetMusicOn(bo: boolean) {
|
||||
if (this.isMusicOn == bo)
|
||||
return
|
||||
this.isMusicOn = bo
|
||||
PlayerDataManager.setForKey(CommonConfig.StorageConfig.SETTING_MUSIC, bo)
|
||||
if (bo)
|
||||
AudioManager.I.ReplayMusic()
|
||||
else
|
||||
AudioManager.I.StopMusic()
|
||||
}
|
||||
|
||||
public SetSoundOn(bo: boolean) {
|
||||
if (this.isSoundOn == bo)
|
||||
return
|
||||
this.isSoundOn = bo
|
||||
PlayerDataManager.setForKey(CommonConfig.StorageConfig.SETTING_SOUND, bo)
|
||||
}
|
||||
|
||||
/**主界面引导完成*/
|
||||
public SetGuideMainFinish(bo: boolean) {
|
||||
if (this.guideMainFinished == bo)
|
||||
return
|
||||
this.guideMainFinished = bo
|
||||
PlayerDataManager.setForKey(CommonConfig.StorageConfig.GUIDE_MAIN, bo)
|
||||
}
|
||||
/**聊天界面引导完成*/
|
||||
public SetGuideTalkFinish(bo: boolean) {
|
||||
if (this.guideTalkFinished == bo)
|
||||
return
|
||||
this.guideTalkFinished = bo
|
||||
PlayerDataManager.setForKey(CommonConfig.StorageConfig.GUIDE_TALK, bo)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 类型内部处理,外层部分类型 isBindingId //标识位数据需要绑定 playerid的时候,默认值为 true,若是传 false,则不进入绑定
|
||||
* */
|
||||
static setForKey(key: number | string, data) {
|
||||
if (!key || void (0) === data) {
|
||||
Utils.Log("key can`t nil");
|
||||
return;
|
||||
}
|
||||
key = key + "";
|
||||
sys.localStorage.setItem(key, JSON.stringify(data));
|
||||
}
|
||||
|
||||
static getForKey(key: number | string, defaultVal): any {
|
||||
if (!key) {
|
||||
Utils.Log("key can`t nil");
|
||||
return;
|
||||
}
|
||||
key = key + "";
|
||||
let jsonObj;
|
||||
try {
|
||||
let str = sys.localStorage.getItem(key);
|
||||
try {
|
||||
jsonObj = JSON.parse(str);
|
||||
} catch (error) {
|
||||
jsonObj = str;
|
||||
}
|
||||
} catch (error) {
|
||||
Utils.Log(`getForKey--->>>解析${key}的值的时候报错`);
|
||||
}
|
||||
if (jsonObj == null){
|
||||
jsonObj = defaultVal;
|
||||
}
|
||||
return jsonObj;
|
||||
}
|
||||
|
||||
static removeForKey(key: number | string): void {
|
||||
key = key + "";
|
||||
sys.localStorage.setItem(key, "");
|
||||
}
|
||||
|
||||
/**清档 */
|
||||
static clearAll(): void {
|
||||
sys.localStorage.clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "54a36d09-f9e0-4044-b065-7237b4a5aa85",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,462 @@
|
||||
import { _decorator, AssetManager, assetManager, Component, Node, director, Prefab, resources, Sprite, SpriteFrame, Texture2D, v2, SpriteAtlas, ImageAsset, instantiate, AudioClip, Asset, JsonAsset, Material } from 'cc';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('ResManager')
|
||||
export default class ResManager {
|
||||
private static _I: ResManager = null;
|
||||
public static get I(): ResManager {
|
||||
if (!ResManager._I) {
|
||||
ResManager._I = new ResManager();
|
||||
}
|
||||
return ResManager._I;
|
||||
}
|
||||
|
||||
|
||||
/**切换场景 */
|
||||
enterScene(i_sceneName: string) {
|
||||
director.loadScene(i_sceneName, () => { });
|
||||
}
|
||||
|
||||
|
||||
/** 场景-跳转到主界面场景*/
|
||||
goMainScene() {
|
||||
this.enterScene('MainScene');
|
||||
}
|
||||
|
||||
/** 场景-跳转到游戏场景*/
|
||||
goGameScene() {
|
||||
this.enterScene('GameScene');
|
||||
}
|
||||
|
||||
/** 场景-跳转到自定义场景*/
|
||||
goCustomScene(sceneName:string) {
|
||||
this.enterScene(sceneName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// /**加载bundle */
|
||||
// loadBundle(bundleName, cb?) {
|
||||
// let bundle = assetManager.getBundle(bundleName)
|
||||
// if (bundle) { cb && cb(bundle); return; }
|
||||
// assetManager.loadBundle(bundleName, (err: Error, _bundle: AssetManager.Bundle) => {
|
||||
// if (!err) {
|
||||
// cb && cb(_bundle);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
/**移除bundle */
|
||||
removeBundle(bundleName) {
|
||||
let bundle = assetManager.getBundle(bundleName);
|
||||
if (bundle) {
|
||||
bundle.releaseAll();
|
||||
assetManager.removeBundle(bundle);
|
||||
}
|
||||
}
|
||||
/**预加载bundle中的PB*/
|
||||
preLoadSubpackagePrefab(url: string, cb) {
|
||||
let bundle = assetManager.getBundle("PB");
|
||||
if (bundle){
|
||||
bundle.preload(url, Prefab, (err, res) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
cb && cb();
|
||||
});
|
||||
} else {
|
||||
assetManager.loadBundle("PB", (err: Error, _bundle: AssetManager.Bundle) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
this.preLoadSubpackagePrefab(url, cb);
|
||||
});
|
||||
}
|
||||
}
|
||||
/**预加载bundle中的文件*/
|
||||
preLoadSubpackageFile(url: string, pkgName: string, ftype, succCB, failCB) {
|
||||
let bundle = assetManager.getBundle(pkgName);
|
||||
if (bundle){
|
||||
bundle.preload(url, ftype, (err, res) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
failCB && failCB(err);
|
||||
return
|
||||
}
|
||||
succCB && succCB();
|
||||
});
|
||||
} else {
|
||||
assetManager.loadBundle(pkgName, (err: Error, _bundle: AssetManager.Bundle) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
failCB && failCB(err);
|
||||
return
|
||||
}
|
||||
this.preLoadSubpackageFile(url, pkgName, ftype, succCB, failCB);
|
||||
});
|
||||
}
|
||||
}
|
||||
/** 加载bundle中的PB*/
|
||||
loadSubpackagePrefab(url: string, cb) {
|
||||
let bundle = assetManager.getBundle("PB");
|
||||
if (bundle){
|
||||
bundle.load(url, Prefab, (err, res: Prefab) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
let cc_N = instantiate(res);
|
||||
cb && cb(cc_N);
|
||||
});
|
||||
}else{
|
||||
assetManager.loadBundle("PB", (err: Error, _bundle: AssetManager.Bundle) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
this.loadSubpackagePrefab(url, cb);
|
||||
});
|
||||
}
|
||||
}
|
||||
/**获取pb节点 */
|
||||
getPrefab(path: string, cb: Function, target: Node) {
|
||||
this.loadSubpackagePrefab(path, (pb: Prefab) => {
|
||||
if (target && !target.isValid) {
|
||||
pb.destroy()
|
||||
return;
|
||||
}
|
||||
pb['path'] = path;
|
||||
cb && cb(pb);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/** 加载bundle中的PB*/
|
||||
loadSubpackage3DModel(url: string, cb) {
|
||||
let bundle = assetManager.getBundle("Model3D");
|
||||
if (bundle){
|
||||
bundle.load(url, Prefab, (err, res: Prefab) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
let cc_N = instantiate(res);
|
||||
cb && cb(cc_N);
|
||||
});
|
||||
}else{
|
||||
assetManager.loadBundle("Model3D", (err: Error, _bundle: AssetManager.Bundle) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
this.loadSubpackage3DModel(url, cb);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** 改变图片--bundle资源 sprite-frame类型的图片*/
|
||||
changeBundleSpriteFrame(spt: Sprite, url: string, packageName: string, cb: Function = null) {
|
||||
if (!spt || !url) return;
|
||||
let spttemp:any = spt
|
||||
spttemp.frameUrl = url
|
||||
let bundle = assetManager.getBundle(packageName);
|
||||
if (bundle){
|
||||
bundle.load(url + "/spriteFrame", SpriteFrame, (err, res: SpriteFrame) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
if (!spt.isValid) {
|
||||
return;
|
||||
}
|
||||
if (spttemp.frameUrl != url) {
|
||||
return;
|
||||
}
|
||||
spt.spriteFrame = res;
|
||||
cb && cb(res);
|
||||
});
|
||||
}else{
|
||||
assetManager.loadBundle(packageName, (err: Error, _bundle: AssetManager.Bundle) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
this.changeBundleSpriteFrame(spt, url, packageName, cb);
|
||||
});
|
||||
}
|
||||
}
|
||||
/** 改变图片--bundle资源 texture类型的图片*/
|
||||
changeBundleTexture(spt: Sprite, url: string, packageName: string, cb: Function = null) {
|
||||
if (!spt || !url) return;
|
||||
let bundle = assetManager.getBundle(packageName);
|
||||
if (bundle){
|
||||
bundle.load(url + "/texture", Texture2D, (err, res: Texture2D) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
if (!spt.isValid) {
|
||||
return;
|
||||
}
|
||||
let spriteFrame = new SpriteFrame()
|
||||
spriteFrame.texture = res
|
||||
spt.spriteFrame = spriteFrame;
|
||||
cb && cb(res);
|
||||
});
|
||||
}else{
|
||||
assetManager.loadBundle(packageName, (err: Error, _bundle: AssetManager.Bundle) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
this.changeBundleTexture(spt, url, packageName, cb);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** 加载bundle中的音频文件*/
|
||||
getBundleAudio(url: string, cb) {
|
||||
let bundle = assetManager.getBundle("Audio");
|
||||
if (bundle){
|
||||
bundle.load(url, AudioClip, (err, res: AudioClip) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
cb && cb(res);
|
||||
});
|
||||
}else{
|
||||
assetManager.loadBundle("Audio", (err: Error, _bundle: AssetManager.Bundle) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
this.getBundleAudio(url, cb);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** 加载bundle中的配置表*/
|
||||
loadSubpackageDataTable(url: string, cb) {
|
||||
let bundle = assetManager.getBundle("DataTable");
|
||||
if (bundle){
|
||||
bundle.load(url, JsonAsset, (err, res: JsonAsset) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
cb && cb(res);
|
||||
});
|
||||
}else{
|
||||
assetManager.loadBundle("DataTable", (err: Error, _bundle: AssetManager.Bundle) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
this.loadSubpackagePrefab(url, cb);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//region 加载远程音频
|
||||
/** 加载远程资源*/
|
||||
loadRemoteAudio(url: string, cb: Function = null) {
|
||||
assetManager.loadRemote<AudioClip>(url, (err, res: AudioClip) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
return
|
||||
}
|
||||
cb && cb(res);
|
||||
})
|
||||
}
|
||||
|
||||
/** 加载远程资源*/
|
||||
// private loadRemoteRes1(url1: string, suffix: string = 'png', cb) {
|
||||
// let tempStrArr: Array<string> = url1.split(".");
|
||||
// let aimStr = url1;
|
||||
// if (tempStrArr.length > 1) {
|
||||
// aimStr = tempStrArr[0];
|
||||
// }
|
||||
// let url: string = `http://tk3h5.hgwl710.com/Fish/DEV/TS/Res/`;
|
||||
// url += aimStr + '.' + suffix;
|
||||
// if (url1.includes("://")) { url = url1 }
|
||||
// assetManager.loadRemote<ImageAsset>(url, { cacheEnabled: true }, (err, res: ImageAsset) => {
|
||||
// if (!err) {
|
||||
// const spriteFrame = new SpriteFrame();
|
||||
// const texture = new Texture2D();
|
||||
// texture.image = res;
|
||||
// spriteFrame.texture = texture;
|
||||
// cb && cb(spriteFrame);
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
|
||||
//region 加载远程图片
|
||||
/**
|
||||
* 获取远程图片资源并设置
|
||||
* @param spt 要设置的节点
|
||||
* @param url url地址
|
||||
* @param suffix 图片后缀名
|
||||
* @param cb 回调函数
|
||||
*/
|
||||
changeRemoteSpriteFrame(spt: Sprite, url: string, suffix: string = 'png', cb: Function = null) {
|
||||
if (!spt || !url) return;
|
||||
assetManager.loadRemote<ImageAsset>(url, {ext: '.'+suffix}, (err, res: ImageAsset) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
if (!spt.isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
const spriteFrame = new SpriteFrame();
|
||||
const texture = new Texture2D();
|
||||
texture.image = res;
|
||||
spriteFrame.texture = texture;
|
||||
|
||||
spt.spriteFrame = spriteFrame;
|
||||
cb && cb(res);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/** 加载resources里的PB path:不带后缀*/
|
||||
private loadResourcePrefab(path: string, cb) {
|
||||
resources.load(path, Prefab, (err, res: Prefab) => {
|
||||
if (!err) {
|
||||
cb && cb(res);
|
||||
} else {
|
||||
// loader.rlease(path);
|
||||
}
|
||||
})
|
||||
}
|
||||
/** 加载resources里的图片*/
|
||||
private loadResourceRes(path: string, cb) {
|
||||
resources.load(path, ImageAsset, (err, res: ImageAsset) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
cb && cb(res);
|
||||
})
|
||||
}
|
||||
/** 加载resources里图集里的图片*/
|
||||
// 加载 SpriteAtlas(图集),并且获取其中的一个 SpriteFrame
|
||||
// 注意 atlas 资源文件(plist)通常会和一个同名的图片文件(png)放在一个目录下, 所以需要在第二个参数指定资源类型
|
||||
private loadResourceAtlas(sptName: string, path: string, cb) {
|
||||
resources.load(path, SpriteAtlas, (err, res: SpriteAtlas) => {
|
||||
const frame = res.getSpriteFrame(sptName);
|
||||
if (!err) {
|
||||
cb && cb(frame);
|
||||
} else {
|
||||
// loader.release(path);
|
||||
}
|
||||
});
|
||||
}
|
||||
/** 改变图片--resources里sprite-frame类型的图片*/
|
||||
changeResourceSpriteFrame(spt: Sprite, path: string, cb: Function = null) {
|
||||
if (!spt || !path) return;
|
||||
resources.load(path + "/spriteFrame", SpriteFrame, (err, res: SpriteFrame) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
if (!spt.isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
spt.spriteFrame = res;
|
||||
cb && cb(res);
|
||||
})
|
||||
}
|
||||
/** 改变图片--resources里texture类型的图片*/
|
||||
changeResourceTexture(spt: Sprite, path: string, cb: Function = null) {
|
||||
if (!spt || !path) return;
|
||||
resources.load(path + "/texture", Texture2D, (err, res: Texture2D) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
if (!spt.isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
let spriteFrame = new SpriteFrame()
|
||||
spriteFrame.texture = res
|
||||
spt.spriteFrame = spriteFrame;
|
||||
cb && cb(res);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//设置图片置灰
|
||||
SetGray(spt: Sprite, isGray: boolean) {
|
||||
//cc.assetManager.builtins.getBuiltin("material", "builtin-" + name)
|
||||
if (isGray) {
|
||||
let bundle = assetManager.getBundle("Materials");
|
||||
if (bundle){
|
||||
bundle.load("ui_sprite_gray", Material, (err, res: Material) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
// spt.setSharedMaterial(res, 0)
|
||||
spt.customMaterial = res
|
||||
});
|
||||
}else{
|
||||
assetManager.loadBundle("Materials", (err: Error, _bundle: AssetManager.Bundle) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
this.SetGray(spt, isGray);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// spt.setSharedMaterial(null, 0)
|
||||
spt.customMaterial = null
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**设置图片模糊*/
|
||||
SetBlur(spt: Sprite, isBule: boolean) {
|
||||
if (isBule) {
|
||||
let bundle = assetManager.getBundle("Materials");
|
||||
if (bundle){
|
||||
bundle.load("mohu", Material, (err, res: Material) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
// spt.setSharedMaterial(res, 0)
|
||||
spt.customMaterial = res
|
||||
});
|
||||
}else{
|
||||
assetManager.loadBundle("Materials", (err: Error, _bundle: AssetManager.Bundle) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
this.SetBlur(spt, isBule);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// spt.setSharedMaterial(null, 0)
|
||||
spt.customMaterial = null
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "2ec035aa-2267-461c-a381-5e10ec6df354",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
import { _decorator, Node, Camera, Component, director, game, instantiate, Prefab, RenderTexture, view, resources, macro } from "cc";
|
||||
import Utils from "../Common/Utils";
|
||||
import GameRootUI from "../Common/GameRootUI";
|
||||
import ResManager from "./ResManager";
|
||||
import { CommonConfig } from "../Config/CommonConfig";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
@ccclass('ViewManager')
|
||||
export class ViewManager extends Component {
|
||||
private static _I: ViewManager = null;
|
||||
public static get I(): ViewManager {
|
||||
if (!ViewManager._I) {
|
||||
ViewManager._I = new ViewManager();
|
||||
}
|
||||
return ViewManager._I;
|
||||
}
|
||||
|
||||
private m_viewList = [];
|
||||
private m_viewListData = {};
|
||||
|
||||
start() {
|
||||
|
||||
}
|
||||
|
||||
update(deltaTime: number) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
private openIdx = 0;
|
||||
private openViewByPrefab(err, i_prefab: Prefab | Node, i_openInfo, callBack = null, path, type: string = '') {
|
||||
if (err) {
|
||||
Utils.Log('打开界面时加载资源出错:' + err, path);
|
||||
return;
|
||||
}
|
||||
let t_node:any = instantiate(i_prefab);
|
||||
if (!t_node.isValid) return;
|
||||
|
||||
//界面已打开
|
||||
for (let i = this.m_viewList.length - 1; i >= 0; i--) {
|
||||
let t_view: Node = this.m_viewList[i];
|
||||
if (t_view) {
|
||||
if (t_view.isValid && t_node.name == t_view.name) {
|
||||
t_node.setSiblingIndex(999)
|
||||
Utils.Log('已经打开的相同的界面:' + t_node.name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//截屏纹理
|
||||
if (i_openInfo && i_openInfo.blueBg===true){
|
||||
i_openInfo.screenShotTex = this.getScreenShot()
|
||||
}
|
||||
|
||||
let viewSP = t_node.getComponent(t_node.name);
|
||||
if (!viewSP) {
|
||||
for (let index = 0; index < t_node['_components'].length; index++) {
|
||||
const element = t_node['_components'][index];
|
||||
if (element.isScriptComponent) {
|
||||
viewSP = element;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.m_viewList.push(t_node);
|
||||
this.m_viewListData[t_node.name] = { path: path, data: i_openInfo, sort: this.openIdx++, name: t_node.name, uuid: t_node["_prefab"]['asset']['_uuid'] };
|
||||
viewSP && viewSP.openUIData && viewSP.openUIData(i_openInfo);
|
||||
callBack && callBack(t_node, i_openInfo);
|
||||
if (type == '') {
|
||||
GameRootUI.I.AddUIToLayer(t_node, CommonConfig.UILayerGroup.Layer_ui1, this.m_viewList.length)
|
||||
} else if (type == 'top') {
|
||||
// t_node.sType = "top"
|
||||
GameRootUI.I.AddUIToLayer(t_node, CommonConfig.UILayerGroup.Layer_top)
|
||||
} else if (type == 'tips') {
|
||||
GameRootUI.I.AddUIToLayer(t_node, CommonConfig.UILayerGroup.Layer_tips)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//检查是否有相同的View
|
||||
private checkSameView(i_node: Node, path){
|
||||
// let t_com = i_node.getComponent('li_BaseView');
|
||||
// if (t_com) {
|
||||
// if (t_com.name == 'li_BaseView') return true;
|
||||
// for (let i = this.m_viewList.length - 1; i >= 0; i--) {
|
||||
// let t_view: Node = this.m_viewList[i];
|
||||
// if (t_view) {
|
||||
// if (t_view.isValid && t_com.node.name == t_view.name) {
|
||||
// i_node.setSiblingIndex(999)
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// i_node['path'] = path;
|
||||
// this.m_viewList.push(i_node);
|
||||
// return true;
|
||||
// }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//获取截屏纹理
|
||||
private getScreenShot():RenderTexture {
|
||||
// let texture = new RenderTexture();
|
||||
// let winSize = view.getViewportRect()
|
||||
// let winSize1 = view.getVisibleSize()
|
||||
// texture.reset({
|
||||
// width: winSize.width,
|
||||
// height: winSize.height,
|
||||
// });
|
||||
|
||||
// let camera = director.getScene().getComponentInChildren(Camera);
|
||||
// let oldTargetTexture = camera.targetTexture
|
||||
// camera.targetTexture = texture;
|
||||
// camera.render();
|
||||
// camera.targetTexture = oldTargetTexture
|
||||
|
||||
// return texture
|
||||
return null
|
||||
}
|
||||
|
||||
private getViewIndex(i_view: Node) {
|
||||
for (let i = this.m_viewList.length - 1; i >= 0; i--) {
|
||||
let t_view = this.m_viewList[i];
|
||||
if (t_view == i_view) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**打开resources窗体 */
|
||||
openMainView(i_prefab: string | Prefab, i_openData?, callBack = null, type: string = '') {
|
||||
if (i_prefab instanceof Prefab) {
|
||||
this.openViewByPrefab(null, i_prefab, i_openData, callBack, i_prefab, type);
|
||||
} else {
|
||||
resources.load(i_prefab, (err, $prefab: Prefab) => {
|
||||
this.openViewByPrefab(err, $prefab, i_openData, callBack, i_prefab, type);
|
||||
});
|
||||
}
|
||||
}
|
||||
/**打开bundle窗体 */
|
||||
openBundlesView(i_prefab: string | Prefab, i_openData?, callBack = null, type: string = '') {
|
||||
if (i_prefab instanceof Prefab) {
|
||||
this.openViewByPrefab(null, i_prefab, i_openData, callBack, i_prefab, type);
|
||||
} else {
|
||||
console.log("打开界面:", i_prefab);
|
||||
ResManager.I.getPrefab(i_prefab, (pb: Node) => {
|
||||
this.openViewByPrefab(null, pb, i_openData, callBack, i_prefab, type);
|
||||
}, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**关闭窗体 */
|
||||
closeView(i_view: Node) {
|
||||
let closeUIName = null
|
||||
let t_index = this.getViewIndex(i_view);
|
||||
if (t_index > -1) {
|
||||
let t_view = this.m_viewList[t_index];
|
||||
if (t_view) {
|
||||
closeUIName = t_view.name
|
||||
delete this.m_viewListData[t_view.name];
|
||||
t_view.destroy();
|
||||
t_view.removeFromParent();
|
||||
|
||||
}
|
||||
this.m_viewList.splice(t_index, 1); //删除列表元素 参数1是指定位置,参数2是删除元素个数
|
||||
}
|
||||
else {
|
||||
if (!this.m_viewList.length) {
|
||||
i_view.destroy();
|
||||
}
|
||||
Utils.Log('试图关闭一个队列中不存在的界面:', i_view.name);
|
||||
}
|
||||
}
|
||||
|
||||
/**关闭所有窗体 */
|
||||
closeAllView(isR = false) {
|
||||
for (let i = this.m_viewList.length - 1; i >= 0; i--) {
|
||||
let t_view = this.m_viewList[i];
|
||||
if (t_view) {
|
||||
delete this.m_viewListData[t_view.name];
|
||||
t_view.destroy();
|
||||
t_view.removeFromParent();
|
||||
}
|
||||
}
|
||||
|
||||
this.m_viewList = [];
|
||||
this.m_viewListData = {};
|
||||
this.openIdx = 0;
|
||||
|
||||
}
|
||||
|
||||
//是否在主界面,没有打开任何其他界面。主界面是在打开场景时直接创建的,不走这里的打开接口
|
||||
isNotOpenAnyUI() {
|
||||
if (this.m_viewList && this.m_viewList.length > 0) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "4c93d9e1-7465-4d94-a057-1f1c02a066ef",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user