码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2020-04-08 16:16:32      阅读:287      评论:0      收藏:0      [点我收藏+]

标签:col   base   ports   nbsp   根据   快速定位   ++i   func   rhs   

 

 

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快速定位资源

标签:col   base   ports   nbsp   根据   快速定位   ++i   func   rhs   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!