Duplicate inspector with some controls as in game GUI

Is it possible to have a replication of the Unity inspector with some components such as the physics controls and menu items as a GUI in game.
I doubt it but worth a shot to ask. I noticed a function called:

Editor.DrawDefaultInspector *bool DrawDefaultInspector(); Description Draw the built-in inspector.

Call this function from inside OnInspectorGUI method to draw the automatic inspector. It is useful you don’t want to redo the entire inspector, but you want to add a few buttons to it.*

So that would create a custom inspector but how to add the components and how to put that into the game? It would be a huge bonus if the controls actually could take in data and act like they do in Unity but I very much doubt that. But it would be a start and save a lot of GUI work it think. So any ideas that would be great and any scripting examples please use C#.

Most likely I’ll have to do it the normal way and create a custom GUI I have access to iGUI and NGUI. I’ve looked at some tutorials on basic controls examples (iGUI site) but I’m interested in all the physics controls which I get lost on how to do. So if someone can show the scripting steps how to do just one of the physics components (say the joints) that would be great. If in iGUI that would be great but the scripting will be very similar no matter the way it’s made so I’ll take any kind of example. Cheers

You can’t use any editor functionality in game. The whole UnityEditor namespace simply doesn’t exist at runtime. So whenever you found a function that might be useful, first check to which namespace it belongs. UnityEngine → ok UnityEditor → forget it.

edit
Ok just to explain that a bit more in detail:

Unity uses Mono as scripting environment. Mono is an open source implementation of “.NET”. You have almost the whole .NET framework avaliable. If you want to know what classes / methods of the .NET framework are available check the MonoCompatibility page (this site is huge, so wait until it’s loaded).

Unity(the engine) itself also provides classes and functions which you can use in your game. If you take a look at the scripting reference you can see a dropdown menu at the top left. All categories starting with “Runtime” can be used in game. Those classes are inside the UnityEngine namespace.

Unity(the editor application) provides it’s own set of classes which can be used by editor scripts to extend the editors functionality. All categories starting with “Editor” can only be used in editor scripts inside the editor. Those classes belong to the UnityEditor namespace which doesn’t exist at runtime, so they can’t be used in your game.

The reflection system, which got mentioned by Ben and yoyo is part of the Mono/.NET framework and allows type inspection of any class / method / field / property at runtime. Reflection is quite slow compared to “normal” class usage, but allows at access things in a more generic way and even to access private members which you normally couldn’t access.

The reflection system provides a lot classes which are used to describe other types / classes / methods / …

The most important class is the System.Type class. The system has an System.Type instance for every type that exists in your runtime. You can get this type object by using the typeof operator or using the GetType function of any variable at runtime. In UnityScript there is no typeof operator. You can directly use a type to get it’s type object.

The Type object provides a lot properties which describe what kind of type it is, it’s name and everything you can actually know about the type ;). You can use GetFields / GetMethods / GetProperties / … To get a special class instance which describe all the fields / methods / properties which are defined by this class / struct / type.

The system is designed to be as versatile as possible. Since .NET / Mono has quite a few complex language constructs, like generics, nested classes and indexers, the system is often a pain to use. It will take you a while until you get behind how it works and how to use it.

At this point i want to stress this a bit more: Reflection shouldn’t be used for the “normal” programming stuff. It actually breaks OOP encapsulation and can be really slow. It’s not the preferred way to do something. However in “some” cases it’s the only way.

As for the GUI side of your question, you have to program it yourself. You can either use the Unity GUI system like the editor does, or if you have other GUI frameworks like NGUI / EzGUI / … you can roll your own solution.

Finally a last hint which should be used with caution. You can use ILSpy, which is an opensource .NET reflector which allows you to look “into” .NET DLLs and decompile them to IL or C#. That way you can “see” how the UnityEditor works behind the scene. Be warned that a lot methods are linked to native code which can’t be seen or decompiled. However a lot of the EditorGUI stuff would also work at runtime. The inspector code would not since it relies heavily on the editors functionality.

I have no clue what’s the legal border if you would use code snippets from the UnityEditor.dll in your game code since that wasn’t designed/ment to be included in game code. So it’s up to you if you simply copy & paste some of the editor code or roll your own version (inspired by the editor code ;)).

All in all to mimic the inspectors functionality at runtime requires a lot work. In most cases it makes more sense to just build some of the required GUI controls like you would for a settings screen.