Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
1
Question by yoyo · Oct 13, 2010 at 11:29 PM · inspectorslider

Can I use custom inspector widgets, such as a slider for a floating point property, without writing a custom editor?

Suppose I have a class with 10 public properties, which all happen to be floats. If I want one of them controlled by a slider, is there a code attribute I can add to do so, or do I have to write a custom editor that knows about all 10 properties and implements text boxes for nine of them and a slider for the other one?

I suspect I need a custom editor, which is unfortunate. I browsed all the answers related to "inspector", and this was the closest I found:

http://answers.unity3d.com/questions/18198/whats-attribute-to-limit-range-of-serialized-variable

Many thanks.

EDIT: As of Unity 4, the PropertyDrawer class enables precisely what I was looking for when I asked this question.

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

3 Replies

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

Answer by skovacs1 · Oct 14, 2010 at 03:12 PM

I believe that you are correct in your assumption that a CustomEditor is the solution. An attribute would be a great way to do this, but that's not the way the code was written. I'm surprised how few questions there are on CustomEditor, but they aren't that hard.

If you check the docs on Editor, there is a good js example of a CustomEditor - target is the object being inspected and it is of the type specified as the type your CustomEditor is for. To do it in another language isn't that much different. The different built-in GUI interfaces that you can use can be found in EditorGUILayout.

Comment
Add comment · Show 1 · 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 yoyo · Oct 14, 2010 at 07:16 PM 0
Share

Thanks, that's what I thought. I've created custom editors, I agree they aren't that hard -- though on a complex object (lists, custom structs, etc.) they can get tricky. It's a shame there's not a way to override the widget used for a single property, rather than having to override the editor for the entire component.

avatar image
5

Answer by sotirosn · Nov 21, 2013 at 02:16 AM

I think you can just use the range attribute.

 class MyClass : MonoBehaviour {
    [Range(0, 1)]
    public float sliderValue;
 
    public float otherValue;
 }
Comment
Add comment · Show 1 · 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 tfunk · Jul 30, 2014 at 10:15 PM 0
Share

This does just what I was looking for, and is very simple! Thanks!

avatar image
1

Answer by yoyo · Nov 15, 2010 at 08:28 PM

This isn't precisely what I want, but useful enough to call out. The DrawDefaultInspector() method does just what it says, which is useful if you want to add a control or two to the normal editor. You can add a slider for one of the 10 attributes and keep the standard textbox control as well.

http://unity3d.com/support/documentation/ScriptReference/Editor.DrawDefaultInspector.html

If you want the default widgets available just as an "advanced" feature of your editor, this works nicely (_foldoutDefaultInspector is a bool member variable of the editor):

_foldoutDefaultInspector = EditorGUILayout.Foldout(_foldoutDefaultInspector, "Advanced");
if (_foldoutDefaultInspector)
{
    EditorGUILayout.BeginHorizontal();
    GUILayout.Space(12);
    DrawDefaultInspector();
    EditorGUILayout.EndHorizontal();
}
Comment
Add comment · Show 1 · 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 rakkarage · Sep 16, 2014 at 06:20 PM 0
Share

maybe use EditorGUIUtility.singleLineHeight ins$$anonymous$$d of 12?

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.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Array has length 0, but I can see its' elements in the inspector 1 Answer

Restrict sliders in Unity inspector to have different values 1 Answer

slider bar in inspector 4 Answers

Inspector slider value? 2 Answers

Move camera with inspector slider and include it's current location? 2 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