-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindAllChilds.cs
More file actions
59 lines (48 loc) · 1.3 KB
/
Copy pathFindAllChilds.cs
File metadata and controls
59 lines (48 loc) · 1.3 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
private List<GameObject> AllChilds(GameObject root)
{
List<GameObject> result = new List<GameObject>();
if (root.transform.childCount > 0)
{
foreach (Transform VARIABLE in root.transform)
{
Searcher(result,VARIABLE.gameObject);
}
}
return result;
}
private void Searcher(List<GameObject> list,GameObject root)
{
list.Add(root);
if (root.transform.childCount > 0)
{
foreach (Transform VARIABLE in root.transform)
{
Searcher(list,VARIABLE.gameObject);
}
}
}
/* OTHER */
USE : gameobjet.GetAllChilds()
List<Transform> GetAllChilds(Transform _t)
{
List<Transform> ts = new List<Transform>();
foreach (Transform t in _t)
{
ts.Add(t);
if (t.childCount > 0)
ts.AddRange(GetAllChilds(t));
}
return ts;
}
/* EXTENSION */
public static class TransformExtension {
public static List<Transform> GetAllChildren(this Transform parent, List<Transform> transformList = null)
{
if (transformList == null) transformList = new List<Transform>();
foreach (Transform child in parent) {
transformList.Add(child);
child.GetAllChildren(transformList);
}
return transformList;
}
}