[Godot] Find all custom attributes in the script

Godot 3.2.3

The following method gets a list of custom attributes of a node

func get_custom_property_list(obj: Object) -> Array:
	"""获取节点的自定义属性列表"""
	var property_list : Array = []
	for i in obj.get_property_list():
		# 这是一个 [自定义] 的属性 [usage] 则添加
		if is_custom_property(i['usage']):
			property_list.append(i)
	return property_list


func is_custom_property(var_usage) -> bool:
	"""返回变量是否是自定义属性
	@var_usage 变量标识
	"""
	if (var_usage == PROPERTY_USAGE_SCRIPT_VARIABLE || 
		var_usage == PROPERTY_USAGE_SCRIPT_VARIABLE | PROPERTY_USAGE_STORAGE 
						| PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NETWORK
	):
		return true
	return false

The script called directly get_custom_property_liston it

have a test

extends Node

var test = 'Test Variable'

func _ready() -> void:
    var array = get_custom_property_list(self)
    print(array)

Guess you like

Origin blog.csdn.net/qq_37280924/article/details/108163938