Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by t79 · Apr 10, 2019 at 12:26 PM · guieditorsliderserializedproperty

How to make a SerializedProperty with a list of values?

Hi

I am trying to make a custom editor with a slider, that only shows specific values. e.g.: 5, 7,8,11,321,512.

From https://docs.unity3d.com/ScriptReference/EditorGUILayout.Slider.html it looks like that

public static void Slider(SerializedProperty property, float leftValue, float rightValue, params GUILayoutOption[] options);

is the function to use. But I do not find out how to make the SerializedProperty.

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 t79 · Apr 10, 2019 at 12:43 PM 0
Share

Do not manege to save the topics: Editor, Slider, SerializedProperty

avatar image dan_wipf t79 · Apr 10, 2019 at 03:00 PM 0
Share

i did save it for you.

1 Reply

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

Answer by dan_wipf · Apr 10, 2019 at 02:12 PM

If you want to have a custom Slider, which shows an Array of integer Values (5, 7,8,11,321,512) you need to do something like this:


Int Slider


Editor Script

 using UnityEngine;
 using UnityEditor;
 [CustomEditor(typeof(Value))]
 public class ValueEditor : Editor
 {
     SerializedProperty intRange;
     float select = 0;   
     public override void OnInspectorGUI()
     {
         intRange = serializedObject.FindProperty("intRange");
         select = CustomIntSlider(intRange,select);
     }
     float CustomIntSlider(SerializedProperty property,float selected){
         EditorGUILayout.BeginHorizontal();
         EditorGUILayout.LabelField("My Slider",GUILayout.Width(100));
         selected = GUILayout.HorizontalSlider(Mathf.Round(selected),0,property.arraySize-1);
         EditorGUILayout.IntField(property.GetArrayElementAtIndex((int)selected).intValue,GUILayout.Width(50));
         EditorGUILayout.EndHorizontal();
         return selected;
     }
 }
 


Monobehaviour

 using System.Collections.Generic;
 using UnityEngine;
 [UnityEditor.CanEditMultipleObjects]
 public class Value : MonoBehaviour
 {
     public List<int> intRange = new List<int>(){5,7,8,11,321,512};
 }    


bildschirmfoto-2019-04-10-um-160941.png (14.9 kB)
Comment
Add comment · Show 2 · 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 t79 · Apr 11, 2019 at 11:45 AM 0
Share

Perfect!

It relay did what I was hoping for and thank you wherry much. :) But unsure if I should change the question since you did not use EditorGUILayout.Slider.

avatar image t79 · Apr 11, 2019 at 12:24 PM 0
Share

Here is the function I did end up using, simplify it since the slider was already in a begin/endHorizontal with a label. The source is the keys from a dictionary.

 int PropertyValueSlider(int[] values, int selectedIndex)
     {
         selectedIndex = (int)$$anonymous$$athf.Round(GUILayout.HorizontalSlider(selectedIndex, 0, values.Length - 1));
         EditorGUILayout.IntField(values[selectedIndex], GUILayout.Width(40));
         return selectedIndex;
     }

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

254 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 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 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 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 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 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 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 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 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 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

How do I get a slider to modify an input field and vice versa? 0 Answers

how can i control a float in Javascript with a UI Slider 1 Answer

Best way to add file chooser dialog 0 Answers

Receiving strange error for first time 1 Answer

Auxiliary data class for editor 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