- Home /
Make a custom inspector that shows a group of variables in form of list
I want to make my inspector look clean and tidy, so I'm asking this question. I have 3 variables, (Z offset, Y offset and X offset) and I want to "hide" them under some kind of arrow. Think of how Unity handles lists and arrays, you click on the arrow and it shows the values to edit. In this case, I want to make something like that to show these 3 variables. Is this possible? Thanks.
Answer by Raimi · Sep 16, 2017 at 10:25 PM
public class MainClass: MonoBehaviour
{
public SomeClass someClass;
void Start()
{
//Example usage;
if(someClass.xOffset == 0)
{
someClass.xOffset = 10;
}
}
}
[System.Serializable]
class SomeClass
{
public float xOffset = 0;
public float yOffset = 0;
public float zOffset = 0;
}
Thanks. That kind of works, but how do I make this in a custom inspector script? (script that derives from "Editor")? That would help me a lot. Thanks again.
You can find out more about custom inspectors at the following link to the official unity tutorial...
https://unity3d.com/learn/tutorials/topics/interface-essentials/building-custom-inspector
I would just like to add, custom inspectors only add better visual representations.
Some people spend more time creating custom inspectors than writing good usable code. Editor scripts just add more to the work load and more scripts to maintain.
Unless you have a specific need for a custom inspector, id leave it out.
Answer by $$anonymous$$ · Sep 17, 2017 at 06:10 PM
I managed to do this by using EditorGUILayout. (I don't think I need to state my code, since the docs say everything).
Thanks everyone that tried to help me.
Your answer
Follow this Question
Related Questions
Custom Editor DragAndDrop for List 1 Answer
Unity Custom Editor Texture Warning 2 Answers
Edit existing editor inspector? 1 Answer
How to show an array of custom objects in Inspector? 2 Answers