- Home /
Custom Inspector, Textfield with Icon
Hi,
I'm currently fooling around with some custom inspector stuff and since in the unity default inspector you can often see textfields with an icon inside the textfield I wondered how they did this? Look for example at the first item in every monobehaviour inspector where they show the script name, there's a little c# script icon right in front of the text. Does somebody know how to achieve this?
Greetings
Answer by Adam-Mechtley · Dec 08, 2016 at 09:16 AM
Hi! That particular field is an ObjectField, not a text field. Object fields (i.e. a serialized field that contains a reference to a UnityEngine.Object of some kind) will display the icon associated with the type in question. For custom scripts (e.g., MonoBehaviours or ScriptableObjects) this icon is the one specified on the script asset in your project view (up at the very top left of the Inspector when you have the script selected).
That said, if you are wanting to actually implement a text field with an icon or something on it, I strongly recommend you check out the PropertyDrawer class.
Thanks for the reply. Yeah the ObjectField works but it says that it's deprecated.
Oh never$$anonymous$$d it was just this version of the ObjectField method which is deprecated :D
Okay when I pass in the target field of my custom inspector as object it always say "GameObjectName (ScriptName)" in the unity editor, do you know how i can get it to just show the script name?
The reason the script field does not show the type in parentheses is that its type filter is set to typeof (UnityEditor.$$anonymous$$onoScript). If your type filter is e.g., a component type, then the text in the field will show you the GameObject name as well as the component type in parentheses so you have enough context to know what the object reference is. If you are just trying to show the script field in a custom Editor though, you can use:
EditorGUILayout.PropertyField (serializedObject.FindProperty ("m_Script"));
Your answer
Follow this Question
Related Questions
How should I generate an image of a model? 1 Answer
How to speed up TextField input? 0 Answers
Input not registering while TextField is selected 3 Answers
Lock a textarea/textfield for editing 1 Answer
GUI textfield duplicate text 0 Answers