I want to make one DLL file with all code and assets for small Editor tool.
In this case I need some UI for custom Editor window, and I am going to make it with UI Toolkit.
So, I have 3 files: C# script, .uxml file and .uss file. And I need to do something like this for making editor window:
// Each editor window contains a root VisualElement object
VisualElement root = rootVisualElement;
// Import UXML
var visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/Scripts/UI/AutoGenSkybox.uxml");
VisualElement labelFromUXML = visualTree.Instantiate();
root.Add(labelFromUXML);
The problem is that the AssetDatabase will not work with the uxml file as embeded DLL resource. So I am using this:
Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name);
How can I convert this data to VisualTreeAsset?
We rely on a scripted importer to process the .uxml and .uss into a usable asset. I never tried including assets in a dll like you are doing, but I am pretty certain the asset database won’t know about theses. You can possibly save the imported asset as a .asset, and load that file from the dll, but this will make the asset specific to that version of the editor.
Are you able to use an imported asset (like a texture or a scriptable object) form the dll?
I think that I can include only text or byte[ ] assets in to DLL what C# BinaryFormatter or Stream reader will understand. The main goal of DLL - to be one separate file which I can just drop in Assets folder without any another folders and files. So I assumed there was an option to convert UXML text to VisualElement. But, as I see, this may not be very reliable.
I will be able to achieve my goal by writing C# code for the UI instead of saving it in UXML file. Just wanted to make sure that this is the best option.
Thank You!