Sorry for digging, but I’m working on custom editor script now, and I’m wondering if there’s a possibility to create a EnumField directly in .uxml file?
I’ve tried this:
@patrickf Hi, I found that specifying type for EnumField in UXML doesn’t work for nested type. like this:
namespace MyNamespace
{
public class MyClass
{
public eum MyEnum{}
}
}
MyNamespace.MyClass.MyEnum doesn’t work. If I move MyEnum to the outside of MyClass, it works. Is this intended behaviour? and how to specify nested types in UXML?
I have the same issue that an enum field now doesn’t work anymore for my editor scripts. Which before was the easiest task, now seems to be a massive pain in the ass, plus a nightmare to debug if the type string / namespace changes, which happens quite often, mostly in the early stages of a project.
I use the UI Builder to check UI Toolkit out for the first time, the first field is an enum and my world falls apart already. Here is the enum definition:
Here is my class that contains the enum:
namespace Source.Components.Common
{
[RequireComponent(typeof(Image))]
public class ImageFX : MonoBehaviour
{
public enum Effect
{
Glow,
Flash,
Shine,
GlowSoftMask,
FlashSoftMask,
}
[...]
}
}
I get a popup type attribute invalid, make sure to include assembly name.
I tried Source.Components.Common.ImageFX.Effect as-well.
The generated UXML window shows as my new editor layout, but the enum field has no values.
PS: I also tried to fill the enum popup via code, which would be fine for me, but this doesn’t seem to work either:
[CustomEditor(typeof(ImageFX))]
public class ImageFxEditor : UnityEditor.Editor
{
public void OnEnable()
{
VisualTreeAsset visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/Source/Components/Common/Editor/ImageFX.uxml");
var ui = visualTree.Instantiate();
var enumField = ui.Q<EnumField>("effect");
enumField.Init(ImageFX.Effect.Glow);
}
}
I feel like this should at least work, but it doesn’t somehow…
For you and for someone that need. You need to create a assembly definition of the your project. Take a look at some AssemblyDefinition tutorial.
In My case, i created a folder for my UIElement project, called “GMB”, (Game Manager BackEnd).
At my GMB folder project i have scripts for behaviour and scripts only for editor, so i have a folder for Editor too.
I created a Assembly Definition in root of my GMB Folder and other in Root of Editor Folder of the my GMB Folder.
In my Assembly Definition of Editor, i have a assemblyDefinition Reference, that is my GMB Assembly definition, and it is set to only Editor plataform. So now, my ENUM work very fine, because i can use my GMB Assembly name, that contains my custom enum.
My Custom enum path is: GMB.Data_ItemIngredient.RequireIngredientType.
My Assembly name is GMB.
BUT, Keep in mind that i use namespace GMB for all my project, so this is my assembly name, and i use GMBEditor namespace for all only editor scripts… Thats is it!