Commit 307de46b authored by liujiaxin's avatar liujiaxin

feat: use bundle load new skin

parent 7675b3ef
......@@ -7751,7 +7751,7 @@
"defaultCover": {
"__uuid__": "97b97a55-719c-48ff-81e0-269363ee147c"
},
"_id": "bbaF/xfq1D4ZUceYJYzAlJ"
"_id": "d7CwOQnuREtZv5XUoGzig/"
},
{
"__type__": "cc.Node",
......
......@@ -8,20 +8,22 @@ class Dress {
cover: "ani/cover.png",
type: 3,
meta_value: {
"eat": {
"tex_png": "ani/eating/eating_tex.png",
"ske_json": "ani/eating/eating_ske.json",
"tex_json": "ani/eating/eating_tex.json",
"armature": "",
// "play": "default"
},
"walk": {
"tex_png": "ani/walkinghungryhappy/walkinghungryhappy_tex.png",
"ske_json": "ani/walkinghungryhappy/walkinghungryhappy_ske.json",
"tex_json": "ani/walkinghungryhappy/walkinghungryhappy_tex.json",
"armature": "Armature",
"animation": "happy",
// "play": ""
nodes: {
"eat": {
"tex_png": "ani/eating/eating_tex.png",
"ske_json": "ani/eating/eating_ske.json",
"tex_json": "ani/eating/eating_tex.json",
"armature": "",
// "play": "default"
},
"walk": {
"tex_png": "ani/walkinghungryhappy/walkinghungryhappy_tex.png",
"ske_json": "ani/walkinghungryhappy/walkinghungryhappy_ske.json",
"tex_json": "ani/walkinghungryhappy/walkinghungryhappy_tex.json",
"armature": "Armature",
"animation": "happy",
// "play": ""
}
}
},
};
......
......@@ -40,20 +40,25 @@ export default class PengPeng extends cc.Component {
const eatAsset = eatDragonDisplay.dragonAsset;
const eatArmatureName = eatDragonDisplay.armatureName;
walkAtlasAsset.addRef();
walkAsset.addRef();
eatAtlasAsset.addRef();
eatAsset.addRef();
console.log('this.defaultCover.getTexture()', this.defaultCover.getTexture())
dress.defaultSkin.cover = this.defaultCover.getTexture();
dress.defaultSkin.meta_value.walk.tex_png = null;
dress.defaultSkin.meta_value.walk.ske_json = walkAsset
dress.defaultSkin.meta_value.walk.tex_json = walkAtlasAsset
dress.defaultSkin.meta_value.eat.armature = walkArmatureName
dress.defaultSkin.meta_value.nodes.walk.tex_png = null;
dress.defaultSkin.meta_value.nodes.walk.ske_json = walkAsset
dress.defaultSkin.meta_value.nodes.walk.tex_json = walkAtlasAsset
dress.defaultSkin.meta_value.nodes.walk.armature = walkArmatureName
dress.defaultSkin.meta_value.eat.tex_png = null;
dress.defaultSkin.meta_value.eat.ske_json = eatAsset
dress.defaultSkin.meta_value.eat.tex_json = eatAtlasAsset
dress.defaultSkin.meta_value.eat.armature = eatArmatureName
dress.defaultSkin.meta_value.nodes.eat.tex_png = null;
dress.defaultSkin.meta_value.nodes.eat.ske_json = eatAsset
dress.defaultSkin.meta_value.nodes.eat.tex_json = eatAtlasAsset
dress.defaultSkin.meta_value.nodes.eat.armature = eatArmatureName
}
dataReady = () => {
console.log('pengpeng dataReady');
......@@ -199,9 +204,90 @@ export default class PengPeng extends cc.Component {
});
})
}
changeDress(data) {
console.log('changeDress1', dress)
console.log('changeDress2', data)
const promiseArray = [];
const bundleUrl = data.meta_value.bundle;
const version = data.meta_value.version;
let bundleOption = null
if (version) {
bundleOption = {version}
}
return new Promise((resolve, reject) => {
let fn = cc.assetManager.loadBundle.bind(cc.assetManager)
if (!bundleUrl) {
fn = (bundleUrl, option, cb) => {
if (!bundleUrl) {
cb(null, null)
}
}
}
fn(bundleUrl, bundleOption, (err, bundle) => {
const nodeNames = Object.keys(data.meta_value.nodes);
for(let i = 0; i < nodeNames.length; i++) {
const nodeName = nodeNames[i];
const node = cc.find(nodeName, this.node)
node.stopAllActions();
if (node) {
const meta = data.meta_value.nodes[nodeName];
const dragonDisplay = node.getComponent(dragonBones.ArmatureDisplay);
// const imageUrl = meta['tex_png'];
const skeUrl = meta['ske_json'];
const atlasUrl = meta['tex_json'];
const armatureName = meta['armature'];
const animationName = meta['animation'];
const properties = meta['node'];
const offset = meta['offset'];
console.log(nodeName, armatureName, node)
dragonDisplay.dragonAsset = null;
dragonDisplay.dragonAtlasAsset = null;
dragonDisplay.armatureName = "";
const proc = new Promise((resolve1, reject1) => {
pg.load.loadFromBundle(bundle, [
[atlasUrl, dragonBones.DragonBonesAtlasAsset],
[skeUrl, dragonBones.DragonBonesAsset]
]).then(([atlas, asset]) => {
dragonDisplay.dragonAtlasAsset = atlas;
console.log(8)
dragonDisplay.dragonAsset = asset;
console.log(9)
dragonDisplay.armatureName = armatureName;
console.log(10)
const armature = dragonDisplay.armature()
// armature.animation.animationNames
console.log('animationName',node.name, armatureName, animationName, armature ? armature.animation.animationNames : [])
if (animationName) {
dragonDisplay.playAnimation(animationName, 0);
}
node.scaleX = 1;
node.scaleY = 1;
if (properties) {
Object.keys(properties).forEach(key => {
node[key] = properties[key];
})
}
if (offset) {
Object.keys(offset).forEach(key => {
node[key] += +offset[key];
})
}
resolve1()
})
})
promiseArray.push(proc)
}
}
})
Promise.all(promiseArray).then(() => {
resolve()
})
})
}
changeDress____123123(data) {
console.log('changeDress1', dress)
console.log('changeDress2', data)
const promiseArray = [];
......@@ -226,7 +312,7 @@ export default class PengPeng extends cc.Component {
console.log(nodeName, armatureName, node)
pg.load.loadAssets([
[imageUrl],
[imageUrl,{ext: '.png', type: cc.Texture2D}],
[atlasUrl, {ext: '.txt', type: dragonBones.DragonBonesAtlasAsset}],
[skeUrl, {ext: '.txt', type: dragonBones.DragonBonesAsset}]
]).then((assets: any[]) => {
......
......@@ -278,24 +278,54 @@ let pg = {
},
load: {
//资源加载
// loadBundle: function (bundleName) {
// return new Promise((resolve, reject) => {
// // let hallBundle = cc.assetManager.getBundle(`hall`);
// // hallBundle.releaseAll();
// // cc.assetManager.removeBundle(hallBundle);
// let bundle = cc.assetManager.getBundle(bundleName);
// if (bundle) return resolve('');
// cc.assetManager.loadBundle(bundleName, (err, bundle) => {
// if (err) return cc.error(err);
// resolve(bundle);
// });
// });
// },
loadBundle: function (bundleUri, options) {
return new Promise((resolve, reject) => {
if (!bundleUri) {
resolve();
return
}
// let hallBundle = cc.assetManager.getBundle(`hall`);
// hallBundle.releaseAll();
// cc.assetManager.removeBundle(hallBundle);
let bundle = cc.assetManager.getBundle(bundleUri);
if (bundle) return resolve('');
cc.assetManager.loadBundle(bundleUri,options, (err, bundle) => {
if (err) {
reject(err)
return cc.error(err)
};
resolve(bundle);
});
});
},
loadFromBundle: function (bundle, params) {
return new Promise((resolve, reject) => {
const tasks = params.map(p => {
return new Promise((resolve, reject) => {
if (typeof p[0] == 'string') {
bundle.load(p[0],p[1], (err, data) => {
if (err && !data) return reject(err);
resolve(data);
});
} else {
resolve(p[0]);
}
})
});
Promise.all(tasks).then((res) => {
resolve(res);
}).catch(e => {
reject(e);
})
})
},
loadRes: function (res, type, bundleName) {
//此处需要二次封装,新的存在assetbundle
return new Promise((resolve, reject) => {
cc.loader.loadRes(res, type, (err, data) => {
if (err && !data) return reject(pg.logger.d('loading loadRes error-> ' + res));
if (err && !data) return reject(err);
resolve(data);
});
})
......
......@@ -16,7 +16,7 @@
"mainCompressionType": "default",
"mainIsRemote": false,
"optimizeHotUpdate": false,
"md5Cache": false,
"md5Cache": true,
"nativeMd5Cache": true,
"encryptJs": true,
"xxteaKey": "af95a0f7-a8da-4f",
......
{
"last-module-event-record-time": 1655180857809,
"last-module-event-record-time": 1706792034745,
"migrate-history": [
"cloud-function"
],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment