mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-15 17:54:52 +08:00
Allow FGuid to generate a Guid string
This commit is contained in:
17
js/FGuid.js
17
js/FGuid.js
@@ -1,16 +1,21 @@
|
||||
export default class FGuid {
|
||||
static generateGuid() {
|
||||
let result = ""
|
||||
let random = new Uint32Array(4);
|
||||
crypto.getRandomValues(random)
|
||||
random.forEach(n => {
|
||||
this.result += ('00000000' + n.toString(16).toUpperCase()).slice(-8)
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
constructor(guid) {
|
||||
if (guid?.constructor?.name === 'String') {
|
||||
this.value = guid
|
||||
} else if (guid?.constructor?.name === 'FGuid') {
|
||||
this.value = guid.value
|
||||
} else {
|
||||
let random = new Uint32Array(4);
|
||||
crypto.getRandomValues(random)
|
||||
this.value = ""
|
||||
random.forEach(n => {
|
||||
this.value += ('00000000' + n.toString(16).toUpperCase()).slice(-8)
|
||||
})
|
||||
this.value = FGuid.generateGuid()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user