Search Unity

Show/Hide Scriptable Object depending on bool value

Discussion in 'Immediate Mode GUI (IMGUI)' started by mrCharli3, Apr 16, 2018.

  1. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    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?