Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hierarchy Icons added #26

Merged
merged 5 commits into from
Feb 24, 2024
Merged

Conversation

MateuszBudny
Copy link
Contributor

Description of the Change

Hierarchy Icons has been added! They show the same icons as in the Project View for prefabs.
image
I have refactored ProjectWindowInterace class by extracting GetStatusIconForAssetGUID(guid) method from it, so I can get an icon for an asset GUID easily, without copying code.

Alternate Designs

I was thinking about adding such icons next to a prefab name in prefab mode too, but that's maybe for the future, as it is easier now after my ProjectWindowInterace class refactor.
image

Benefits

It is much easier to see now, which prefabs are currently locked. It is not needed to look at Locks window or to look at Project View before modifying any prefab, so it is harder to make changes in locked files by mistake.

Possible Drawbacks

It is possible for the icons to be drawn on prefabs names. But you need to have a very long prefab's name or a very narrow Hierarchy window. For me, it is a small price to pay for less mistakes made by developers.
image

Applicable Issues

Before this change, checking if a prefab is locked was easy from scene/prefab view, but demanded additional action (finding the prefab in a Project View or opening a Locks window and comparing a list of locks with your prefab). Now, you see this info in Hierarchy window, which means you can see if the prefab is locked without additional actions, when you modify the prefab from Scene View.

@CapnRat CapnRat self-requested a review January 12, 2024 11:59
Copy link
Member

@shana shana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is cool, thank you so much for the PR! I just have a couple of code reviews and comments:

This should probably be an optional setting, because the hierarchy window is very sensitive to performance issues, and there are a lot of plugins that also add icons to the hierarchy, which could also cause visual problems. If you could add a setting to the settings tab to toggle this, that would be great!

Your PR has highlighted the fact that ProjectWindowInterface is acting both as a database and as a UI handler, which is not great. If you're looking to do more things, splitting the AssetPostProcessor data handling parts from the UI parts in that class would be awesome. This is not a requirement for this PR at all, it's just something I noticed needs doing :P

{
static HierarchyWindowInterface()
{
EditorApplication.hierarchyWindowItemOnGUI += OnHierarchyItemTryToDrawStatusIcon;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be subscribed at InitializeOnLoad time, because there is no guarantee that this callback will happen after all of the git bits have been initialized by ApplicationManagerBase. You probably haven't noticed any issues because you already have git set up in your project, so in most cases this callback happens at a safe time, but at times when git needs to be set up or there's an update happening, this callback will get called before the setup is done, and the ProjectWindowInterface.GetStatusIconForAssetGUID(guid) call below will likely throw an exception.

To make sure there's no race conditions at startup, this should be done in a Initialize method like https://github.com/spoiledcat/git-for-unity/blob/main/src/com.spoiledcat.git.ui/Editor/UI/ProjectWindowInterface.cs#L39, and the call to it should be added in https://github.com/spoiledcat/git-for-unity/blob/main/src/com.spoiledcat.git.ui/Editor/ApplicationManager.cs#L36C35-L36C35

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, your way is much better integrated with the tool ;) I have done as you asked, thanks!


// place the icon to the right of the list:
Rect r = new Rect(selectionRect);
r.x = r.width + 10;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The icons seem to be aligned with an inverse indentation to the list item indentation, instead of being all aligned to the right of the window regardless of the indentation of the list entry. That looks odd? This probably needs to be r.x = r.xMax - 10, so it's aligned to the right no matter how much indentation the entry has.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been using this tool for a while now in my own project and I kinda got used to that incidental indentation - it's easier to see which Hierarchy Icon belongs to which prefab object, when those Hierarchy Icons mimick the indentation of the prefab objects. But, I understand that it might not be for everyone, so I added an option to the SettingsView to turn on/off that indentation, I hope it is okay :)

@MateuszBudny
Copy link
Contributor Author

@shana
Hi, thanks for the CR! Very good insights :D With new commits that I just pushed, I have added an option to turn the Hierarchy Icons on or off and even added the X offset slider, so the user can adjust Hierarchy Icons positions as they please. Additionally, I have fixed one bug - I had previously used PrefabUtility.GetCorrespondingObjectFromSource() where I should use PrefabUtility.GetCorrespondingObjectFromOriginalSource() (this bug was causing all of prefabs child objects to have an Hierarchy Icon when that icon was only viable to the prefab object). More details about other changes in the replies to your comments corresponding to the given changes ;)

About refactoring ProjectWindowInterface I have one question. Because it looks like database/controller functions, which I should separate from ProjectWindowInterface, would belong nice to the ApplicationManager class, but that manager already has some other functions and responsibilities which are different from Git database/controller functions, so I don't think it is a good idea. Maybe the name ApplicationManager is too broad? Because it sounds like it does everything that relates to managing this tool, which is not a good approach and I would like to move database/controller functions from ProjectWindowInterface to the completely new class, but then there will be more managers than one and it might get messy. What do you think about it?

@shana
Copy link
Member

shana commented Feb 1, 2024

I looked at ProjectWindowInterface some more and ooof, ok, it's a lot. So all of the parts that update the list of files and guids and lock and status data, that whole logic, that's basically taking what RepositoryManager is generating (and caching), and matching it with Unity data. It's basically a cross-reference from generic git data to specific Unity data. This is conceptually close to what UnityEnvironment does, which is a subclass/implementation of a generic Environment, tied to specific Unity data. So, this sounds like it would be a UnityGitView singleton of some sort. UnityGitStatus? UnityFileView? Something like that. Names are hard.

You can tell it's a singleton because haha everything in there is static. 🫣

It's an AssetPostProcessor subclass, but we're not implementing any callbacks for that? That's probably a sign it doesn't need to be an AssetPostProcessor. The likely reason we're not hooking up any AssetPostProcessor events? That's because it only fires for files Unity cares about, not actually for all filesystem changes in the whole repository, and we have a native filesystemwatcher that watches and raises events for everything, so AssetPostProcessor is redundant. If we did want to hook up to asset post processing, I would do it in a handler class that just fires off "hey files might have changed" events, and that would be something that RepositoryManager would listen for, because RepositoryManager is responsible for listening to filesystem changes events and updating git data accordingly (but we already have all the filesystem data we need, so we don't need to do this)

I haven't had time yet to look at your updated changes, but I'll get to it as soon as I can, hopefully this evening. Thank you again for taking the time to do this, I can't express enough how much I appreciate it! ❤️

@shana shana merged commit 8730d1d into spoiledcat:main Feb 24, 2024
1 check passed
@shana
Copy link
Member

shana commented Feb 24, 2024

@MateuszBudny This is now merged and included in the v1.0.27 release (available from https://registry.spoiledcat.com/ or from the packages/* branches). I did some cleanups and additional changes and fixes, so you might have to set your preferred settings again, as the some of the settings keys have changed. Thank you so much again for the contribution!

@MateuszBudny
Copy link
Contributor Author

@MateuszBudny This is now merged and included in the v1.0.27 release (available from https://registry.spoiledcat.com/ or from the packages/* branches). I did some cleanups and additional changes and cleanups, so you might have to set your preferred settings again, as the some of the settings keys have changed. Thank you so much again for the contribution!

@shana
You're welcome, I'm happy to help :D Thanks for the great tips on this PR :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants