♻️ migrated the InteractionAreas currently used to the new format and removed the old code

This commit is contained in:
2025-11-04 17:20:15 +01:00
parent 8d616735f4
commit 8b77ca9bc5
15 changed files with 132 additions and 70 deletions
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Godot;
namespace Babushka.scripts.CSharp.Common.Util;
@@ -23,4 +24,54 @@ public static class NodeExtension
}
throw new Exception($"Parent of type {typeof(T)} not found for node {self.Name}");
}
//acts like Unity's GetComponent<T> / GetComponentInChildren<T>
// only works with Godot's built-in types.
public static T GetChildByType<T>(this Node node, bool recursive = true)
where T : Node
{
int childCount = node.GetChildCount();
for (int i = 0; i < childCount; i++)
{
Node child = node.GetChild(i);
if (child is T childT)
return childT;
if (recursive && child.GetChildCount() > 0)
{
T recursiveResult = child.GetChildByType<T>(true);
if (recursiveResult != null)
return recursiveResult;
}
}
return null;
}
/// <summary>
/// Another reimplementation of Unity's GetComponent<T>.
/// Verified to work with all types, also derived ones, but only when used from within a scene and at runtime.
/// </summary>
/// <param name="node"></param>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public static T GetComponent<T>(Node node)
{
if (node is T)
{
return (T)(object)node;
}
foreach (Node child in node.GetChildren())
{
if (child is T)
{
return (T)(object)child;
}
}
return (T)(object)null;
}
}