脚本开发
GDScript
注解规范
为作用于脚本或其代码的修饰符创建注解。此外,为特定于 Godot 引擎和编辑器的行为创建注解;如果主要目的是影响引擎或编辑器处理或与脚本交互的方式,则应将该标记实现为注解。
请勿为通用编程语言功能创建注解。
# Affects how the editor treats this script.
@icon("res://path/to/class/icon.svg")
# Affects how the engine interacts with this script.
@onready var character_name = $Label
# static is a general programming language feature.
static var num_players = 2
由于历史原因,部分现有的注解和关键字并未严格遵循上述准则。将某项功能实现为注解还是语言关键字,是一个需要权衡的决策,应与其他 GDScript 开发者共同讨论后决定。