Skip to content

Instantly share code, notes, and snippets.

@shanestevens
Forked from AngryAnt/Utilities.cs
Created December 2, 2012 04:22
Show Gist options
  • Save shanestevens/4186948 to your computer and use it in GitHub Desktop.
Save shanestevens/4186948 to your computer and use it in GitHub Desktop.
Example code for "Logging an entire GameObject" blog post on AngryAnt.com
using UnityEngine;
using System.Reflection;
public class Utilities
{
/* ... */
static void LogGameObject( GameObject gameObject, bool children )
{
Component[] components = gameObject.GetComponents( typeof( Component ) );
FieldInfo[] fields;
PropertyInfo[] properties;
Debug.Log( gameObject.name + ":" );
foreach( Component component in components )
{
Debug.Log( " - " + component.GetType().Name + ":" );
fields = component.GetType().GetFields();
foreach( FieldInfo field in fields )
{
Debug.Log( " ." + field.Name + " = " + field.GetValue( component ) );
}
properties = component.GetType().GetProperties();
foreach( PropertyInfo property in properties )
{
Debug.Log( " ." + property.Name + " = " + property.GetGetMethod().Invoke( component, null ) );
}
}
if( children )
{
foreach( Transform transform in gameObject.transform )
{
Debug.Log( "->" );
LogGameObject( transform.gameObject, children );
}
}
}
static void LogGameObject( GameObject gameObject )
{
LogGameObject( gameObject, false );
}
/* ... */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment