handzlikchris / Unity.MissingUnityEvents

Editor extension to generate events that are executed before property set, eg. Transform-position, Transform-rotation, Transform-parent which allows to write more event driven code or debug property changes that are not simple to track down. Easily customisable to allow adding events to different property setters / types.
MIT License
186 stars 16 forks source link

Cannot remove list entries in the "Missing Unity Events" panel. #11

Closed VladimirMarko closed 2 years ago

VladimirMarko commented 2 years ago

In this package's UI, in the "Missing Unity Events" panel, there's an editable list of types and their properties. There is a button labeled "Add New Event" that adds a new entry to this list. There is no way to remove entries from this list - it can only grow. The entries persist over Unity restarts.

cannot remove empty list entries

In other words, I cannot get rid of the empty entries marked by the exclamation mark, only add more.

EDIT: I figured out that you can reset everything via Tools -> Missing Unity Events -> Recreate Config. That's however not ideal, of course.

handzlikchris commented 2 years ago

Hi @VladimirMarko - thanks, glad you've found a workaround.

There shou'd be a '-' in that table.

If not you can have a look with debugger what's happening, the code that draws it is in MissingUnityEventsManagerEditorWindow :172

 if (GUILayout.Button("-", PercentageWidth(8)))
{
    _config.EventConfigurationEntries.RemoveAt(i);
}
VladimirMarko commented 2 years ago

OK, I've been playing with this and I found out that consistently PercentageWidth(66) instead of PercentageWidth(100) means the whole window width for both GUILayout and EditorGUILayout static methods/UI elements.

I had no idea why. Then I checked DPI scaling and sure enough, it was 150%. So that's the problem. The way you use width is not robust with respect to DPI scaling (at least on Windows 10).

VladimirMarko commented 2 years ago

DPI scaling = 100%:

dpi scaling 100%

DPI scaling = 150%:

dpi scaling 150%

DPI scaling = 175%:

dpi scaling 175%

VladimirMarko commented 2 years ago

Hm... I cannot figure out a clean solution to this.

The crux of the matter is that GUILayout.Button("A window-wide button", GUILayout.Width(Screen.width)); produces a button that will be wider than its window, if DPI scaling is above 100%.

We have Screen.dpi, but that's the absolute value and not a scaling factor. The base value is system-dependent (e.g., normally 96 PPI on Windows) and the Unity API does not seem to allow us to get it for the current system.

Some external packages might help, but as I understand it, Unity does not play well with the NuGet package manager, so adding them as dependencies would be non-kosher, I suspect. I am not sure about this point.

In any case, I filed a bug report with Unity, as I assume that this discrepancy in behavior between GUILayout.Width and Screen.width is unintended.

As a workaround, I would suggest defining the UI elements using just absolute pixel values. I don't know whether there is a better way.

VladimirMarko commented 2 years ago

Nevermind. I figured it out.

Apparently the correct thing to use is position.width (inherited from EditorWindow), instead of Screen.width.

I will submit a pull request.

handzlikchris commented 2 years ago

Thanks @VladimirMarko that's some good investigation and fix