Hello,
I created a custom editor with uxml and uss, which works perfectly fine, but now, I am trying to display it within an EditorWindow. However I can only display the default inspector (commented code) using OnInspectorGUI.
Any help is appreciated, thanks a lot.
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
public class EditorTest : EditorWindow {
private static int _armor = 75;
private static int _damage = 25;
[MenuItem("EditorTest/Open _%#T")]
public static void ShowWindow() {
// Opens the window, otherwise focuses it if it’s already open.
var window = GetWindow<EditorTest>();
// Adds a title to the window.
window.titleContent = new GUIContent("EditorTest");
// Sets a minimum size to the window.
window.minSize = new Vector2(250, 50);
}
/*
private void OnGUI() {
var editor = Editor.CreateEditor(TestEditorWindow.Instance);
editor.OnInspectorGUI();
}*/
private void OnEnable() {
var editor = Editor.CreateEditor(TestEditorWindow.Instance);
editor.CreateInspectorGUI();
}
}
public class TestEditorWindow : System.ScriptableSingleton<TestEditorWindow> {
public int armor = 75;
public int damage = 25;
public string text;
}
[CustomEditor(typeof(TestEditorWindow))]
public class TestEditorWindowEditor : Editor {
public override VisualElement CreateInspectorGUI() {
VisualElement customInspector = new VisualElement();
var quickToolVisualTree = Resources.Load<VisualTreeAsset>("EditorTest_Main");
quickToolVisualTree.CloneTree(customInspector);
customInspector.styleSheets.Add(Resources.Load("custom-editor-uie-style") as StyleSheet);
return customInspector;
}
}
