Godot 4 源码分析 - 获取属性信息

在管道通信基础上,可进行宿主程序与Godot的双向通信。

先拿属性信息试试手。

DrGraph端

static UnicodeString command = "Book.position";
if (InputQuery("输入窗口", "请输入待获取的属性信息", command)) {
	TDrStream_Get drGet(THelper::String::GetStringAt(command, L".", 0).Trim(),
						THelper::String::GetStringAt(command, L".", 1).Trim());
	TDllStream ds;
	ds << drGet;
	PipeStreamServer->WritePipe(ds, 1000);
}

Godot端(源码完善)

List<PropertyInfo> *p_list = new List<PropertyInfo>;
bool p_reversed = true;
destObject->get_property_list(p_list, p_reversed);
cofs << "OK";
for (List<PropertyInfo>::Iterator it = p_list->begin(); it != p_list->end(); ++it) {
	String content = it->name.ptr();
	if (it->class_name.operator String().is_empty() == false)
		content += str_format(U"[%s]", it->class_name.operator String().utf8().get_data());
	Variant value = destObject->get(it->name);
	content += str_format(U" = %s", value.operator String().utf8().get_data());
	cofs << content;
}
delete p_list;

运行结果

132. 13:20:29:829 > 【主线程】 > [Pipe.发送] > 发送数据中内容[DrGraph.28: Request - wait 1000 ms]: 
	[int]类型 > 值 = 2
	[UnicodeString]类型 > 值 = root
	[UnicodeString]类型 > 值 = propertyNames
133. 13:20:30:015 > 【主线程】 > [Pipe.Read] > 发送数据[DrGraph.28: Request - wait 1000 ms]成功返回 1837 字节... > PIPE响应中内容[godot -> DrGraph.28: Response - no return]: 
	[int]类型 > 值 = 3
	[UnicodeString]类型 > 值 = OK
	[UnicodeString]类型 > 值 = book.gd = <null>
	[UnicodeString]类型 > 值 = singlePage = false
	[UnicodeString]类型 > 值 = middleBarWidth = 0
	[UnicodeString]类型 > 值 = shader_rect[ColorRect] = ShaderRect:<ColorRect#26944209673>
	[UnicodeString]类型 > 值 = currentPageMode = false
	[UnicodeString]类型 > 值 = currentAreaType = -2
	[UnicodeString]类型 > 值 = triggleAreaMoment = 484887
	[UnicodeString]类型 > 值 = currentPageIndex = 30
	[UnicodeString]类型 > 值 = pageCount = 100
	[UnicodeString]类型 > 值 = pageImgPath = res://Pages/
	[UnicodeString]类型 > 值 = leftMouseDownMoment = 0
	[UnicodeString]类型 > 值 = underAutoTurnPage = false
	[UnicodeString]类型 > 值 = leftMouseDownPos = (0, 0)
	[UnicodeString]类型 > 值 = dllStream[DllStream] = <DllStream#67024979098>
	[UnicodeString]类型 > 值 = AutoTurnObject = <RefCounted#-9223372009692462322>
	[UnicodeString]类型 > 值 = Node2D = <null>
	[UnicodeString]类型 > 值 = Transform = <null>
	[UnicodeString]类型 > 值 = position = (0, 0)
	[UnicodeString]类型 > 值 = rotation = 0
	[UnicodeString]类型 > 值 = rotation_degrees = 0
	[UnicodeString]类型 > 值 = scale = (1, 1)
	[UnicodeString]类型 > 值 = skew = 0
	[UnicodeString]类型 > 值 = transform = [X: (1, 0), Y: (0, 1), O: (0, 0)]
	[UnicodeString]类型 > 值 = global_position = (0, 0)
	[UnicodeString]类型 > 值 = global_rotation = 0
	[UnicodeString]类型 > 值 = global_rotation_degrees = 0
	[UnicodeString]类型 > 值 = global_scale = (1, 1)
	[UnicodeString]类型 > 值 = global_skew = 0
	[UnicodeString]类型 > 值 = global_transform = [X: (1, 0), Y: (0, 1), O: (0, 0)]
	[UnicodeString]类型 > 值 = CanvasItem = <null>
	[UnicodeString]类型 > 值 = Visibility = <null>
	[UnicodeString]类型 > 值 = visible = true
	[UnicodeString]类型 > 值 = modulate = (1, 1, 1, 1)
	[UnicodeString]类型 > 值 = self_modulate = (1, 1, 1, 1)
	[UnicodeString]类型 > 值 = show_behind_parent = false
	[UnicodeString]类型 > 值 = top_level = false
	[UnicodeString]类型 > 值 = clip_children = 0
	[UnicodeString]类型 > 值 = light_mask = 1
	[UnicodeString]类型 > 值 = visibility_layer = 1
	[UnicodeString]类型 > 值 = Ordering = <null>
	[UnicodeString]类型 > 值 = z_index = 0
	[UnicodeString]类型 > 值 = z_as_relative = true
	[UnicodeString]类型 > 值 = y_sort_enabled = false
	[UnicodeString]类型 > 值 = Texture = <null>
	[UnicodeString]类型 > 值 = texture_filter = 0
	[UnicodeString]类型 > 值 = texture_repeat = 0
	[UnicodeString]类型 > 值 = Material = <null>
	[UnicodeString]类型 > 值 = material[CanvasItemMaterial,ShaderMaterial] = <Object#null>
	[UnicodeString]类型 > 值 = use_parent_material = false
	[UnicodeString]类型 > 值 = Node = <null>
	[UnicodeString]类型 > 值 = _import_path = 
	[UnicodeString]类型 > 值 = name = Book
	[UnicodeString]类型 > 值 = unique_name_in_owner = false
	[UnicodeString]类型 > 值 = scene_file_path = res://book.tscn
	[UnicodeString]类型 > 值 = owner[Node] = <Object#null>
	[UnicodeString]类型 > 值 = multiplayer[MultiplayerAPI] = <SceneMultiplayer#-9223372011168857310>
	[UnicodeString]类型 > 值 = Process = <null>
	[UnicodeString]类型 > 值 = process_mode = 0
	[UnicodeString]类型 > 值 = process_priority = 0
	[UnicodeString]类型 > 值 = Editor Description = <null>
	[UnicodeString]类型 > 值 = editor_description = 
	[UnicodeString]类型 > 值 = script[Script] = <GDScript#-9223372010984307965>

 这已具备RTTI的雏形。 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值