- Home /
Inspector button to generate code?
So what I can't find information about is how to get the inspector button to generate code. For example I want to create ten level parameters, but do not want to constantly have to go into the LevelManager type out each one, but instead be able to type in all the strings and click Add Level and it will generate the code.
So instead of typing out another level02, I hit the inspector Add button and it will generate this for me. How would I go about doing this? Thanks.
[System.serializable]
public class level01
{
//code
}
public class LevelManager : MonoBehavior
{
public level01 level01Parameters;
}
You need to learn how to write Editor scripts.
http://docs.unity3d.com/ScriptReference/Editor.html
When I was doing my first editor script, I found it helpful to look over some existing scripts:
Answer by CodeMasterMike · Aug 06, 2014 at 05:06 AM
There is a "Create Script dialog" editor extension in the Asset store, which generates scripts. Maybe you can look at that code and make your own from that:
https://www.assetstore.unity3d.com/en/#!/content/2668
But there are other ways to make what you want.
I personally, would make a class which I would call something like "CustomLevel", and this class would have all the level data I would need for each level.
So when clicking on your "Add Level" button in the editor, it will create a new instance of the CustomLevel class and store it in a list.
And then in the inspector you could have the whole list of all your custom levels, and by choosing one from the list, the data for that specific level will be presented and you can edit it as you wish.
Your answer
Follow this Question
Related Questions
Unity Custom Editor Texture Warning 2 Answers
Distribute terrain in zones 3 Answers
Reorderable list of UnityEvents 2 Answers
Make a custom inspector that shows a group of variables in form of list 2 Answers
How do I change inspector values of other game objects using a custom Editor Window 0 Answers