Skip to content

Instantly share code, notes, and snippets.

@rutcreate
Created March 1, 2015 13:57
Show Gist options
  • Save rutcreate/b6fb8ff79d5ff769f2fd to your computer and use it in GitHub Desktop.
Save rutcreate/b6fb8ff79d5ff769f2fd to your computer and use it in GitHub Desktop.
Unity3D: C# Loop through class member using Reflection.
using UnityEngine;
using System.Collections;
using System.Reflection;
public class Configuration {
public const float musicVolume = 1.0f;
public const float sfxVolume = 1.0f;
public const string debugName = "Nirut";
public const int staticInt = 28;
public static string staticName = "I'm value from static";
public int mInt = 20;
public string mString = "This is string from class's member";
public Configuration() {}
}
public class TestLoopThroughMembers : MonoBehaviour {
private void Start() {
Configuration conf = new Configuration();
foreach (FieldInfo fieldInfo in conf.GetType().GetFields()) {
Debug.Log(fieldInfo.Name + ": " + fieldInfo.GetValue(conf) + " (" + fieldInfo.FieldType + ")");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment