Created
October 11, 2022 03:35
-
-
Save kaiyumcg/0d053969ada9297bcb58375879ced0c0 to your computer and use it in GitHub Desktop.
Find component in disabled parent gameobjects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
//Put this file in any location inside Asset Folder of unity project | |
//except any special folder. https://docs.unity3d.com/Manual/SpecialFolders.html | |
public static class Ext | |
{ | |
internal static T ExGetComponentInParent<T>(this GameObject g, bool includeInactive = false) | |
{ | |
var ts = g.GetComponentsInParent<T>(includeInactive); | |
return ts == null || ts.Length == 0 ? default : ts[0]; | |
} | |
internal static T ExGetComponentInParent<T>(this Transform t, bool includeInactive = false) | |
{ | |
var ts = t.GetComponentsInParent<T>(includeInactive); | |
return ts == null || ts.Length == 0 ? default : ts[0]; | |
} | |
internal static T ExGetComponentInParent<T>(this MonoBehaviour script, bool includeInactive = false) | |
{ | |
var ts = script.GetComponentsInParent<T>(includeInactive); | |
return ts == null || ts.Length == 0 ? default : ts[0]; | |
} | |
internal static T ExGetComponentInParent<T>(this Component component, bool includeInactive = false) | |
{ | |
var ts = component.GetComponentsInParent<T>(includeInactive); | |
return ts == null || ts.Length == 0 ? default : ts[0]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment