16.导出数组

导出数组是可行的,但有一个重要的注意事项:虽然常规数组是在每个类实例本地创建的,但导出的数组是在所有实例之间“共享”的。这意味着在一个实例中编辑它们将导致在所有其他实例中更改它们。导出的数组可以有初始化器,但它们必须是常量表达式。

# Exported array, shared between all instances.
# Default value must be a constant expression.

export var a = [1, 2, 3]

# Exported arrays can specify type (using the same hints as before).

export(Array, int) var ints = [1,2,3]
export(Array, int, "Red", "Green", "Blue") var enums = [2, 1, 0]
export(Array, Array, float) var two_dimensional = [[1, 2], [3, 4]]

# You can omit the default value, but then it would be null if not assigned.

export(Array) var b
export(Array, PackedScene) var scenes

# Typed arrays also work, only initialized empty:

export var vector3s = PoolVector3Array()
export var strings = PoolStringArray()

# Regular array, created local for every instance.
# Default value can include run-time values, but can't
# be exported.

var c = [a, 2, 3]
posted @ 2018-12-30 14:11  宸少凌  阅读(578)  评论(0编辑  收藏  举报

万年以来谁著史,三千里外欲封侯