- Home /
Property Drawer toggles working between the UI and the item.
I think this might be a simple problem. I have a custom property drawer for a script and most of the variables are linked. I also have two toggles in the property drawer, only one of which can be active at a time that expand the inspector height. The problem I am having is trying link matching bool values in the inspected item to the UI inspectors bool values. My main question is how to access a bool in the inspected script from the property drawer without drawing said bool value.
This is the code for the toggles in the property drawer:
bool weaponFold;
bool armorFold;
public override void OnGUI(Rect _pos, SerializedProperty _prop, GUIContent _label)
{
ToggleWepon(EditorGUI.ToggleLeft(wepFoldRectLabel, "Weapon", weaponFold));
ToggleArmor(EditorGUI.ToggleLeft(armorFoldRectLabel, "Armor", armorFold));
}
public void ToggleWepon(bool toggle)
{
if (toggle)
{
ToggleArmor(false);
}
weaponFold = toggle;
}
public void ToggleArmor(bool toggle)
{
if (toggle)
{
ToggleWepon(false);
}
armorFold = toggle;
}
Is there any way for me to assign my armorFold & weaponFold variables to the armor & weapon bool variables of the drawn script?
Answer by Pablomon · Mar 23, 2018 at 12:28 PM
I would say what you need is:
SerializedProperty weaponBool = property.FindPropertyRelative("Weapon");
weaponBool.boolValue = EditorGUI.ToggleLeft(wepFoldRectLabel, "Weapon", weaponFold);
Your answer
Follow this Question
Related Questions
Property Drawer and Inheritance 0 Answers
Can I have an attribute-based and a class-based property drawer on the same field? 0 Answers
Using EditorGUI.ObjectField in PropertyDrawer 0 Answers
Writing PropertyDrawers for functions. 1 Answer
CustomPropertyDrawer: foldout issues when switching properties (simulating weak references) 0 Answers