- Home /
GUISkin and CustomEditor
Hey there,
Is there something special I have to do to get a GUISkin working in a custom editor? I currently have the code:
using UnityEditor;
using UnityEngine;
using System.Collections;
[CustomEditor(typeof(TexturedObjectCS))]
public class TexturedObjectEditorCS : Editor
{
public override void OnInspectorGUI()
{
GUI.skin = new EditorSkin();
...but it's not working. It's giving me an error about converting EditorSkin to GUISkin. All of the documentation, however, indicates that this should work. I created a skin by going Assets > Create > GUI Skin and named it EditorSkin.
Answer by UnityBrains · Dec 15, 2011 at 07:54 AM
Okay, I got it sorted. You have to load the GUISkin resource for some reason. I might look into the details later.
Instead of
GUI.skin = new EditorSkin();
I had to use
GUI.skin = (GUISkin)(Resources.LoadAssetAtPath("Assets/EditorSkin.guiskin", typeof(GUISkin)));
Awesome.
Thanks for the answer. Two considerations: 1.In Unity 5 - 2017 it changed to UnityEditor.AssetDatabase.LoadAssetAtPath 2.I guess It would be better to load this line OnEnable, save it as a local variable an use it on the iterations. Ex:
private GUISkin mySkin;
void OnEnable()
{
mySkin = (GUISkin)(UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/$$anonymous$$yCoolSkin.guiskin", typeof(GUISkin)));
}