Skip to content

Instantly share code, notes, and snippets.

@aras-p
Created February 14, 2012 20:09
Show Gist options
  • Select an option

  • Save aras-p/1829848 to your computer and use it in GitHub Desktop.

Select an option

Save aras-p/1829848 to your computer and use it in GitHub Desktop.
cache instead
static public void SetRenderActiveFlagMode( ref GameObject parent, bool mode )
{
var pr = parent.renderer; // query the component just once!
if( pr != null )
{
pr.enabled = mode;
}
var pt = parent.transform; // query the component just once!
int childCount = pt.GetChildCount();
for(int i = 0; i < childCount ; i++)
{
var pc = pt.GetChild(i); // query the child just once!
Renderer rr = pc.renderer;
if( rr != null )
{
rr.enabled = mode;
}
GameObject go = pc.gameObject;
if( go != null )
{
SetRenderActiveFlagMode( ref go , mode );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment