• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by kamuzai1226 · Aug 06, 2014 at 04:35 AM · c#inspectorcustom-inspector

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;
 }

Comment

People who like this

0 Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · Aug 06, 2014 at 05:06 AM 1
Share

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:

http://wiki.unity3d.com/index.php/Scripts/Editor

1 Reply

· Add your reply
  • Sort: 
avatar image

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.

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

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

Unity Editor - Class variable value contrain 4 Answers

How do I change inspector values of other game objects using a custom Editor Window 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges