- Home /
 
               Question by 
               fleity · Jun 22, 2021 at 05:37 PM · 
                inspectoreditor-scriptingeditorguipropertydrawer  
              
 
              How to get width at which Inspector does line breaks (for Vectors)
I am writing a property drawer which draws Vector4s as single lines in arrays using EditorGUI.Vector4Field(). I would like to keep the functionality of having it expand to two lines when the inspector is narrow.
something along these lines works
 EditorGUIUtility.currentViewWidth < 345 ? baseHeight * 2 : baseHeight;
but how do I get the correct value instead of the magic number 345?

 
                 
                linebreakwidth.jpg 
                (13.9 kB) 
               
 
              
               Comment
              
 
               
              Answer by Proliecan · Jun 23, 2021 at 10:04 AM
You will have to make a CustomPropertyDrawer
Documentation: https://docs.unity3d.com/Manual/editor-PropertyDrawers.html
I am writing a property drawer
... I have done that. The question is about how to achieve the line break in this custom property drawer without comparing with this magic number.
 [CustomPropertyDrawer(typeof(VectorInlineAttribute))]
 public class VectorInlinePropertyDrawer : PropertyDrawer
 {
 
   ...
 
     public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
     {
         float baseHeight = base.GetPropertyHeight(property, label);
         if (property.propertyPath.Contains(".Array.")) { return baseHeight; }
         else
         {
             return EditorGUIUtility.currentViewWidth < 345 ? baseHeight * 2 : baseHeight;
         }
     }
 }
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                