I am creating a custom property drawer. I want the label for my property , but instead of drawing the control for my property I want to draw a popup with string choices. Now this is all fine and is drawn sorta right. Now my problem is whenever I resize the inspector the width of my popup will change and my x is changing. Now they should be changing like the rest of the controls do, but they are changing wrong. They are becoming too wide and moving too far to the left, while the label stays in the proper spot. Anyone know how to fix it so it stays the right width and x position? I want it the same as the enums variables below it.
Here is my code:
[CustomPropertyDrawer(typeof(StringVerEnum))]
public class StringVerEnumDrawer : PropertyDrawer
{
string[] options = { "Item1", "Item2", "Item3", "Item4", "Item5™" };
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
int choice = property.enumValueIndex;
GUIContent LabelText= new GUIContent("My Label","My tooltip");
EditorGUI.PrefixLabel(position, LabelText);
var PopupPosition = new Rect(position.x + (position.x/0.1f), position.y , position.width -(position.width/3f) , position.height);
EditorGUI.BeginChangeCheck();
choice = EditorGUI.Popup(PopupPosition, choice, options);
if (EditorGUI.EndChangeCheck())
{
property.enumValueIndex = choice;
}
}
}
StringVerEnum is an attribute that I am using for the variable/property that is using this property drawer, incase that somehow matters. Now it is also entirely possible my position change values are just wrong, I’m not entirely sure. I do know when I use position it is the rect for the label and the control. It would be nice if there was someway to get the rect for just the label and just the control to try to make sure that everything is in the right place , but haven’t been able to find anything in the docs that does that. Any help with getting my control/popup to always be in the right position is greatly appreciated.