init
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 161 KiB |
|
After Width: | Height: | Size: 961 KiB |
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.24",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "52115c35-aa3a-43c5-b66a-dce8559f819c",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
|
After Width: | Height: | Size: 158 KiB |
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 33 KiB |
@@ -0,0 +1,462 @@
|
||||
import { randomRange, view } from "cc";
|
||||
import GlobalValue from "../Common/GlobalValue";
|
||||
import SubManager from "../../Sub/SubManager";
|
||||
import { I_SDK_UserInfo_Callback } from "./SDKManager";
|
||||
|
||||
//广告ID
|
||||
const wx_banner_ad_unit_id = 'test'
|
||||
const wx_splash_ad_unit_id = 'test'
|
||||
const wx_video_ad_unit_id = 'test'
|
||||
|
||||
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广告 弹窗广告
|
||||
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);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//微信登录
|
||||
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() {
|
||||
this.wx_video = window['wx'].createRewardedVideoAd({
|
||||
adUnitId: wx_video_ad_unit_id
|
||||
});
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
//初始化插屏广告
|
||||
private init_splash() {
|
||||
// 创建插屏广告实例,提前初始化
|
||||
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() {
|
||||
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 => {
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
//显示视频广告
|
||||
show_video(callback:Function, tag:number) {
|
||||
if (wx_video_ad_unit_id == 'test') {
|
||||
console.log('未接入广告ID,视频广告请求直接返回');
|
||||
callback && callback();
|
||||
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) 要打开
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//分享信息
|
||||
shareInfo() {
|
||||
return {
|
||||
title: "告白契约", //Resource.getText(_shareInfo.invite_des),
|
||||
query: "ShareCode=" + "user_default", //ModelPlayer.I.getPlayerId(),
|
||||
}
|
||||
}
|
||||
//主动拉起分享
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//检查是否支持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);
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"ver": "1.0.27",
|
||||
"importer": "image",
|
||||
"imported": true,
|
||||
"uuid": "22f1d07d-6083-4f04-bcf2-ad9bbd562327",
|
||||
"files": [
|
||||
".json",
|
||||
".png"
|
||||
],
|
||||
"subMetas": {
|
||||
"6c48a": {
|
||||
"importer": "texture",
|
||||
"uuid": "22f1d07d-6083-4f04-bcf2-ad9bbd562327@6c48a",
|
||||
"displayName": "mochiduki_aoi_disgust",
|
||||
"id": "6c48a",
|
||||
"name": "texture",
|
||||
"userData": {
|
||||
"wrapModeS": "clamp-to-edge",
|
||||
"wrapModeT": "clamp-to-edge",
|
||||
"imageUuidOrDatabaseUri": "22f1d07d-6083-4f04-bcf2-ad9bbd562327",
|
||||
"isUuid": true,
|
||||
"visible": false,
|
||||
"minfilter": "linear",
|
||||
"magfilter": "linear",
|
||||
"mipfilter": "none",
|
||||
"anisotropy": 0
|
||||
},
|
||||
"ver": "1.0.22",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
},
|
||||
"f9941": {
|
||||
"importer": "sprite-frame",
|
||||
"uuid": "22f1d07d-6083-4f04-bcf2-ad9bbd562327@f9941",
|
||||
"displayName": "mochiduki_aoi_disgust",
|
||||
"id": "f9941",
|
||||
"name": "spriteFrame",
|
||||
"userData": {
|
||||
"trimType": "none",
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": 0,
|
||||
"offsetY": 0,
|
||||
"trimX": 0,
|
||||
"trimY": 0,
|
||||
"width": 925,
|
||||
"height": 1189,
|
||||
"rawWidth": 925,
|
||||
"rawHeight": 1189,
|
||||
"borderTop": 0,
|
||||
"borderBottom": 0,
|
||||
"borderLeft": 0,
|
||||
"borderRight": 0,
|
||||
"packable": true,
|
||||
"pixelsToUnit": 100,
|
||||
"pivotX": 0.5,
|
||||
"pivotY": 0.5,
|
||||
"meshType": 0,
|
||||
"vertices": {
|
||||
"rawPosition": [
|
||||
-462.5,
|
||||
-594.5,
|
||||
0,
|
||||
462.5,
|
||||
-594.5,
|
||||
0,
|
||||
-462.5,
|
||||
594.5,
|
||||
0,
|
||||
462.5,
|
||||
594.5,
|
||||
0
|
||||
],
|
||||
"indexes": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
3
|
||||
],
|
||||
"uv": [
|
||||
0,
|
||||
1189,
|
||||
925,
|
||||
1189,
|
||||
0,
|
||||
0,
|
||||
925,
|
||||
0
|
||||
],
|
||||
"nuv": [
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"minPos": [
|
||||
-462.5,
|
||||
-594.5,
|
||||
0
|
||||
],
|
||||
"maxPos": [
|
||||
462.5,
|
||||
594.5,
|
||||
0
|
||||
]
|
||||
},
|
||||
"isUuid": true,
|
||||
"imageUuidOrDatabaseUri": "22f1d07d-6083-4f04-bcf2-ad9bbd562327@6c48a",
|
||||
"atlasUuid": ""
|
||||
},
|
||||
"ver": "1.0.12",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
}
|
||||
},
|
||||
"userData": {
|
||||
"type": "sprite-frame",
|
||||
"hasAlpha": true,
|
||||
"fixAlphaTransparencyArtifacts": false,
|
||||
"redirect": "22f1d07d-6083-4f04-bcf2-ad9bbd562327@6c48a"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 404 KiB |
|
After Width: | Height: | Size: 1001 KiB |
@@ -0,0 +1,22 @@
|
||||
|
||||
//消息枚举
|
||||
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, //私家珍藏更新消息
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"ver": "1.0.27",
|
||||
"importer": "image",
|
||||
"imported": true,
|
||||
"uuid": "fe6c2f0c-1d5b-45a7-9874-007a49c05132",
|
||||
"files": [
|
||||
".jpg",
|
||||
".json"
|
||||
],
|
||||
"subMetas": {
|
||||
"6c48a": {
|
||||
"importer": "texture",
|
||||
"uuid": "fe6c2f0c-1d5b-45a7-9874-007a49c05132@6c48a",
|
||||
"displayName": "hippo_0_cg",
|
||||
"id": "6c48a",
|
||||
"name": "texture",
|
||||
"userData": {
|
||||
"wrapModeS": "clamp-to-edge",
|
||||
"wrapModeT": "clamp-to-edge",
|
||||
"imageUuidOrDatabaseUri": "fe6c2f0c-1d5b-45a7-9874-007a49c05132",
|
||||
"isUuid": true,
|
||||
"visible": false,
|
||||
"minfilter": "linear",
|
||||
"magfilter": "linear",
|
||||
"mipfilter": "none",
|
||||
"anisotropy": 0
|
||||
},
|
||||
"ver": "1.0.22",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
},
|
||||
"f9941": {
|
||||
"importer": "sprite-frame",
|
||||
"uuid": "fe6c2f0c-1d5b-45a7-9874-007a49c05132@f9941",
|
||||
"displayName": "hippo_0_cg",
|
||||
"id": "f9941",
|
||||
"name": "spriteFrame",
|
||||
"userData": {
|
||||
"trimType": "auto",
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": 0,
|
||||
"offsetY": 0,
|
||||
"trimX": 0,
|
||||
"trimY": 0,
|
||||
"width": 996,
|
||||
"height": 1280,
|
||||
"rawWidth": 996,
|
||||
"rawHeight": 1280,
|
||||
"borderTop": 0,
|
||||
"borderBottom": 0,
|
||||
"borderLeft": 0,
|
||||
"borderRight": 0,
|
||||
"packable": true,
|
||||
"pixelsToUnit": 100,
|
||||
"pivotX": 0.5,
|
||||
"pivotY": 0.5,
|
||||
"meshType": 0,
|
||||
"vertices": {
|
||||
"rawPosition": [
|
||||
-498,
|
||||
-640,
|
||||
0,
|
||||
498,
|
||||
-640,
|
||||
0,
|
||||
-498,
|
||||
640,
|
||||
0,
|
||||
498,
|
||||
640,
|
||||
0
|
||||
],
|
||||
"indexes": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
3
|
||||
],
|
||||
"uv": [
|
||||
0,
|
||||
1280,
|
||||
996,
|
||||
1280,
|
||||
0,
|
||||
0,
|
||||
996,
|
||||
0
|
||||
],
|
||||
"nuv": [
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"minPos": [
|
||||
-498,
|
||||
-640,
|
||||
0
|
||||
],
|
||||
"maxPos": [
|
||||
498,
|
||||
640,
|
||||
0
|
||||
]
|
||||
},
|
||||
"isUuid": true,
|
||||
"imageUuidOrDatabaseUri": "fe6c2f0c-1d5b-45a7-9874-007a49c05132@6c48a",
|
||||
"atlasUuid": ""
|
||||
},
|
||||
"ver": "1.0.12",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
}
|
||||
},
|
||||
"userData": {
|
||||
"type": "sprite-frame",
|
||||
"hasAlpha": false,
|
||||
"fixAlphaTransparencyArtifacts": false,
|
||||
"redirect": "fe6c2f0c-1d5b-45a7-9874-007a49c05132@6c48a"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"ver": "1.0.27",
|
||||
"importer": "image",
|
||||
"imported": true,
|
||||
"uuid": "8eae627f-d583-42f0-bb4b-210198476961",
|
||||
"files": [
|
||||
".json",
|
||||
".png"
|
||||
],
|
||||
"subMetas": {
|
||||
"6c48a": {
|
||||
"importer": "texture",
|
||||
"uuid": "8eae627f-d583-42f0-bb4b-210198476961@6c48a",
|
||||
"displayName": "hilaryvel_disgust",
|
||||
"id": "6c48a",
|
||||
"name": "texture",
|
||||
"userData": {
|
||||
"wrapModeS": "clamp-to-edge",
|
||||
"wrapModeT": "clamp-to-edge",
|
||||
"imageUuidOrDatabaseUri": "8eae627f-d583-42f0-bb4b-210198476961",
|
||||
"isUuid": true,
|
||||
"visible": false,
|
||||
"minfilter": "linear",
|
||||
"magfilter": "linear",
|
||||
"mipfilter": "none",
|
||||
"anisotropy": 0
|
||||
},
|
||||
"ver": "1.0.22",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
},
|
||||
"f9941": {
|
||||
"importer": "sprite-frame",
|
||||
"uuid": "8eae627f-d583-42f0-bb4b-210198476961@f9941",
|
||||
"displayName": "hilaryvel_disgust",
|
||||
"id": "f9941",
|
||||
"name": "spriteFrame",
|
||||
"userData": {
|
||||
"trimType": "auto",
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": -1,
|
||||
"offsetY": -10,
|
||||
"trimX": 0,
|
||||
"trimY": 20,
|
||||
"width": 923,
|
||||
"height": 1169,
|
||||
"rawWidth": 925,
|
||||
"rawHeight": 1189,
|
||||
"borderTop": 0,
|
||||
"borderBottom": 0,
|
||||
"borderLeft": 0,
|
||||
"borderRight": 0,
|
||||
"packable": true,
|
||||
"pixelsToUnit": 100,
|
||||
"pivotX": 0.5,
|
||||
"pivotY": 0.5,
|
||||
"meshType": 0,
|
||||
"vertices": {
|
||||
"rawPosition": [
|
||||
-461.5,
|
||||
-584.5,
|
||||
0,
|
||||
461.5,
|
||||
-584.5,
|
||||
0,
|
||||
-461.5,
|
||||
584.5,
|
||||
0,
|
||||
461.5,
|
||||
584.5,
|
||||
0
|
||||
],
|
||||
"indexes": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
3
|
||||
],
|
||||
"uv": [
|
||||
0,
|
||||
1169,
|
||||
923,
|
||||
1169,
|
||||
0,
|
||||
0,
|
||||
923,
|
||||
0
|
||||
],
|
||||
"nuv": [
|
||||
0,
|
||||
0,
|
||||
0.9978378378378379,
|
||||
0,
|
||||
0,
|
||||
0.9831791421362489,
|
||||
0.9978378378378379,
|
||||
0.9831791421362489
|
||||
],
|
||||
"minPos": [
|
||||
-461.5,
|
||||
-584.5,
|
||||
0
|
||||
],
|
||||
"maxPos": [
|
||||
461.5,
|
||||
584.5,
|
||||
0
|
||||
]
|
||||
},
|
||||
"isUuid": true,
|
||||
"imageUuidOrDatabaseUri": "8eae627f-d583-42f0-bb4b-210198476961@6c48a",
|
||||
"atlasUuid": ""
|
||||
},
|
||||
"ver": "1.0.12",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
}
|
||||
},
|
||||
"userData": {
|
||||
"type": "sprite-frame",
|
||||
"hasAlpha": true,
|
||||
"fixAlphaTransparencyArtifacts": false,
|
||||
"redirect": "8eae627f-d583-42f0-bb4b-210198476961@6c48a"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"ver": "1.0.27",
|
||||
"importer": "image",
|
||||
"imported": true,
|
||||
"uuid": "80b35374-00cb-4f4e-a7e6-ea2742b0c124",
|
||||
"files": [
|
||||
".jpg",
|
||||
".json"
|
||||
],
|
||||
"subMetas": {
|
||||
"6c48a": {
|
||||
"importer": "texture",
|
||||
"uuid": "80b35374-00cb-4f4e-a7e6-ea2742b0c124@6c48a",
|
||||
"displayName": "zhiyan_3_cg",
|
||||
"id": "6c48a",
|
||||
"name": "texture",
|
||||
"userData": {
|
||||
"wrapModeS": "clamp-to-edge",
|
||||
"wrapModeT": "clamp-to-edge",
|
||||
"imageUuidOrDatabaseUri": "80b35374-00cb-4f4e-a7e6-ea2742b0c124",
|
||||
"isUuid": true,
|
||||
"visible": false,
|
||||
"minfilter": "linear",
|
||||
"magfilter": "linear",
|
||||
"mipfilter": "none",
|
||||
"anisotropy": 0
|
||||
},
|
||||
"ver": "1.0.22",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
},
|
||||
"f9941": {
|
||||
"importer": "sprite-frame",
|
||||
"uuid": "80b35374-00cb-4f4e-a7e6-ea2742b0c124@f9941",
|
||||
"displayName": "zhiyan_3_cg",
|
||||
"id": "f9941",
|
||||
"name": "spriteFrame",
|
||||
"userData": {
|
||||
"trimType": "auto",
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": 0,
|
||||
"offsetY": 0,
|
||||
"trimX": 0,
|
||||
"trimY": 0,
|
||||
"width": 996,
|
||||
"height": 1280,
|
||||
"rawWidth": 996,
|
||||
"rawHeight": 1280,
|
||||
"borderTop": 0,
|
||||
"borderBottom": 0,
|
||||
"borderLeft": 0,
|
||||
"borderRight": 0,
|
||||
"packable": true,
|
||||
"pixelsToUnit": 100,
|
||||
"pivotX": 0.5,
|
||||
"pivotY": 0.5,
|
||||
"meshType": 0,
|
||||
"vertices": {
|
||||
"rawPosition": [
|
||||
-498,
|
||||
-640,
|
||||
0,
|
||||
498,
|
||||
-640,
|
||||
0,
|
||||
-498,
|
||||
640,
|
||||
0,
|
||||
498,
|
||||
640,
|
||||
0
|
||||
],
|
||||
"indexes": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
3
|
||||
],
|
||||
"uv": [
|
||||
0,
|
||||
1280,
|
||||
996,
|
||||
1280,
|
||||
0,
|
||||
0,
|
||||
996,
|
||||
0
|
||||
],
|
||||
"nuv": [
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"minPos": [
|
||||
-498,
|
||||
-640,
|
||||
0
|
||||
],
|
||||
"maxPos": [
|
||||
498,
|
||||
640,
|
||||
0
|
||||
]
|
||||
},
|
||||
"isUuid": true,
|
||||
"imageUuidOrDatabaseUri": "80b35374-00cb-4f4e-a7e6-ea2742b0c124@6c48a",
|
||||
"atlasUuid": ""
|
||||
},
|
||||
"ver": "1.0.12",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
}
|
||||
},
|
||||
"userData": {
|
||||
"type": "sprite-frame",
|
||||
"hasAlpha": false,
|
||||
"fixAlphaTransparencyArtifacts": false,
|
||||
"redirect": "80b35374-00cb-4f4e-a7e6-ea2742b0c124@6c48a"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"ver": "1.0.27",
|
||||
"importer": "image",
|
||||
"imported": true,
|
||||
"uuid": "96d7b836-48be-4a1f-a293-8620c2107959",
|
||||
"files": [
|
||||
".json",
|
||||
".png"
|
||||
],
|
||||
"subMetas": {
|
||||
"6c48a": {
|
||||
"importer": "texture",
|
||||
"uuid": "96d7b836-48be-4a1f-a293-8620c2107959@6c48a",
|
||||
"displayName": "shirley_disgust",
|
||||
"id": "6c48a",
|
||||
"name": "texture",
|
||||
"userData": {
|
||||
"wrapModeS": "clamp-to-edge",
|
||||
"wrapModeT": "clamp-to-edge",
|
||||
"imageUuidOrDatabaseUri": "96d7b836-48be-4a1f-a293-8620c2107959",
|
||||
"isUuid": true,
|
||||
"visible": false,
|
||||
"minfilter": "linear",
|
||||
"magfilter": "linear",
|
||||
"mipfilter": "none",
|
||||
"anisotropy": 0
|
||||
},
|
||||
"ver": "1.0.22",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
},
|
||||
"f9941": {
|
||||
"importer": "sprite-frame",
|
||||
"uuid": "96d7b836-48be-4a1f-a293-8620c2107959@f9941",
|
||||
"displayName": "shirley_disgust",
|
||||
"id": "f9941",
|
||||
"name": "spriteFrame",
|
||||
"userData": {
|
||||
"trimType": "auto",
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": 2,
|
||||
"offsetY": -11.5,
|
||||
"trimX": 4,
|
||||
"trimY": 23,
|
||||
"width": 921,
|
||||
"height": 1166,
|
||||
"rawWidth": 925,
|
||||
"rawHeight": 1189,
|
||||
"borderTop": 0,
|
||||
"borderBottom": 0,
|
||||
"borderLeft": 0,
|
||||
"borderRight": 0,
|
||||
"packable": true,
|
||||
"pixelsToUnit": 100,
|
||||
"pivotX": 0.5,
|
||||
"pivotY": 0.5,
|
||||
"meshType": 0,
|
||||
"vertices": {
|
||||
"rawPosition": [
|
||||
-460.5,
|
||||
-583,
|
||||
0,
|
||||
460.5,
|
||||
-583,
|
||||
0,
|
||||
-460.5,
|
||||
583,
|
||||
0,
|
||||
460.5,
|
||||
583,
|
||||
0
|
||||
],
|
||||
"indexes": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
3
|
||||
],
|
||||
"uv": [
|
||||
4,
|
||||
1166,
|
||||
925,
|
||||
1166,
|
||||
4,
|
||||
0,
|
||||
925,
|
||||
0
|
||||
],
|
||||
"nuv": [
|
||||
0.004324324324324324,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0.004324324324324324,
|
||||
0.9806560134566863,
|
||||
1,
|
||||
0.9806560134566863
|
||||
],
|
||||
"minPos": [
|
||||
-460.5,
|
||||
-583,
|
||||
0
|
||||
],
|
||||
"maxPos": [
|
||||
460.5,
|
||||
583,
|
||||
0
|
||||
]
|
||||
},
|
||||
"isUuid": true,
|
||||
"imageUuidOrDatabaseUri": "96d7b836-48be-4a1f-a293-8620c2107959@6c48a",
|
||||
"atlasUuid": ""
|
||||
},
|
||||
"ver": "1.0.12",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
}
|
||||
},
|
||||
"userData": {
|
||||
"type": "sprite-frame",
|
||||
"hasAlpha": true,
|
||||
"fixAlphaTransparencyArtifacts": false,
|
||||
"redirect": "96d7b836-48be-4a1f-a293-8620c2107959@6c48a"
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||