Reimplement Resource._local_to_scene_setup
& remove workaround
Reimplements the virtual method _setup_local_to_scene, lost in #51970 Also deprecates the redundant `setup_local_to_scene_requested` signal.
This commit is contained in:
parent
8c1817f755
commit
79ce0c6e80
3 changed files with 24 additions and 5 deletions
|
@ -379,8 +379,8 @@ Node *Resource::get_local_scene() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Resource::setup_local_to_scene() {
|
void Resource::setup_local_to_scene() {
|
||||||
// Can't use GDVIRTUAL in Resource, so this will have to be done with a signal
|
|
||||||
emit_signal(SNAME("setup_local_to_scene_requested"));
|
emit_signal(SNAME("setup_local_to_scene_requested"));
|
||||||
|
GDVIRTUAL_CALL(_setup_local_to_scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Resource::reset_local_to_scene() {
|
void Resource::reset_local_to_scene() {
|
||||||
|
@ -460,6 +460,7 @@ void Resource::_bind_methods() {
|
||||||
get_rid_bind.return_val.type = Variant::RID;
|
get_rid_bind.return_val.type = Variant::RID;
|
||||||
|
|
||||||
::ClassDB::add_virtual_method(get_class_static(), get_rid_bind, true, Vector<String>(), true);
|
::ClassDB::add_virtual_method(get_class_static(), get_rid_bind, true, Vector<String>(), true);
|
||||||
|
GDVIRTUAL_BIND(_setup_local_to_scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
Resource::Resource() :
|
Resource::Resource() :
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
|
|
||||||
#include "core/io/resource_uid.h"
|
#include "core/io/resource_uid.h"
|
||||||
#include "core/object/class_db.h"
|
#include "core/object/class_db.h"
|
||||||
|
#include "core/object/gdvirtual.gen.inc"
|
||||||
#include "core/object/ref_counted.h"
|
#include "core/object/ref_counted.h"
|
||||||
#include "core/templates/safe_refcount.h"
|
#include "core/templates/safe_refcount.h"
|
||||||
#include "core/templates/self_list.h"
|
#include "core/templates/self_list.h"
|
||||||
|
@ -81,6 +82,7 @@ protected:
|
||||||
void _take_over_path(const String &p_path);
|
void _take_over_path(const String &p_path);
|
||||||
|
|
||||||
virtual void reset_local_to_scene();
|
virtual void reset_local_to_scene();
|
||||||
|
GDVIRTUAL0(_setup_local_to_scene);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static Node *(*_get_local_scene_func)(); //used by editor
|
static Node *(*_get_local_scene_func)(); //used by editor
|
||||||
|
|
|
@ -19,6 +19,21 @@
|
||||||
Override this method to return a custom [RID] when [method get_rid] is called.
|
Override this method to return a custom [RID] when [method get_rid] is called.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="_setup_local_to_scene" qualifiers="virtual">
|
||||||
|
<return type="void" />
|
||||||
|
<description>
|
||||||
|
Override this method to customize the newly duplicated resource created from [method PackedScene.instantiate], if the original's [member resource_local_to_scene] is set to [code]true[/code].
|
||||||
|
[b]Example:[/b] Set a random [code]damage[/code] value to every local resource from an instantiated scene.
|
||||||
|
[codeblock]
|
||||||
|
extends Resource
|
||||||
|
|
||||||
|
var damage = 0
|
||||||
|
|
||||||
|
func _setup_local_to_scene():
|
||||||
|
damage = randi_range(10, 40)
|
||||||
|
[/codeblock]
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="duplicate" qualifiers="const">
|
<method name="duplicate" qualifiers="const">
|
||||||
<return type="Resource" />
|
<return type="Resource" />
|
||||||
<param index="0" name="subresources" type="bool" default="false" />
|
<param index="0" name="subresources" type="bool" default="false" />
|
||||||
|
@ -58,8 +73,8 @@
|
||||||
<method name="setup_local_to_scene" is_deprecated="true">
|
<method name="setup_local_to_scene" is_deprecated="true">
|
||||||
<return type="void" />
|
<return type="void" />
|
||||||
<description>
|
<description>
|
||||||
Emits the [signal setup_local_to_scene_requested] signal. If [member resource_local_to_scene] is set to [code]true[/code], this method is called from [method PackedScene.instantiate] by the newly duplicated resource within the scene instance.
|
Calls [method _setup_local_to_scene]. If [member resource_local_to_scene] is set to [code]true[/code], this method is automatically called from [method PackedScene.instantiate] by the newly duplicated resource within the scene instance.
|
||||||
For most resources, this method performs no logic of its own. Custom behavior can be defined by connecting [signal setup_local_to_scene_requested] from a script, [b]not[/b] by overriding this method.
|
[i]Deprecated.[/i] This method should only be called internally. Override [method _setup_local_to_scene] instead.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="take_over_path">
|
<method name="take_over_path">
|
||||||
|
@ -90,9 +105,10 @@
|
||||||
[b]Note:[/b] This signal is not emitted automatically for properties of custom resources. If necessary, a setter needs to be created to emit the signal.
|
[b]Note:[/b] This signal is not emitted automatically for properties of custom resources. If necessary, a setter needs to be created to emit the signal.
|
||||||
</description>
|
</description>
|
||||||
</signal>
|
</signal>
|
||||||
<signal name="setup_local_to_scene_requested">
|
<signal name="setup_local_to_scene_requested" is_deprecated="true">
|
||||||
<description>
|
<description>
|
||||||
Emitted by the newly duplicated resource with [member resource_local_to_scene] set to [code]true[/code], when the scene is instantiated. Custom behavior can be defined by connecting this signal.
|
Emitted by a newly duplicated resource with [member resource_local_to_scene] set to [code]true[/code].
|
||||||
|
[i]Deprecated.[/i] This signal is only emitted when the resource is created. Override [method _setup_local_to_scene] instead.
|
||||||
</description>
|
</description>
|
||||||
</signal>
|
</signal>
|
||||||
</signals>
|
</signals>
|
||||||
|
|
Loading…
Reference in a new issue