Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  4. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Show/Hide Scriptable Object depending on bool value

Discussion in 'Extensions & OnGUI' started by mrCharli3, Apr 16, 2018.

  1. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    287
    I want to show/hide some values depending on if a bool variable is set to true or false in the editor. I can do it with an int like this:

    Code (CSharp):
    1. public class MyScript : MonoBehaviour
    2. {
    3.    public bool flag;
    4.    public int i = 1;
    5. }
    6. [CustomEditor(typeof(MyScript))]
    7. public class MyScriptEditor : Editor
    8. {
    9.  
    10. override public void OnInspectorGUI()
    11.    {
    12.      var myScript = target as MyScript;
    13.      myScript.flag = GUILayout.Toggle(myScript.flag, "Flag");
    14.    
    15.      if(myScript.flag)
    16.        myScript.i = EditorGUILayout.IntSlider("I field:", myScript.i , 1 , 100);
    17.    }
    18. }
    I cannot find the correct EditorGUILayout component to use for a scriptable object. How can I do this?