Hide/show variables in the inspector using an enum

5.3k views Asked by At

I am currently working on a larger project with some artists, programmers, level designer, art director etc. Now the artists and level designers are not that keen on code, so they are very depended on the variables shown in the inspector and I want to make as easy as possible for them to use.

So in the inspector of a gameobject I want some variables to be shown depended on the value of a public enum variable. Is there a way to do this using macros and [HideInInspector] or other?

We are using C# by the way.

1

There are 1 answers

0
Ricardo Reiter On BEST ANSWER

You will need create a Custom Editor for that.

Exemple, create a slider only if a flag is true:

public class MyScript : MonoBehaviour
{
   public bool flag;
   public int i = 1;
}

[CustomEditor(typeof(MyScript))]
public class MyScriptEditor : Editor
{
   void OnInspectorGUI()
   {
       var myScript = target as MyScript;

       myScript.flag = GUILayout.Toggle(myScript.flag, "Flag");

       if(myScript.flag)
           myScript.i = EditorGUILayout.IntSlider("I field:", myScript.i , 1 , 100);

   }  
}

Code taken from a same question:
http://answers.unity3d.com/questions/192895/hideshow-properties-dynamically-in-inspector.html