使用 Editor.Utils.UuidUtils.decompressUuid(uuid) 报Editor 为undefined(项目环境 项目构建模块全选, creator v1.8.2, 在模拟器上运行)。
是在哪里执行的这个代码?
Win10打包的时候,如果uuid是以语言代码开头的,那么极有可能会打包不进去,比如uuid是afaa9345-ef72-46fd-9129-9e30a0a9650a,那么在res/impor里面会放在af的文件夹里面有一个afaa9345-ef72-46fd-9129-9e30a0a9650a.*的文件,那么这个文件会打包不进去。能否提供一些uuid生成过滤,或者重新生成的办法。
Editor.Utils.UuidUtils.decompressUuid 这个方法内部算法是什么?
// decodeUuid
var BASE64_KEYS = ‘ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=’;
var BASE64_VALUES = new Array(123); // max char code in base64Keys
for (var i = 0; i < 123; ++i) {
BASE64_VALUES[i] = 64;
} // fill with placeholder(’=’) index
for (var _i = 0; _i < 64; ++_i) {
BASE64_VALUES[BASE64_KEYS.charCodeAt(_i)] = _i;
}
var HexChars = ‘0123456789abcdef’.split(’’);
var _t = [’’, ‘’, ‘’, ‘’];
var UuidTemplate = _t.concat(_t, ‘-’, _t, ‘-’, _t, ‘-’, _t, ‘-’, _t, _t, _t);
var Indices = UuidTemplate.map(function (x, i) {
return x === ‘-’ ? NaN : i;
}).filter(isFinite); // fcmR3XADNLgJ1ByKhqcC5Z -> fc991dd7-0033-4b80-9d41-c8a86a702e59
module.exports = function (base64) {
if (base64.length !== 22) {
return base64;
}
UuidTemplate[0] = base64[0];
UuidTemplate[1] = base64[1];
for (var i = 2, j = 2; i < 22; i += 2) {
var lhs = Base64Values[base64.charCodeAt(i)];
var rhs = Base64Values[base64.charCodeAt(i + 1)];
UuidTemplate[Indices[j++]] = HexChars[lhs >> 2];
UuidTemplate[Indices[j++]] = HexChars[(lhs & 3) << 2 | rhs >> 4];
UuidTemplate[Indices[j++]] = HexChars[rhs & 0xF];
}
return UuidTemplate.join(’’);
};
// encodeUuid
let maxCharCode = ‘f’.charCodeAt(0);
let BASE16_KEYS = ‘0123456789abcdef=’;
let BASE16_VALUES = new Array(maxCharCode + 1);
for (let i = 0; i <= maxCharCode; ++i) {
BASE16_VALUES[i] = 16;
}
for (let i = 0; i < 16; ++i) {
BASE16_VALUES[BASE16_KEYS.charCodeAt(i)] = i;
}
let HexChars = ‘ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/’.split(’’);
let t = [’’, ‘’, ‘’, ‘’];
let UuidTemplate = t.concat(t, t, t, t, ‘’, ‘’);
let Indices = UuidTemplate.map(function (x, i) {
return i;
});
// fc991dd7-0033-4b80-9d41-c8a86a702e59 -> fcmR3XADNLgJ1ByKhqcC5Z
function encodeUuid(base64) {
if (base64.length !== 36) {
return base64;
}
base64 = base64.replace(/-/g, ‘’);
UuidTemplate[0] = base64[0];
UuidTemplate[1] = base64[1];
for (let i = 2, j = 2; i < 32; i += 3) {
let lhs = BASE16_VALUES[base64.charCodeAt(i)];
let mhs = BASE16_VALUES[base64.charCodeAt(i + 1)];
let rhs = BASE16_VALUES[base64.charCodeAt(i + 2)];
UuidTemplate[Indices[j++]] = HexChars[lhs << 2 | mhs >> 2];
UuidTemplate[Indices[j++]] = HexChars[rhs | ((mhs & 3) << 4)];
}
return UuidTemplate.join(’’);
}
export default encodeUuid;