- Home /
Custom Editor - Show variable if bool is true in class list
Hello, I am going to show varable ExampleString if ExampleBool is true independently of each other.
public class Example : MonoBehaviour
{
public List<ExampleClass> ExampleList = new List<ExampleClass>();
[System.Serializable]
public class ExampleClass
{
public bool ExampleBool;
[HideInInspector]
//if ExampleBool is true show this string in inspector
public string ExampleString;
}
}
Answer by Dray · Nov 25, 2017 at 05:17 PM
I've been looking for the same thing and unfortunately it seems like that attribute doesn't exist by now. You could build your own attribute that does what you want but I figured that would take more effort than just implementing a CustomEditor:
[CustomEditor(typeof(Example))]
public class ExampleEditor : Editor
{
public override void OnInspectorGUI()
{
var instance = (Example) this.target;
instance.toggle = GUILayout.Toggle (instance.toggle, "toggle me");
if (instance.toggle == true) {
instance.foo = EditorGUILayout.IntField (instance.foo);
}
}
}
i am trying to do it in class list. This is code for do it out of the list this is a construction:
I'd do the same thing I posted above in a loop then:
[CustomEditor(typeof(Example))]
public class ExampleEditor : Editor
{
public override void OnInspectorGUI()
{
var instance = (Example) this.target;
var list = instance.yourList;
foreach(var item in list) {
item.toggle = GUILayout.Toggle (item.toggle, "toggle me");
if (item.toggle == true) {
item.foo = EditorGUILayout.IntField (item.foo);
}
}
}
}
hmm, list not showing(only this vars)
[1]: /storage/temp/106345-przechwytywanie.png
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Custom Editor DragAndDrop for List 1 Answer
Public list are not reflecting in inspector. 1 Answer
3D game kit Ellen / Show Player Input script variables on the inspector, 0 Answers
Update list on mouse click 1 Answer