瀏覽代碼

Merge pull request #38819 from EricEzaM/improve-to_string-for-nodes

Added Node name to print() of all Nodes by making to_string() in Object virtual, so it can be overriden in C++.
Rémi Verschelde 4 年之前
父節點
當前提交
f79e79d479
共有 2 個文件被更改,包括 14 次插入0 次删除
  1. 12 0
      scene/main/node.cpp
  2. 2 0
      scene/main/node.h

+ 12 - 0
scene/main/node.cpp

@@ -1822,6 +1822,18 @@ Node *Node::get_deepest_editable_node(Node *p_start_node) const {
 	return node;
 	return node;
 }
 }
 
 
+String Node::to_string() {
+	if (get_script_instance()) {
+		bool valid;
+		String ret = get_script_instance()->to_string(&valid);
+		if (valid) {
+			return ret;
+		}
+	}
+
+	return (get_name() ? String(get_name()) + ":" : "") + Object::to_string();
+}
+
 void Node::set_scene_instance_state(const Ref<SceneState> &p_state) {
 void Node::set_scene_instance_state(const Ref<SceneState> &p_state) {
 	data.instance_state = p_state;
 	data.instance_state = p_state;
 }
 }

+ 2 - 0
scene/main/node.h

@@ -329,6 +329,8 @@ public:
 	bool is_editable_instance(const Node *p_node) const;
 	bool is_editable_instance(const Node *p_node) const;
 	Node *get_deepest_editable_node(Node *p_start_node) const;
 	Node *get_deepest_editable_node(Node *p_start_node) const;
 
 
+	virtual String to_string() override;
+
 	/* NOTIFICATIONS */
 	/* NOTIFICATIONS */
 
 
 	void propagate_notification(int p_notification);
 	void propagate_notification(int p_notification);