cocos-engine icon indicating copy to clipboard operation
cocos-engine copied to clipboard

希望引擎中能包含 uuid 压缩和解压缩的方法.

Open finscn opened this issue 1 year ago • 2 comments

Use Case

实际项目中 需要 将标准 uuid 转换成 压缩的uuid, 但是发现 3.x 里并暴露没有相关方法 (源码中也没有) 而是调用的 编辑器的相关代码. 编辑器又不开源.

具体使用场景有点特殊, 我是要扫描prefab 对里面引用的资源做一些处理, 但是引用资源的uuid 都是完整版的, 但是编译后的项目使用的又是压缩版本的.

且引擎提供的各种 uuid相关的方法的示例里使用的都是 压缩格式的. 开发者其实挺难通过脚本批量进行 uuid的压缩和解压.

总不能在编辑器里一个个的资源点击右键查看 然后自己记录.

希望官方能提供下相关方法. 哪怕不暴露

Problem Description

如上

Proposed Solution

No response

How it works

No response

Alternatives Considered

Additional Information

No response

finscn avatar Jun 29 '24 16:06 finscn

你说的是这个吗 `/**

  • @en
  • Decode base64-compressed uuid.
  • @zh
  • 解码用 base64 压缩过的 uuid。
  • @param base64 @en Base-64 compressed uuid. @zh 用 base-64 压缩过的 uuid。
  • @returns @en Original uuid. @zh 未压缩过的 uuid。
  • @example
  • const uuid = 'fcmR3XADNLgJ1ByKhqcC5Z';
  • const originalUuid = decodeUuid(uuid); // fc991dd7-0033-4b80-9d41-c8a86a702e59

*/ export default function decodeUuid (base64: string): string { const strs = base64.split(separator); const uuid = strs[0]; if (uuid.length !== 22) { return base64; } UuidTemplate[0] = base64[0]; UuidTemplate[1] = base64[1]; for (let i = 2, j = 2; i < 22; i += 2) { const lhs = BASE64_VALUES[base64.charCodeAt(i)]; const rhs = BASE64_VALUES[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 base64.replace(uuid, UuidTemplate.join('')); }

if (TEST) { legacyCC._Test.decodeUuid = decodeUuid; }`

hszhsh avatar Jul 01 '24 01:07 hszhsh

你说的是这个吗 `/**

  • @en
  • Decode base64-compressed uuid.
  • @zh
  • 解码用 base64 压缩过的 uuid。
  • @param base64 @en Base-64 compressed uuid. @zh 用 base-64 压缩过的 uuid。
  • @returns @en Original uuid. @zh 未压缩过的 uuid。
  • @example
  • const uuid = 'fcmR3XADNLgJ1ByKhqcC5Z';
  • const originalUuid = decodeUuid(uuid); // fc991dd7-0033-4b80-9d41-c8a86a702e59

*/ export default function decodeUuid (base64: string): string { const strs = base64.split(separator); const uuid = strs[0]; if (uuid.length !== 22) { return base64; } UuidTemplate[0] = base64[0]; UuidTemplate[1] = base64[1]; for (let i = 2, j = 2; i < 22; i += 2) { const lhs = BASE64_VALUES[base64.charCodeAt(i)]; const rhs = BASE64_VALUES[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 base64.replace(uuid, UuidTemplate.join('')); }

if (TEST) { legacyCC._Test.decodeUuid = decodeUuid; }`

是这个, 但是这个是 decode , 我还想要 encode .

其实 uuid的压缩 解压 算法和 cocos 2.x 的是一样的. 我如果要用 可以自己从 cocos 2.x 里copy出来. 但是我还是希望引擎直接提供 . 因为万一哪天 3.x 改了算法呢. 还是引擎提供保险些. (可以不开放出来, 但是最好能让开发者找到源码, 知道具体怎么处理的)

finscn avatar Jul 01 '24 12:07 finscn