Created
March 1, 2015 13:57
-
-
Save rutcreate/b6fb8ff79d5ff769f2fd to your computer and use it in GitHub Desktop.
Unity3D: C# Loop through class member using Reflection.
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.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