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