This commit is contained in:
CortexCore
2024-04-16 04:15:21 +08:00
parent 337840ebb3
commit 3ffbaae6c8
26 changed files with 505 additions and 25 deletions

View File

@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using Godot;
using Org.BouncyCastle.Crypto.Digests;
namespace BITKit;
/// <summary>
@@ -8,6 +9,10 @@ namespace BITKit;
/// </summary>
public static partial class MathNode
{
public static T Cast<T>(this Node node) where T : Node
{
return (T)node.GetNode(new NodePath(node.Name));
}
/// <summary>
/// 获取Node下所有的子Node节点
/// </summary>
@@ -17,6 +22,8 @@ public static partial class MathNode
{
List<Node> nodes = new() { self };
For(self);
return nodes.Distinct();
void For(Node node)
{
foreach (var x in node.GetChildren())
@@ -25,9 +32,27 @@ public static partial class MathNode
nodes.Add(x);
}
}
return nodes.Distinct();
}
public static IEnumerable<Node> GetNodesInParent(Node self)
{
var nodes = new List<Node>() { self };
var parent = self.GetParent();
while (parent is not null)
{
nodes.Add(parent);
parent = parent.GetParent();
}
return nodes.Distinct();
}
public static bool TryGetNodeInParent<T>(Node self, out T node)
{
node = default;
var nodes = GetNodesInParent(self);
if (nodes.FirstOrDefault(x => x is T) is not T t) return false;
node = t;
return true;
}
public static void ClearChild(Node self)
{
foreach (var x in self.GetChildren())