Problem with GUIStyle and editor script

Hello.

I’m having a minor but annoying issue when i’m using my level editor which is an editor script.
I kinda had to use a custom GUIStyle for adjust the size of the scrollbar’s stuff but when I’m done with the script the editor is all messed up with the new GUIStyle.

I tried adding this line:

        GUI.skin = EditorGUIUtility.Load("Skin.guiskin") as GUISkin;

This is how I set my configuration in the script:

                    GUIStyle hStyle= GUI.skin.horizontalScrollbar;
                    hStyle.fixedHeight = window.position.height * 0.1f;
                    hStyle.fixedWidth = window.position.width * 0.1f;
                    GUIStyle hStylethumb = GUI.skin.horizontalScrollbarThumb;
                    hStylethumb.fixedHeight = window.position.height * 0.1f;
                    hStylethumb.fixedWidth = window.position.width * 0.1f;
                    GUIStyle vStyle= GUI.skin.verticalScrollbar;
                    vStyle.fixedHeight = window.position.height * 0.1f;
                    vStyle.fixedWidth = window.position.width * 0.1f;
                    GUIStyle vStylethumb = GUI.skin.verticalScrollbarThumb;
                    vStylethumb.fixedHeight = window.position.height * 0.1f;
                    vStylethumb.fixedWidth = window.position.width * 0.1f;

I have most of the inspector writing gone after that and have to close and launch again unity. What am I doing wrong or what is the workaround to this please?

Thanks for any help!

I didn’t test this, but maybe it helps if you create a new GUIStyle instead of using a reference to the one Unity uses.

by using the constructor which accepts an existing GUIStyle.

Example:

        GUIStyle hStyle = new GUIStyle(GUIStyleGUI.skin.horizontalScrollbar);
        hStyle.fixedHeight = window.position.height * 0.1f;
        hStyle.fixedWidth = window.position.width * 0.1f;
        GUIStyle hStylethumb = new GUIStyle(GUI.skin.horizontalScrollbarThumb);
        hStylethumb.fixedHeight = window.position.height * 0.1f;
        hStylethumb.fixedWidth = window.position.width * 0.1f;
        GUIStyle vStyle = new GUIStyle(GUI.skin.verticalScrollbar);
        vStyle.fixedHeight = window.position.height * 0.1f;
        vStyle.fixedWidth = window.position.width * 0.1f;
        GUIStyle vStylethumb = new GUIStyle(GUI.skin.verticalScrollbarThumb);
        vStylethumb.fixedHeight = window.position.height * 0.1f;
        vStylethumb.fixedWidth = window.position.width * 0.1f;