c# - Iterating through multiple levels of Child Objects -


i have block of code. , need iterate through every child object, child objects have more children within them. awake() method called when program first ran. so, i'm asking how build iterator check if there children within children. , run resizemeshcollection(meshfilter[] collection) on children, until there no more child objects.

    public class resizeasset : monobehaviour {       void awake()     {         resizemeshcollection(this.getcomponentsinchildren<meshfilter>());     }      void resizemeshcollection(meshfilter[] collection)     {         foreach (meshfilter mf in collection)         {             mf.getcomponent<meshfilter>();             transform tf = mf.getcomponent<transform>();             /// resize logic here             /// check if there children under child object,              /// run resizemeshcollection() on             /// children until there no more. 

i'm sure not want run resizemeshcollection() within itself, nor know if possible, can't figure out how this.

the way wrote how want it. method called recursion. popular way of achieving trying do, nothing wrong having method calling itself, if done within guidelines meeting criteria before executing again.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -