Giter VIP home page Giter VIP logo

Comments (13)

emberTrev avatar emberTrev commented on June 2, 2024

image
Screenshot of ShowNativePropertyTest component in action in the Test Scene.

from naughtyattributes.

emberTrev avatar emberTrev commented on June 2, 2024

I have become aware of this checkbox in the project settings. Not a fan of it, but I guess it could be a workaround.
Screenshot_2023-08-22-10-45-23_Unity

from naughtyattributes.

crawfis avatar crawfis commented on June 2, 2024

ShowIf/HideIf also do not work with UI Toolkit and Unity 2022.3

from naughtyattributes.

Elliot0112358 avatar Elliot0112358 commented on June 2, 2024

from naughtyattributes.

emberTrev avatar emberTrev commented on June 2, 2024

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:

  1. Write both if you want to support everyone.
  2. Write only the UI Toolkit version if you are ok ignoring old versions of Unity Editor. I'm not sure how far back that will work. It's not like UI Toolkit was added with 2022.2, that is just when IMGUI was turned off.
  3. Writing only an IMGUI implementation seems like the worst choice since IMGUI is totally turned off starting with Unity Editor 2022.2. (You can re-enable it manually, see my previous comments in this thread.)

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.

from naughtyattributes.

ADH-LukeBollam avatar ADH-LukeBollam commented on June 2, 2024

@emberTrev did enabling that checkbox return your buttons? It doesn't do anything for me on 2022.3.15f

from naughtyattributes.

TylerTemp avatar TylerTemp commented on June 2, 2024

Can you give a reproducable example? My test works:

  1. Unity: 2022.3.16f1
  2. NA: 2.1.4
  3. Project Settings - Editor -> Uncheck Inspector: Use IMGUI Default Inspector

屏幕截图 2024-01-01 185202

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");
    }
}

屏幕截图 2024-01-01 185240


Update: Got it, but my case is using it with UIKit drawers, the UIKit drawers can not be rendered correctly

from naughtyattributes.

emberTrev avatar emberTrev commented on June 2, 2024

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?

from naughtyattributes.

TylerTemp avatar TylerTemp commented on June 2, 2024

OK after some digging here is the thing

  1. It's not possible to render ToolKit inside IMGUI

  2. 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;
  3. 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

  4. 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...)

from naughtyattributes.

emberTrev avatar emberTrev commented on June 2, 2024

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.

from naughtyattributes.

TylerTemp avatar TylerTemp commented on June 2, 2024

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:

  1. 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.

  2. 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 on PropertyField to fallback the appearence. This is not even fixable at this point. If you try to obtain the info by query out the PropertyField 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.

  3. PropertyField of an Object 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 a PropertyField to it. Clicking on the error message will lead to the Console tab's layout got completely messed up.

    This is not fixable.

  4. DropdownField will tread a label's change as a value change... I have no idea why this happens and why only DropdownField. Luckily this change event will give a newValue=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?

from naughtyattributes.

JellySnek avatar JellySnek commented on June 2, 2024

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.

from naughtyattributes.

TylerTemp avatar TylerTemp commented on June 2, 2024

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

from naughtyattributes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.