Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Question Custom Editors and Hiding Properties

Discussion in 'UGUI & TextMesh Pro' started by ut110, Jan 22, 2023.

  1. ut110

    ut110

    Joined:
    May 31, 2018
    Posts:
    8
    Hey I have a quick question, I have a slider editor script for a script which inherits from the Slider script, that a looks something like this

    Code (CSharp):
    1. using UnityEditor;
    2.  
    3. namespace UnityEngine.UI
    4. {
    5.     [CustomEditor(typeof(SliderWithBetterControls))]
    6.     public class NewSliderOptions : Editor
    7.     {
    8.         SerializedProperty moveIncrement;
    9.         SerializedObject sliderObject;
    10.         SliderWithBetterControls slider;
    11.  
    12.         private void OnEnable()
    13.         {
    14.             slider = (SliderWithBetterControls)target;
    15.             sliderObject = new SerializedObject(slider);
    16.             moveIncrement = sliderObject.FindProperty("moveIncrement");
    17.         }
    18.  
    19.         public override void OnInspectorGUI()
    20.         {
    21.             sliderObject.Update();
    22.  
    23.             DrawDefaultInspector();
    24.  
    25.             EditorGUILayout.BeginHorizontal();
    26.             EditorGUILayout.Slider(moveIncrement, 0.1f, 100f, "Move Increment Percent:");
    27.             EditorGUILayout.EndHorizontal();
    28.  
    29.             sliderObject.ApplyModifiedProperties();
    30.         }
    31.     }
    32. }
    and a slider normally hides a bunch of properties depending on what transition type you have selected, but with this code it just shows it all. Now, I could replicate that default behavior myself, but I was wondering if there was an easy way, like one line to just say to do the default thing. Anyone know?
     
    Last edited: Jan 27, 2023