• 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
0
Question by ronaldosilva · Mar 25, 2014 at 02:29 PM · editor

What is the best way to create custom inspectors?

Hi everyone! I am messing around with the custom inspectors, but I noticed a vast lexicon around the topic, and now I don't know the best way to create one with advanced controls with serialized properties. For instance: When should I use property drawers, or just a custom inspector that extends Editor? Or, why certain controls are so hard to implement, like the min max slider with a serialized float variable? Anyway, its all too confusing for me now...

Comment
Add comment · Show 2
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 frarees · Mar 25, 2014 at 03:07 PM 1
Share

PropertyDrawers can be used to reuse editor parts e.g. a radio button, a curve representation, a field to properly hold an IP address... You can of course use implement custom editors that draw custom properties. It depends on what you want to implement. I recommend you to inspect and experiment with the EditorGUI class (and some others like GUILayout, ProjectWindow, InspectorWindow...), that will help you understand how editor stuff works.

I've made a simple custom MinMax slider with property drawers. I don't have that code here, I can share it when I'm back home.

avatar image Randomman159 · Mar 25, 2014 at 03:21 PM 0
Share

I feel as if there is an incredible lack of documentation on the topic of customizing the editor. Custom inspectors, windows, etc. I too am currently working my way into it, so my advice is to just read sample code to see what others have done. Hopefully you can pull it together from that.

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by frarees · Mar 26, 2014 at 07:41 PM

Here's a MinMaxSlider implementation I did some time ago.

https://gist.github.com/frarees/9791517

Comment
Add comment · Show 10 · 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
avatar image ronaldosilva · Mar 27, 2014 at 02:06 AM 0
Share

Hi man! You are really trying to help me! haha I appreciate it! As I understood, you are kinda creating a new property with this code, right? And how would you implement it (use it) in a custom editor class? Would you show it to me? I will try to reason over the code you provided anyway. If I succeed, you will be the first one to put the hands on my Flies System as a prize for your good will.

avatar image frarees · Mar 27, 2014 at 09:23 AM 0
Share

If you want to use it in a custom editor class, then use PropertyField. Fast example:

 [MinMaxSlider (0f, 100f)]
 public Vector2 myVector;

OnInspectorGUI:

 EditorGUILayout.PropertyField (serializedObject.FindProperty ("myVector"));

avatar image ronaldosilva · Mar 27, 2014 at 03:07 PM 0
Share

Great! Will test it right now! Thanks!

avatar image ronaldosilva · Mar 27, 2014 at 03:53 PM 0
Share

alt text

Great! It worked, now I am trying to add the labels that show the current Min and Max values on the inspector. Any ideas?

Thanks man! Helped a lot!

ui.jpg (28.7 kB)
avatar image ronaldosilva · Mar 27, 2014 at 04:02 PM 1
Share

Yeah I am editing the MinMaxSliderDrawer to add some labels and stuff! Now I understant this PropertyDrawer thing. Nifty. Have a nice day man!

Show more comments
avatar image
0

Answer by MadRobot · May 31, 2016 at 07:09 PM

To create a custom slider in a custom editor inspector is very easy.

Assuming you have already saved 'target' to a variable called 'source' in OnEnable()...

     const string tooltip = "T$$anonymous$$s is a slider";
     const string sliderLabel = "POWER";
     float minValue = 1.0f;
     float maxValue = 3.7f;

     void OnInspectorGUI()
     {
         source.myVariable = EditorGUILayout.Slider(new GUIContent(sliderLabel, tooltip), source.myVariable, minValue, maxValue);
     }


Comment
Add comment · 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

26 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 avatar image avatar image avatar image avatar image

Related Questions

My projects doesn't work! 0 Answers

Are textured/z-clipped gizmos possible? 0 Answers

Filter out materials from imported mesh 0 Answers

Unity Editor - Create a custom scene view 0 Answers

Constant error : SaveSnapshot called without previous call to MakeSnapshot 1 Answer


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