2024-08-17 17:00:50 +02:00
|
|
|
using Godot;
|
2024-06-09 18:19:57 +02:00
|
|
|
|
|
|
|
|
namespace Cirno.Scripts;
|
|
|
|
|
|
|
|
|
|
public static class Tools
|
|
|
|
|
{
|
2024-08-17 17:00:50 +02:00
|
|
|
public static T CreateChild<T>(this Node2D node, PackedScene prefab) where T : Node2D
|
|
|
|
|
{
|
|
|
|
|
if (prefab == null) return null;
|
|
|
|
|
var newInstance = prefab.Instantiate<T>();
|
2024-08-17 19:11:49 +02:00
|
|
|
node.GetParent().CallDeferred("add_child", newInstance);
|
|
|
|
|
// Need to use parent instead of owner because tilemap scenes have no owner
|
|
|
|
|
//node.Owner.CallDeferred("add_child", newInstance);
|
2024-08-17 17:00:50 +02:00
|
|
|
newInstance.Transform = node.GlobalTransform;
|
|
|
|
|
newInstance.Position = node.Position;
|
2024-06-09 18:19:57 +02:00
|
|
|
|
2024-08-17 17:00:50 +02:00
|
|
|
return newInstance;
|
|
|
|
|
}
|
|
|
|
|
}
|