Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    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