Last active
June 5, 2019 00:25
-
-
Save BlueBreathHI/373105b83008b28c00589ae5881d9542 to your computer and use it in GitHub Desktop.
Get all child objects. (TestFile use OdinInspector)
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.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using System.Linq; | |
public static class GetAllChildren_Object{ | |
public static GameObject[] GetAllChildren(this GameObject thisObj,bool getInvalid = false){ | |
return thisObj.GetComponentsInChildren<Transform>(getInvalid).Where(com => com != thisObj.transform).Select(com => com.gameObject).ToArray(); | |
} | |
} | |
public static class GetAllChildren_Component{ | |
public static GameObject[] GetAllChildren(this Component thisCom,bool getInvalid = false){ | |
return thisCom.GetComponentsInChildren<Transform>(getInvalid).Where(com => com != thisCom.transform).Select(com => com.gameObject).ToArray(); | |
} | |
} |
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.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using Sirenix.OdinInspector; | |
using System.Linq; | |
public class GetAllChildrenTest : MonoBehaviour | |
{ | |
[Button] | |
void GetAllChildren_Test(){ | |
GameObject[] children = gameObject.GetAllChildren(); | |
children.ToList().ForEach(x=>Debug.Log("Child:"+ x.name)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment