Destroyable props

This commit is contained in:
Marco 2025-06-19 17:55:23 +02:00
commit 44ebc70448
52 changed files with 1387 additions and 18428 deletions

View file

@ -0,0 +1,24 @@
using Godot;
namespace Cirno.Scripts.Utils;
[Tool]
public partial class MapProxy3D : Node3D
{
[ExportToolButton("Rebuild")] public Callable RebuildButton => Callable.From(Rebuild);
public void Rebuild()
{
if (!Engine.IsEditorHint()) return;
var children = GetChildren();
foreach (var child in children)
{
if (child.HasMethod("verify_and_build"))
{
child.Call("verify_and_build");
}
}
}
}

View file

@ -0,0 +1 @@
uid://crpgy1o73rtlx

64
Scripts/Utils/Tools3D.cs Normal file
View file

@ -0,0 +1,64 @@
using Godot;
namespace Cirno.Scripts.Utils;
public static class Tools3D
{
public static T CreateChild<T>(this Node3D node, PackedScene prefab) where T : Node3D
{
return CreateChild<T>(node, prefab, node.GlobalPosition);
}
public static T CreateChild<T>(this Node3D node, PackedScene prefab, Vector3 position) where T : Node3D
{
return CreateChildOf<T>(node, node, prefab, position);
// if (prefab == null) return null;
// var newInstance = prefab.Instantiate<T>();
// 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);
// newInstance.Transform = node.GlobalTransform;
// newInstance.Position = position;
//
// return newInstance;
}
public static T CreateSibling<T>(this Node3D node, PackedScene prefab) where T : Node3D
{
return CreateChildOf<T>(node, node.GetParent<Node3D>(), prefab, node.GlobalPosition);
}
public static T CreateSibling<T>(this Node3D node, PackedScene prefab, Vector3 position) where T : Node3D
{
return CreateChildOf<T>(node, node.GetParent<Node3D>(), prefab, position);
}
public static T CreateChildOf<T>(this Node3D node, Node3D parentNode, PackedScene prefab) where T : Node3D
{
return CreateChildOf<T>(node, parentNode, prefab, node.GlobalPosition);
}
public static T CreateChildOf<T>(this Node3D node, Node3D parentNode, PackedScene prefab, Vector3 position) where T : Node3D
{
if (prefab == null)
{
GD.PrintErr("Tried to instantiate a null prefab");
return null;
}
if (parentNode == null)
{
GD.PrintErr("Tried to instantiate child of a null parent");
return null;
}
var newInstance = prefab.Instantiate<T>();
//node.GetParent().CallDeferred("add_child", newInstance);
parentNode.CallDeferred("add_child", newInstance);
//newInstance.Transform = node.GlobalTransform;
newInstance.Position = parentNode.ToLocal(position);
return newInstance;
}
}

View file

@ -0,0 +1 @@
uid://frydabuff8ab