Files
cocos4/native/cocos/core/utils/IDGenerator.cpp
T
minggo 5410a48a58 Implement more logic in native (#4131)
Co-authored-by: bofeng.song <bofeng.song@chukong-inc.com>
Co-authored-by: dumganhar <dumganhar@gmail.com>
Co-authored-by: mmyduckx <308303735@qq.com>
Co-authored-by: Patrice Jiang <397136899@qq.com>
Co-authored-by: 江战 <40414978+PatriceJiang@users.noreply.github.com>
2022-01-07 18:39:40 +08:00

22 lines
650 B
C++

#include "core/utils/IDGenerator.h"
#include "base/Random.h"
namespace cc {
IDGenerator globalIdGenerator("global");
IDGenerator::IDGenerator(const std::string &category) {
// Tnit with a random id to emphasize that the returns id should not be stored in persistence data.
_id = static_cast<uint32_t>(RandomHelper::randomInt(0, 998));
_prefix = (category + nonUuidMark);
}
std::string IDGenerator::getNewId() {
//cjh TODO: if (EDITOR && (this.prefix === 'Node.' || this.prefix === 'Comp.')) {
// return EditorExtends.UuidUtils.uuid();
// }
return _prefix + std::to_string(++_id);
}
} // namespace cc