- Home /
Create a drag and drop element in the custom editor for textures.
Hey there,
If you have a game object that has a script that has a texture, you can drag a texture from the asset panel onto the texture variables text box thing and it will apply that texture.
I wish to create something like that for my own custom editor, but when I use:
Script.m_Texture = (Texture2D)EditorGUILayout.ObjectField("Texture", Script.m_Texture, typeof(Texture2D), true);
It comes up with a big ugly texture box.
Does anyone know how to recreate the texture box in the default inspector?
Additionally: When you create an EditorGUILayout and pass in a blank GUIStyle, EVERYTHING disappears. How do you get the icons on the right hand side of a (for example) drop down list to show up again? I can't figure out which part of the GUIStyle controls those.
Thanks in advance!!
Ok, I've partial solved it. I needed to use the Serialized Property things that the GUI uses. The EditorGUILayout.PropertyField provides exactly the right stuff.
I still need to figure out how to properly style the GUIElements. I would like to remove the background box, but keep the little buttons that are on the right. If anyone can help with that it'd be appreciated.
I'm a bit confused, are you trying to create it so that the 2D texture appears on screen????
Sorry no; I'll clarify.
Everything I'm mentioning here has to do with the default inspector panel and how to modify it.
If you create a script and attach it to an object and that script has an enum variable in it, then there is a drop down list in the inspector, right? And it has two arrows on the right had side of it, one pointing up and one pointing down.
What I've done is created a drop down list like that in my custom editor and have created a GUIStyle that has nothing in it and applied that GUIStyle to said dropdown list.
However, in doing that it has removed ALL of the styling from the dropdown list, including the little icon on the right hand side of the list in the inspector.
$$anonymous$$y question, now is: How do I get that icon to show up using GUIStyles on a valid EditorGUILayout?
C#
I thought I said so, but it must have been in my last post.
Answer by UnityBrains · Dec 16, 2011 at 12:05 AM
Okay. Both of these have been solved.
First problem: Solved with SerializedProperty and using a property box.
Second problem: Used a blank GUISkin.
I now have an exact replica of the texture box in the default inspector. Mission accomplished. If anywone has the same problem, I can go into more detail if needed. The answers are out there, though.
Your answer
Follow this Question
Related Questions
if texture used from class it does not show in game, advice needed? 1 Answer
how do you use the terrain tools? 1 Answer
Is there a way to change the shader on all meshes without doing it manually one by one? 3 Answers
Assign texture to shader bypassing material (in Unity Editor) 1 Answer
Isolating a single channel of a texture in the Inspector ? 0 Answers