Search Unity

Border variable in style for unity 2019/2020 behaves much different

Discussion in 'Editor & General Support' started by Nirvan, Jan 13, 2020.

  1. Nirvan

    Nirvan

    Joined:
    Nov 16, 2013
    Posts:
    134
    Newest version of unity broke all of my custom inspector windows.
    I am using class like this (check Style() method)

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3.  
    4. public class SimpleCustomGUI : MonoBehaviour
    5. {
    6.     public float testVariable = 1f;
    7. }
    8.  
    9. [CustomEditor(typeof(SimpleCustomGUI))]
    10. public class SimpleCustomGUIEditor : Editor
    11. {
    12.     public override void OnInspectorGUI()
    13.     {
    14.         SimpleCustomGUI targetScript = (SimpleCustomGUI)target;
    15.         DrawDefaultInspector();
    16.  
    17.         EditorGUILayout.BeginVertical(Style(new Color(1f,1f,1f,0.35f)));
    18.         EditorGUILayout.FloatField("Test", 1f);
    19.         EditorGUILayout.FloatField("Test", 1f);
    20.         EditorGUILayout.FloatField("Test", 1f);
    21.         EditorGUILayout.FloatField("Test", 1f);
    22.         EditorGUILayout.FloatField("Test", 1f);
    23.         EditorGUILayout.FloatField("Test", 1f);
    24.         EditorGUILayout.EndVertical();
    25.     }
    26.  
    27.     private GUIStyle Style(Color bgColor)
    28.     {
    29.         GUIStyle newStyle = new GUIStyle(GUI.skin.box);
    30.         newStyle.border = new RectOffset(-1, -1, -1, -1);
    31.         Color[] solidColor = new Color[1] { bgColor };
    32.  
    33.         Texture2D bg = new Texture2D(1, 1);
    34.         bg.SetPixels(solidColor);
    35.         bg.Apply();
    36.         newStyle.normal.background = bg;
    37.  
    38.         return newStyle;
    39.     }
    40. }
    Before new style it was looking like this:
    upload_2020-1-13_0-48-50.png
    But in new theme it looks like this:
    upload_2020-1-13_0-44-22.png

    What the hell?
    What I have to do in new version to make it look the same?
    Border variable now is working different, removing newStyle.border... is making it look better but borders are black then instead of bright.

    Strangest thing is, once it was working correctly even in unity 2020 but after I dropped my notebook to sleep, after wake it was looking like there.

    Edit:
    Ok I found trace, this broken look is when DPI scalling is not setted to be correct.
    Does exists there some internal variable to check this? :O
    I can do this with Screen.dpi but I'll check how can I use it correctly.
    Removing borders makes UI hard to read.
     
    Last edited: Jan 13, 2020