打包頭條小遊戲的時候仍是須要先打微信包,只是在打包以前須要將以前設置的AssetBudle目錄設置爲普通目錄,而後將資源包放回resource中。而後打其餘包的時候再將Bundle文件夾從resource目錄中拿出來。服務器
var fs = require('fs'); var path = require('path'); var file_util = require('./file_util') //須要被移動到resource下的bundle。 var folderList = ['lobby','decoration','outdoor'] //源目錄 var asset_path = process.argv[2]; //目標目錄 var export_dir = process.argv[3]; //是不是bundle 1和0 var opt = process.argv[4]; function getBundleName(name){ for(var i = 0; i < folderList.length; i ++){ let s = folderList[i] if(name.indexOf(s) >= 0){ return s; } } return null; } function setBundle(meta_name,opt){ console.log(' meta_name',meta_name,' opt ',opt) var flag = opt == '1' ? true : false; console.log(' flag ',flag) let fileData = file_util.readFile(meta_name) if(fileData){ var obj = JSON.parse(fileData); obj['isBundle'] = flag console.log('fileData 2222 ',JSON.stringify(obj)) file_util.writeFile(meta_name,JSON.stringify(obj)) } } function exchangeFiles(asset_path,export_dir,opt) { var stat = fs.statSync(asset_path); if (!stat.isDirectory()) { return; } var subpaths = fs.readdirSync(asset_path), subpath; for (var i = 0; i < subpaths.length; ++i) { if (subpaths[i][0] === '.') { continue; } subpath = path.join(asset_path, subpaths[i]); console.log(" subpath ", subpath); var fname = getBundleName(subpath) if(fname){ stat = fs.statSync(subpath); if (stat.isDirectory()) { let dest_path = path.join(export_dir,fname) file_util.mkdir(dest_path) file_util.copyDir(subpath,dest_path) file_util.delDir(subpath) }else{ var meta_name = subpath var exportMeta_name = path.join(export_dir,fname)+'.meta' setBundle(meta_name,opt) file_util.copyFile(meta_name,exportMeta_name) file_util.deleteFile(meta_name) } } } } exchangeFiles(asset_path,export_dir,opt)
以上是我在使用Creator2.4版本發佈頭條小遊戲時遇到的問題及解決方案。方案可能那個有點笨拙,可是但願對遇到一樣問題的小夥伴有所幫助,也但願若是哪位小夥伴有更好的解決方案能夠分享出來。
如需完整腳本,請進入公衆號回覆 」發佈頭條「 獲取網盤連接。微信
歡迎掃碼關注公衆號《微笑遊戲》,瀏覽更多內容。框架