首页 > 其他 > 详细

Cocos Creator 中根据uuid快速定位资源

时间:2020-04-08 18:05:56      阅读:480      评论:0      收藏:0      [点我收藏+]

 

 

var BASE64_KEYS = ‘ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=‘;
var BASE64_VALUES = new Array(123); // max char code in base64Keys
for (let i = 0; i < 123; ++i) BASE64_VALUES[i] = 64; // fill with placeholder(‘=‘) index
for (let i = 0; i < 64; ++i) BASE64_VALUES[BASE64_KEYS.charCodeAt(i)] = i;

// decoded value indexed by base64 char code
Base64Values = BASE64_VALUES;

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(‘‘);
};

// if (CC_TEST) {
//     cc._Test.decodeUuid = module.exports;
// }

var uuid = module.exports("d3u9uUb6lEnqDsTfYrxOdp")
console.log(uuid)

 

Cocos Creator 中根据uuid快速定位资源

原文:https://www.cnblogs.com/roger-jc/p/12660502.html

(1)
(1)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!