์—ฌ๊ธฐ ๋ณต๋ถ™ํ•˜๋ฉด ์ •์ƒ์œผ๋กœ ๋ณด์ด๋Š”๋ฐ ์‹ค์ œ๋กœ ๊ธ€ ์˜ฌ๋ฆฌ๋ฉด ๋“ค์—ฌ์“ฐ๊ธฐ๊ฐ€ ๋‹ค ์—†์–ด์ง€๋„ค


์ฝ”๋“œ ์˜ฌ๋ฆฌ๋Š” ์ธ๋ถ•์ด๋“ค์€ ์–ด์ผ€ ํ•˜๋Š”๊ฑฐ์ž„



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using Godot;
using System;
namespace Godot
{
private static Node FindChildNodeOfTypeRecursive(Node node, Type type)
{
if (node.GetType() == type)
{
return node;
}
else if (node.GetChildCount() > 0)
{
foreach (Node child in node.GetChildren())
{
Node rv = FindChildNodeOfTypeRecursive(child, type);
if (rv != null)
return rv;
}
}
return null;
}
public static T GetChildOfType<T>(this Node node) where T : Node
{
Type type = typeof(T);
return FindChildNodeOfTypeRecursive(node, type) as T;
}
}
}
cs