Traveller/scripts/utils/NodeUtils.cs

39 lines
1.0 KiB
C#
Raw Normal View History

using System.Threading.Tasks;
using Godot;
2024-04-28 13:55:19 +00:00
namespace ColdMint.scripts.utils;
public class NodeUtils
{
/// <summary>
/// <para>Delete all child nodes</para>
/// <para>删除所有子节点</para>
/// </summary>
/// <param name="parent"></param>
public static int DeleteAllChild(Node parent)
2024-04-28 13:55:19 +00:00
{
var deleteNumber = 0;
2024-04-28 13:55:19 +00:00
var count = parent.GetChildCount();
if (count <= 0) return deleteNumber;
for (var i = 0; i < count; i++)
2024-04-28 13:55:19 +00:00
{
var node = parent.GetChild(0);
parent.RemoveChild(node);
node.QueueFree();
deleteNumber++;
2024-04-28 13:55:19 +00:00
}
return deleteNumber;
}
/// <summary>
/// <para>All child nodes are removed asynchronously</para>
/// <para>异步删除所有子节点</para>
/// </summary>
/// <param name="parent"></param>
/// <returns></returns>
public static async Task<int> DeleteAllChildAsync(Node parent)
{
return await Task.Run<int>(() => DeleteAllChild(parent));
2024-04-28 13:55:19 +00:00
}
}