28 lines
526 B
C#
28 lines
526 B
C#
using UnityEngine;
|
|
|
|
namespace BitStrap
|
|
{
|
|
public static class GameObjectExtensions
|
|
{
|
|
public static T GetComponentInParent<T>(this GameObject self, bool includeInactive) where T : Component
|
|
{
|
|
if (includeInactive)
|
|
{
|
|
T val = (T)null;
|
|
Transform transform = self.transform;
|
|
while (transform != null)
|
|
{
|
|
val = transform.GetComponent<T>();
|
|
if (val != null)
|
|
{
|
|
break;
|
|
}
|
|
transform = transform.parent;
|
|
}
|
|
return val;
|
|
}
|
|
return self.GetComponentInParent<T>();
|
|
}
|
|
}
|
|
}
|