init
This commit is contained in:
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"ver": "1.0.27",
|
||||
"importer": "image",
|
||||
"imported": true,
|
||||
"uuid": "b62239a5-ca74-45b7-8102-1e5281a9d8f7",
|
||||
"files": [
|
||||
".json",
|
||||
".png"
|
||||
],
|
||||
"subMetas": {
|
||||
"6c48a": {
|
||||
"importer": "texture",
|
||||
"uuid": "b62239a5-ca74-45b7-8102-1e5281a9d8f7@6c48a",
|
||||
"displayName": "zjm_23",
|
||||
"id": "6c48a",
|
||||
"name": "texture",
|
||||
"userData": {
|
||||
"wrapModeS": "clamp-to-edge",
|
||||
"wrapModeT": "clamp-to-edge",
|
||||
"imageUuidOrDatabaseUri": "b62239a5-ca74-45b7-8102-1e5281a9d8f7",
|
||||
"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": "b62239a5-ca74-45b7-8102-1e5281a9d8f7@f9941",
|
||||
"displayName": "zjm_23",
|
||||
"id": "f9941",
|
||||
"name": "spriteFrame",
|
||||
"userData": {
|
||||
"trimType": "auto",
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": 0,
|
||||
"offsetY": 0,
|
||||
"trimX": 0,
|
||||
"trimY": 0,
|
||||
"width": 211,
|
||||
"height": 64,
|
||||
"rawWidth": 211,
|
||||
"rawHeight": 64,
|
||||
"borderTop": 0,
|
||||
"borderBottom": 0,
|
||||
"borderLeft": 0,
|
||||
"borderRight": 0,
|
||||
"packable": true,
|
||||
"pixelsToUnit": 100,
|
||||
"pivotX": 0.5,
|
||||
"pivotY": 0.5,
|
||||
"meshType": 0,
|
||||
"vertices": {
|
||||
"rawPosition": [
|
||||
-105.5,
|
||||
-32,
|
||||
0,
|
||||
105.5,
|
||||
-32,
|
||||
0,
|
||||
-105.5,
|
||||
32,
|
||||
0,
|
||||
105.5,
|
||||
32,
|
||||
0
|
||||
],
|
||||
"indexes": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
3
|
||||
],
|
||||
"uv": [
|
||||
0,
|
||||
64,
|
||||
211,
|
||||
64,
|
||||
0,
|
||||
0,
|
||||
211,
|
||||
0
|
||||
],
|
||||
"nuv": [
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1,
|
||||
1
|
||||
],
|
||||
"minPos": [
|
||||
-105.5,
|
||||
-32,
|
||||
0
|
||||
],
|
||||
"maxPos": [
|
||||
105.5,
|
||||
32,
|
||||
0
|
||||
]
|
||||
},
|
||||
"isUuid": true,
|
||||
"imageUuidOrDatabaseUri": "b62239a5-ca74-45b7-8102-1e5281a9d8f7@6c48a",
|
||||
"atlasUuid": ""
|
||||
},
|
||||
"ver": "1.0.12",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
}
|
||||
},
|
||||
"userData": {
|
||||
"type": "sprite-frame",
|
||||
"hasAlpha": true,
|
||||
"fixAlphaTransparencyArtifacts": false,
|
||||
"redirect": "b62239a5-ca74-45b7-8102-1e5281a9d8f7@6c48a"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 101 KiB |
@@ -0,0 +1,513 @@
|
||||
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";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/**
|
||||
* http通讯
|
||||
*/
|
||||
@ccclass
|
||||
export default class HttpUnit {
|
||||
// static readonly ServerHttpHost = "https://bls.vip.hnhxzkj.com/";
|
||||
static readonly ServerHttpHost = "https://xqmnyx.vip.hnhxzkj.com/api/";
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
/**获取心动最大次数 */
|
||||
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 (GlobalValue.GMSwtitch) {
|
||||
return 10
|
||||
}
|
||||
|
||||
if (!HttpUnit.UserInfo) {
|
||||
return 0
|
||||
}
|
||||
let num = HttpUnit.UserInfo.game_share_num || 0;
|
||||
return num;
|
||||
}
|
||||
/**获取可看广告次数 - 相亲次数 */
|
||||
public static GetXiangqinAdNum() {
|
||||
//测试代码
|
||||
if (GlobalValue.GMSwtitch) {
|
||||
return 10
|
||||
}
|
||||
|
||||
if (!HttpUnit.UserInfo) {
|
||||
return 0
|
||||
}
|
||||
let num = HttpUnit.UserInfo.game_ad_num || 0;
|
||||
return num;
|
||||
}
|
||||
/**获取可分享次数 - 聊天次数 */
|
||||
public static GetTalkShareNum() {
|
||||
//测试代码
|
||||
if (GlobalValue.GMSwtitch) {
|
||||
return 10
|
||||
}
|
||||
|
||||
if (!HttpUnit.UserInfo) {
|
||||
return 0
|
||||
}
|
||||
let num = HttpUnit.UserInfo.level_share_num || 0;
|
||||
return num;
|
||||
}
|
||||
/**获取可看广告次数 - 聊天次数 */
|
||||
public static GetTalkAdNum() {
|
||||
//测试代码
|
||||
if (GlobalValue.GMSwtitch) {
|
||||
return 10
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
//登录
|
||||
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}
|
||||
// }
|
||||
|
||||
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 = 123457
|
||||
}
|
||||
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("login:", 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);
|
||||
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);
|
||||
cb && cb(null);
|
||||
}
|
||||
}
|
||||
/**开始关卡*/
|
||||
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);
|
||||
cb && cb(null);
|
||||
}
|
||||
}
|
||||
/**推进关卡*/
|
||||
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);
|
||||
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);
|
||||
cb && cb(null);
|
||||
}
|
||||
}
|
||||
/**增加次数,更新关卡*/
|
||||
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);
|
||||
cb && cb(null);
|
||||
}
|
||||
}
|
||||
/**获取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);
|
||||
cb && cb(null);
|
||||
}
|
||||
}
|
||||
/**获取当前聊天状态*/
|
||||
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);
|
||||
cb && cb(null);
|
||||
}
|
||||
}
|
||||
//非三星通关时继续关卡
|
||||
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);
|
||||
cb && cb(null);
|
||||
}
|
||||
}
|
||||
|
||||
//重新获取用户信息
|
||||
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;
|
||||
cb && cb(data.data);
|
||||
}else{
|
||||
console.log("重新获取用户信息数据失败:"+ data);
|
||||
cb && cb(null);
|
||||
}
|
||||
}
|
||||
//用户看广告
|
||||
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);
|
||||
cb && cb(null);
|
||||
}
|
||||
}
|
||||
//用户分享
|
||||
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);
|
||||
cb && cb(null);
|
||||
}
|
||||
}
|
||||
//获取常用配置
|
||||
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);
|
||||
cb && cb(null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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,134 @@
|
||||
{
|
||||
"ver": "1.0.27",
|
||||
"importer": "image",
|
||||
"imported": true,
|
||||
"uuid": "13e9d7f5-7bd4-4304-9ddb-f06a7ce5df07",
|
||||
"files": [
|
||||
".json",
|
||||
".png"
|
||||
],
|
||||
"subMetas": {
|
||||
"6c48a": {
|
||||
"importer": "texture",
|
||||
"uuid": "13e9d7f5-7bd4-4304-9ddb-f06a7ce5df07@6c48a",
|
||||
"displayName": "shirley_default",
|
||||
"id": "6c48a",
|
||||
"name": "texture",
|
||||
"userData": {
|
||||
"wrapModeS": "clamp-to-edge",
|
||||
"wrapModeT": "clamp-to-edge",
|
||||
"imageUuidOrDatabaseUri": "13e9d7f5-7bd4-4304-9ddb-f06a7ce5df07",
|
||||
"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": "13e9d7f5-7bd4-4304-9ddb-f06a7ce5df07@f9941",
|
||||
"displayName": "shirley_default",
|
||||
"id": "f9941",
|
||||
"name": "spriteFrame",
|
||||
"userData": {
|
||||
"trimType": "auto",
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": 2,
|
||||
"offsetY": -10,
|
||||
"trimX": 4,
|
||||
"trimY": 20,
|
||||
"width": 796,
|
||||
"height": 1009,
|
||||
"rawWidth": 800,
|
||||
"rawHeight": 1029,
|
||||
"borderTop": 0,
|
||||
"borderBottom": 0,
|
||||
"borderLeft": 0,
|
||||
"borderRight": 0,
|
||||
"packable": true,
|
||||
"pixelsToUnit": 100,
|
||||
"pivotX": 0.5,
|
||||
"pivotY": 0.5,
|
||||
"meshType": 0,
|
||||
"vertices": {
|
||||
"rawPosition": [
|
||||
-398,
|
||||
-504.5,
|
||||
0,
|
||||
398,
|
||||
-504.5,
|
||||
0,
|
||||
-398,
|
||||
504.5,
|
||||
0,
|
||||
398,
|
||||
504.5,
|
||||
0
|
||||
],
|
||||
"indexes": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
3
|
||||
],
|
||||
"uv": [
|
||||
4,
|
||||
1009,
|
||||
800,
|
||||
1009,
|
||||
4,
|
||||
0,
|
||||
800,
|
||||
0
|
||||
],
|
||||
"nuv": [
|
||||
0.005,
|
||||
0,
|
||||
1,
|
||||
0,
|
||||
0.005,
|
||||
0.9805636540330418,
|
||||
1,
|
||||
0.9805636540330418
|
||||
],
|
||||
"minPos": [
|
||||
-398,
|
||||
-504.5,
|
||||
0
|
||||
],
|
||||
"maxPos": [
|
||||
398,
|
||||
504.5,
|
||||
0
|
||||
]
|
||||
},
|
||||
"isUuid": true,
|
||||
"imageUuidOrDatabaseUri": "13e9d7f5-7bd4-4304-9ddb-f06a7ce5df07@6c48a",
|
||||
"atlasUuid": ""
|
||||
},
|
||||
"ver": "1.0.12",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
}
|
||||
},
|
||||
"userData": {
|
||||
"type": "sprite-frame",
|
||||
"hasAlpha": true,
|
||||
"fixAlphaTransparencyArtifacts": false,
|
||||
"redirect": "13e9d7f5-7bd4-4304-9ddb-f06a7ce5df07@6c48a"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 712 KiB |
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"ver": "1.0.27",
|
||||
"importer": "image",
|
||||
"imported": true,
|
||||
"uuid": "fa14f148-7621-4131-94c4-3ff5df1ad72e",
|
||||
"files": [
|
||||
".json",
|
||||
".png"
|
||||
],
|
||||
"subMetas": {
|
||||
"6c48a": {
|
||||
"importer": "texture",
|
||||
"uuid": "fa14f148-7621-4131-94c4-3ff5df1ad72e@6c48a",
|
||||
"displayName": "hessian_disgust",
|
||||
"id": "6c48a",
|
||||
"name": "texture",
|
||||
"userData": {
|
||||
"wrapModeS": "clamp-to-edge",
|
||||
"wrapModeT": "clamp-to-edge",
|
||||
"imageUuidOrDatabaseUri": "fa14f148-7621-4131-94c4-3ff5df1ad72e",
|
||||
"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": "fa14f148-7621-4131-94c4-3ff5df1ad72e@f9941",
|
||||
"displayName": "hessian_disgust",
|
||||
"id": "f9941",
|
||||
"name": "spriteFrame",
|
||||
"userData": {
|
||||
"trimType": "auto",
|
||||
"trimThreshold": 1,
|
||||
"rotated": false,
|
||||
"offsetX": 39,
|
||||
"offsetY": -14.5,
|
||||
"trimX": 116,
|
||||
"trimY": 29,
|
||||
"width": 771,
|
||||
"height": 1160,
|
||||
"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": [
|
||||
-385.5,
|
||||
-580,
|
||||
0,
|
||||
385.5,
|
||||
-580,
|
||||
0,
|
||||
-385.5,
|
||||
580,
|
||||
0,
|
||||
385.5,
|
||||
580,
|
||||
0
|
||||
],
|
||||
"indexes": [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
2,
|
||||
1,
|
||||
3
|
||||
],
|
||||
"uv": [
|
||||
116,
|
||||
1160,
|
||||
887,
|
||||
1160,
|
||||
116,
|
||||
0,
|
||||
887,
|
||||
0
|
||||
],
|
||||
"nuv": [
|
||||
0.1254054054054054,
|
||||
0,
|
||||
0.9589189189189189,
|
||||
0,
|
||||
0.1254054054054054,
|
||||
0.975609756097561,
|
||||
0.9589189189189189,
|
||||
0.975609756097561
|
||||
],
|
||||
"minPos": [
|
||||
-385.5,
|
||||
-580,
|
||||
0
|
||||
],
|
||||
"maxPos": [
|
||||
385.5,
|
||||
580,
|
||||
0
|
||||
]
|
||||
},
|
||||
"isUuid": true,
|
||||
"imageUuidOrDatabaseUri": "fa14f148-7621-4131-94c4-3ff5df1ad72e@6c48a",
|
||||
"atlasUuid": ""
|
||||
},
|
||||
"ver": "1.0.12",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
}
|
||||
},
|
||||
"userData": {
|
||||
"type": "sprite-frame",
|
||||
"hasAlpha": true,
|
||||
"fixAlphaTransparencyArtifacts": false,
|
||||
"redirect": "fa14f148-7621-4131-94c4-3ff5df1ad72e@6c48a"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 119 KiB |
@@ -0,0 +1,134 @@
|
||||
{
|
||||
"ver": "1.0.27",
|
||||
"importer": "image",
|
||||
"imported": true,
|
||||
"uuid": "109aa647-38ed-445f-9395-da273b912385",
|
||||
"files": [
|
||||
".json",
|
||||
".png"
|
||||
],
|
||||
"subMetas": {
|
||||
"6c48a": {
|
||||
"importer": "texture",
|
||||
"uuid": "109aa647-38ed-445f-9395-da273b912385@6c48a",
|
||||
"displayName": "krischya_default",
|
||||
"id": "6c48a",
|
||||
"name": "texture",
|
||||
"userData": {
|
||||
"wrapModeS": "clamp-to-edge",
|
||||
"wrapModeT": "clamp-to-edge",
|
||||
"imageUuidOrDatabaseUri": "109aa647-38ed-445f-9395-da273b912385",
|
||||
"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": "109aa647-38ed-445f-9395-da273b912385@f9941",
|
||||
"displayName": "krischya_default",
|
||||
"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": "109aa647-38ed-445f-9395-da273b912385@6c48a",
|
||||
"atlasUuid": ""
|
||||
},
|
||||
"ver": "1.0.12",
|
||||
"imported": true,
|
||||
"files": [
|
||||
".json"
|
||||
],
|
||||
"subMetas": {}
|
||||
}
|
||||
},
|
||||
"userData": {
|
||||
"type": "sprite-frame",
|
||||
"hasAlpha": true,
|
||||
"fixAlphaTransparencyArtifacts": false,
|
||||
"redirect": "109aa647-38ed-445f-9395-da273b912385@6c48a"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,415 @@
|
||||
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 bundle = assetManager.getBundle(packageName);
|
||||
if (bundle){
|
||||
bundle.load(url + "/spriteFrame", SpriteFrame, (err, res: SpriteFrame) => {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return
|
||||
}
|
||||
if (!spt.isValid) {
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/** 加载远程资源*/
|
||||
private loadRemoteRes(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);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取远程图片资源并设置
|
||||
* @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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user