Created
September 29, 2012 17:59
-
-
Save AngryAnt/3804730 to your computer and use it in GitHub Desktop.
Example code for "Logging an entire GameObject" blog post on AngryAnt.com
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 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