mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 22:25:54 +00:00
Destroyable props
This commit is contained in:
parent
93469062a1
commit
44ebc70448
52 changed files with 1387 additions and 18428 deletions
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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue