using System; using Godot; namespace Babushka.scripts.CSharp.Common.Util; public static class NodeExtension { /// /// Searches for a parent node of the specified type. /// /// The type of the parent node to search for. The search is successful, when searchedNode is T /// The node from which to start the search. /// The parent node of type T if found, otherwise throws an exception. public static T FindParentByType(this Node self) { var parent = self.GetParent(); while (parent != null) { if (parent is T tParent) { return tParent; } parent = parent.GetParent(); } throw new Exception($"Parent of type {typeof(T)} not found for node {self.Name}"); } }