38 lines
951 B
C#
38 lines
951 B
C#
|
|
using UnityEngine;
|
||
|
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
|
||
|
|
public static class TransformDeepChildExtension
|
||
|
|
{
|
||
|
|
//Breadth-first search
|
||
|
|
public static Transform FindDeepChild(this Transform aParent, string aName)
|
||
|
|
{
|
||
|
|
if (aParent == null) return null;
|
||
|
|
|
||
|
|
var result = aParent.Find(aName);
|
||
|
|
if (result != null)
|
||
|
|
return result;
|
||
|
|
foreach (Transform child in aParent)
|
||
|
|
{
|
||
|
|
result = child.FindDeepChild(aName);
|
||
|
|
if (result != null)
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static Transform FindDeepParent(this Transform achild, string aName)
|
||
|
|
{
|
||
|
|
if (achild == null) return null;
|
||
|
|
|
||
|
|
var result = achild.Find(aName);
|
||
|
|
if (result != null)
|
||
|
|
return result;
|
||
|
|
|
||
|
|
result = achild.parent.FindDeepParent(aName);
|
||
|
|
if (result != null)
|
||
|
|
return result;
|
||
|
|
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
}
|