Last active
March 13, 2024 05:53
-
-
Save baba-s/2a35637204b60cfe77443211cc0810e2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 UnityEngine; | |
namespace Kogane | |
{ | |
public static class ComponentExtensionMethods | |
{ | |
public static GameObject FindByNameContains<T> | |
( | |
this T self, | |
string name, | |
bool includeInactive = false | |
) where T : Component | |
{ | |
var children = self.GetComponentsInChildren<Transform>( includeInactive ); | |
for ( var i = 0; i < children.Length; i++ ) | |
{ | |
var child = children[ i ]; | |
if ( !child.name.Contains( name, StringComparison.Ordinal ) ) continue; | |
return child.gameObject; | |
} | |
return null; | |
} | |
} | |
} |
This file contains hidden or 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 UnityEngine; | |
namespace Kogane | |
{ | |
public static class GameObjectExtensionMethods | |
{ | |
public static GameObject FindByNameContains | |
( | |
this GameObject self, | |
string name, | |
bool includeInactive = false | |
) | |
{ | |
var children = self.GetComponentsInChildren<Transform>( includeInactive ); | |
for ( var i = 0; i < children.Length; i++ ) | |
{ | |
var child = children[ i ]; | |
if ( !child.name.Contains( name, StringComparison.Ordinal ) ) continue; | |
return child.gameObject; | |
} | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment