- Home /
How do I expose public properties in the same way the inspector does via a gui in game?
I'm using C#, I have a base class for my gametypes which contains most of the code that is common to every gametype, and I extend this class when I want to add a new gametype which has very specific functionality. I want to make all of the properties of each game mode public for the player to change via a menu, but have one GUI screen which will morph to fit the requirements of each gametype. How do I figure out what properties each gametype has without having to hard code it? I basically want to do what the insector does and show all of the public properties in my own GUI.
Answer by appearance · Feb 22, 2013 at 06:55 AM
I think you can achieve this using Reflection.
Check here for microsoft's docs on reflection.
Check here for FieldInfo documentation.
You can obtain "System.Type" of your object, ex:
System.Type objtype = myobject.GetType();
System.Reflection.FieldInfo[] fields = objtype.GetFields();
System.Reflection.PropertyInfo[] properties = objtype.GetProperties();
System.Reflection.MethodInfo[] methods = objtype.GetMethods();
If you have got answer to your question, please select it as "Answered" so that it will not appear in "Unanswered list"
Your answer
Follow this Question
Related Questions
Update variables with C# properties in customeditor 2 Answers
What is frame, How OnGuI is called every frame? 2 Answers
What Am I Doing Wrong? Variable Names 3 Answers
Font sizes, GUI, Iphones and even more head scracthing problems 0 Answers
Problem using EditorGUILayout.ObjectField with custom type 1 Answer