mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 10:55:54 +00:00
Destroyable props
This commit is contained in:
parent
93469062a1
commit
44ebc70448
52 changed files with 1387 additions and 18428 deletions
24
Scripts/Utils/MapProxy3D.cs
Normal file
24
Scripts/Utils/MapProxy3D.cs
Normal 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");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
1
Scripts/Utils/MapProxy3D.cs.uid
Normal file
1
Scripts/Utils/MapProxy3D.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://crpgy1o73rtlx
|
||||
64
Scripts/Utils/Tools3D.cs
Normal file
64
Scripts/Utils/Tools3D.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
1
Scripts/Utils/Tools3D.cs.uid
Normal file
1
Scripts/Utils/Tools3D.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://frydabuff8ab
|
||||
Loading…
Add table
Add a link
Reference in a new issue