Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
PackedDataContainer
已棄用: Use @GlobalScope.var_to_bytes() or FileAccess.store_var() instead. To enable data compression, use PackedByteArray.compress() or FileAccess.open_compressed().
繼承: Resource < RefCounted < Object
將 Array 或 Dictionary 進行高效打包和序列化。
說明
PackedDataContainer can be used to efficiently store data from untyped containers. The data is packed into raw bytes and can be saved to file. Only Array and Dictionary can be stored this way.
You can retrieve the data by iterating on the container, which will work as if iterating on the packed data itself. If the packed container is a Dictionary, the data can be retrieved by key names (String/StringName only).
var data = { "key": "value", "another_key": 123, "lock": Vector2() }
var packed = PackedDataContainer.new()
packed.pack(data)
ResourceSaver.save(packed, "packed_data.res")
var container = load("packed_data.res")
for key in container:
prints(key, container[key])
Prints:
key value
lock (0, 0)
another_key 123
Nested containers will be packed recursively. While iterating, they will be returned as PackedDataContainerRef.
方法
size() const |
方法說明
將給定的容器打包為二進位表示。value 必須為 Array 或 Dictionary,其他型別會導致無效資料錯誤。
注意:後續再次呼叫該方法會覆蓋已有資料。
返回打包後容器的大小(見 Array.size() 和 Dictionary.size())。