Open emberTrev opened 1 year ago
Screenshot of
ShowNativePropertyTest
component in action in the Test Scene.
I have become aware of this checkbox in the project settings. Not a fan of it, but I guess it could be a workaround.
ShowIf/HideIf also do not work with UI Toolkit and Unity 2022.3
So I guess that even if it were possible for me to use the Odin inspector to customize the look and feel of my tools for people that download it (who may or may not have Odin inspector themselves), it would be problematic because it would be version dependent?
On Thu, 16 Nov 2023, 14:26 Roger Crawfis, @.***> wrote:
ShowIf/HideIf also do not work with UI Toolkit and Unity 2022.3
— Reply to this email directly, view it on GitHub https://github.com/dbrizov/NaughtyAttributes/issues/369#issuecomment-1814536388, or unsubscribe https://github.com/notifications/unsubscribe-auth/BCXLXGITXTR453UIGBUXDOLYEYPBVAVCNFSM6AAAAAA3Y3INVOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMJUGUZTMMZYHA . You are receiving this because you are subscribed to this thread.Message ID: @.***>
If you write custom editor UI that uses either IMGUI or UI Toolkit (not both), then yes your custom inspector won't appear for everyone. You can:
I don't know anything about Odin inspector.
Follow-up: NaughtyAttributes already has a full IMGUI implementation, so it needs to add to or replace the implementation with UI Toolkit to support newer Unity versions.
@emberTrev did enabling that checkbox return your buttons? It doesn't do anything for me on 2022.3.15f
Can you give a reproducable example? My test works:
Project Settings
- Editor
-> Uncheck Inspector: Use IMGUI Default Inspector
public class Cap : MonoBehaviour
{
[ShowNonSerializedField] public static readonly Color red = Color.red;
[ShowNativeProperty] public Color blue => Color.blue;
[Button]
private void EditorButton()
{
Debug.Log("EditorButon");
}
}
Update: Got it, but my case is using it with UIKit drawers, the UIKit drawers can not be rendered correctly
Yes, the issue I am reporting is that the UIKit drawers do not work. Since that is the default setup for newer versions of Unity, people who start new projects will install this extension and see that it doesn't work unless they know or find out about the Inspector: Use IMGUI Default Inspector
. I do not have enough control over my team's project to change the Inspector: Use IMGUI Default Inspector
checkbox for everyone.
I realize that to make UIKit work, the author would probably have to re-implement all the features of the extension in UIKit, which would be a lot of work. I guess that is what I am requesting since Unity is missing these features and they are very useful, but I can't use them on my team's project currently.
Are you saying it isn't possible to implement the same feature set in UIKit?
OK after some digging here is the thing
It's not possible to render ToolKit inside IMGUI
It's possible to render IMGUI to ToolKit in public override VisualElement CreatePropertyGUI(SerializedProperty property)
VisualElement container = new VisualElement();
IMGUIContainer imGuiContainer = new IMGUIContainer(() =>
{
myDrawerTool.MyImGuiDraw(myRect, property, label);
});
imGuiContainer.style.height = myRect.height;
container.Add(imGuiContainer);
return container;
As this makes the whole thing a callback, many things that are easy in IMGUI becomes tricky. For example, you need to call property.serializedObject.ApplyModifiedProperties();
which is unnecessary for IMGUI PropertyDrawer
And yes, a hell lots of adaption for this change... (Odin actually supports UIToolKit+IMGUI by this IMGUIContainer , but in my test case, oddly, IMGUI sometimes does not work very well in Odin)
(I'm trying to implement it in my util project and, yes, it's hell lot of pain...)
I am going to post this again from my original issue.
From here: https://docs.unity3d.com/ScriptReference/PropertyDrawer.html
Note: You cannot have UI Toolkit running inside IMGUI, which means that if your custom PropertyDrawer only has a UI Toolkit implementation, it will not work inside an IMGUI custom Inspector or a parent IMGUI custom PropertyDrawer. In Unity 2022.2 and above, the default Inspector uses UI Toolkit exclusively in custom PropertyDrawers. Prior to 2022.2, it is recommended that you either implement both IMGUI and UI Toolkit versions of each PropertyDrawer, or make sure they are exclusively used inside custom UI Toolkit inspectors.
So that's why my expectation would be that you would have to re-implement everything with a UI Toolkit version that has the same behavior as the IMGUI version.
Sorry about this work that the Unity upgrade has brought to the surface. I feel like the bearer of bad news.
Sorry about this work that the Unity upgrade has brought to the surface. I feel like the bearer of bad news.
Well, agreed...
I just adapted my project SaintsField
to support UI Toolkit. And I completely rewrite every components. I don't think there is a shortcut.
(If you like it please give a star, thanks!)
And my experience about UI Toolkit as an editor extension, is painful. Yes it's delightful how easy to handle elements and style, but most things are missing for editor. I quote from my project's README:
Label width. UI Toolkit uses a fixed label width 120px. However, this value is different when the field is nested and indented.
In IMGUI, we have
EditorGUIUtility.labelWidth
,EditorGUI.indentLevel
, which is absolutly not avaliable in UI Toolkit, and there is no way to get the label width.SaintsField
just use the fixed label width.Even most UI Toolkit fields are fixed label width, there is one that the label width behavior exactly like IMGUI:
PropertyField
. This bug has been reported to Unity (Sorry I can't find the link now), but is never fixed.
SaintsField
heavily relies onPropertyField
to fallback the appearence. This is not even fixable at this point. If you try to obtain the info by query out thePropertyField
element, you'll notice that Unity is internally using a script (rather than a uss style) to update it's label width.Even without using any custom inspector, if you use your UI Toolkit
PropertyDrawer
with default fields, your inspector label will not aligned, and makes it look really rediculous.This is not fixable.
PropertyField
of anObject
will give an error when click:NullReferenceException: ... UnityEditor.ProjectBrower.FrameObject...
. Clicking will still lead you to active the target object, but I have no idea where this came from. Even official's example will have this error if you just add aPropertyField
to it. Clicking on the error message will lead to theConsole
tab's layout got completely messed up.This is not fixable.
DropdownField
will tread a label's change as a value change... I have no idea why this happens and why onlyDropdownField
. Luckily this change event will give anewValue=null
so I can work around with it.
My project is very new and not fully tested. For people who want a stable editor plus UI Toolkit? Yeah, just pay for OdinInspector...
Edit:
Oh, and also, when leaving an PropertyDrawer
when active a new target, the old one's CreatePropertyGUI
will also get called once. It's not a big deal in most case, but... I just don't know why, and how, and what?
I have also tried this and I can say that Foldout doesn't work for me. I' on Unity 2022.3.20f1. Sucks, because this really looked like a powerful tool that I could use. Even Using IMGUI tickbox to either true or false, nothing appears. Foldouts don't work at all.
I have also tried this and I can say that Foldout doesn't work for me. I' on Unity 2022.3.20f1. Sucks, because this really looked like a powerful tool that I could use. Even Using IMGUI tickbox to either true or false, nothing appears. Foldouts don't work at all.
Well, after half years, 50+ literation, I have fixed many issues in SaintsField and I personally feel it's stable, well, at least in my personal projects and company projects.
It's a hell lot of pain to adapted to UI Toolkit.
You may have a try, at this point it already has almost all features of NaughtyAttributs plus more
Here is an excerpt from Unity's docs:
https://docs.unity3d.com/ScriptReference/PropertyDrawer.html
I added NaughtyAttributes to my project (running 2022.3) and these are the attributes that I noticed did nothing. There are probably more.