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 ronaldosilva · Mar 19, 2014 at 01:22 AM · editorcustomize

How to display a serialized property inside a min max slider?

Hy Everyone, I am trying to display a min max slider to control a float variable inside my target class. But I Keep getting the error saying that I have a problem with the overload method. I think this is because I nedd to cast my serialized property as (float) inside the min max slider method, but I still get the same error. Any ideas?

Obs: I am creating a Flies System (non particle based) asset to publish for FREE on asset store, so, your help is very appreciated!

Thanks everyone! =)

 using UnityEngine;
 using UnityEditor;
 
 [CustomEditor (typeof(FliesSystem))]
 public class FliesSystemEditor : Editor {
     
     private SerializedObject instance; 
     private SerializedProperty minVelocity;
     private SerializedProperty maxVelocity;
 
     public void OnEnable()
     {
         if(instance == null) instance = new SerializedObject(target);
 
         minVelocity = instance.FindProperty("minVelocity");
         maxVelocity = instance.FindProperty("maxVelocity");
     }
 
     public override void OnInspectorGUI()
     {
 
         instance.Update();    
         EditorGUILayout.MinMaxSlider(ref minVelocity, ref maxVelocity, 0f,10f);
         instance.ApplyModifiedProperties();
     }
 }
 
 
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

2 Replies

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

Answer by frarees · Mar 19, 2014 at 07:18 PM

Wrap your property implementation using EditorGUI.BeginProperty and EditorGUI.EndProperty as done here.

Use SerializedProperty API to access the serialized value (e.g. floatValue... use type to identify which type is holding that property).

Comment
Add comment · Show 4 · 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 20, 2014 at 12:43 AM 0
Share

Hi man, thank you for the answer. I will check it out soon and give give you some feedback! Thanks!

avatar image ronaldosilva · Mar 25, 2014 at 01:37 PM 0
Share

Hi! I am reading the documentation, its all too confusing for me. For instance, why the heck do I need to specify a rect around my property, and how is it done? I can't find any example of that. I guess the documentation is lacking some clarity around these topics yet. Anyway, I'll keep trying. Thanks!

avatar image frarees · Mar 25, 2014 at 02:08 PM 0
Share

How always need to specify a rect (unless using GUILayout, which would do it internally for you). I highly recommend inspecting the UnityEditor assembly to see how Unity works internally with them. Good luck!

avatar image DKasper_3DQR · Jul 07, 2017 at 02:40 PM 0
Share

Why don't you simply use EditorGUILayout.IntSlider(SerializedProperty property, int leftValue, int rightValue, GUIContent label, params GUILayoutOption[] options) ? Wasn't this function available back in 2014?

avatar image
0

Answer by EugeneJefferson · Nov 23, 2020 at 10:32 PM

in target class [SerializeField, Range(0f, 1f)] protected float val = 0;

in Editor Class EditorGUILayout.PropertyField(serializedObject.FindProperty("val"));

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.

Follow this Question

Answers Answers and Comments

23 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

Related Questions

New Project/Scene - Change Default Settings? 2 Answers

How to Draw in Scene View "unconditionally"? 0 Answers

AudioManager.Update & EditorOverhead taking CPU 1 Answer

Event Mouse not working correctly 1 Answer

Adding to GameObject context menu WITHOUT [MenuItem(...)] 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