Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Feedback [Feature] Show dirty state of assets in project browser

Discussion in '2020.2 Beta' started by CDF, Jun 13, 2020.

  1. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    There's a current issue in the new Localization package I've been trying out which raised the need for this feature. Assets are not being made dirty when they should be. It can be tedious to find out if an asset is dirty because you need to inspect the file in a text editor to see if anything has been changed.

    I'd love to see a new feature in the Editor that shows the dirty state of assets like the inspector does with prefab instance overrides; a light blue line at the edge of the window.

    dirty.gif
    Here's a simple script script that shows this state. It's ugly, probably very inefficient, but it does help isolate some of these "data not saved" issues

    Code (CSharp):
    1. public static class SetDirtyMenu {
    2.  
    3.     private static readonly Color dirtyObjectColor = new Color(1f / 255f, 153f / 255f, 235f / 255f, 0.75f);
    4.  
    5.     #region Private Methods
    6.  
    7.     [InitializeOnLoadMethod]
    8.     private static void Initialize() {
    9.  
    10.         EditorApplication.projectWindowItemOnGUI -= OnProjectWindowGUI;
    11.         EditorApplication.projectWindowItemOnGUI += OnProjectWindowGUI;
    12.     }
    13.  
    14.     [MenuItem("Assets/Set Dirty")]
    15.     private static void SetObjectsDirty() {
    16.  
    17.         var objects = GetObjects();
    18.  
    19.         foreach (var obj in objects) {
    20.  
    21.             EditorUtility.SetDirty(obj);
    22.         }
    23.     }
    24.  
    25.     [MenuItem("Assets/Set Dirty", true)]
    26.     private static bool ValidateSetObjectsDirty() {
    27.  
    28.         return GetObjects().Length > 0;
    29.     }
    30.  
    31.     private static Object[] GetObjects() {
    32.  
    33.         return Selection.objects.Where(t => EditorUtility.IsPersistent(t)).ToArray();
    34.     }
    35.  
    36.     private static void OnProjectWindowGUI(string guid, Rect selectionRect) {
    37.  
    38.         if (Event.current.type != EventType.Repaint) {
    39.  
    40.             return;
    41.         }
    42.  
    43.         string path = AssetDatabase.GUIDToAssetPath(guid);
    44.  
    45.         if (AssetDatabase.IsMainAssetAtPathLoaded(path)) {
    46.  
    47.             var obj = AssetDatabase.LoadMainAssetAtPath(path);
    48.  
    49.             if (EditorUtility.IsDirty(obj)) {
    50.  
    51.                 selectionRect.x = 0;
    52.                 selectionRect.width = 2;
    53.  
    54.                 EditorGUI.DrawRect(selectionRect, dirtyObjectColor);
    55.             }
    56.         }
    57.     }
    58.  
    59.     #endregion
    60. }
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,619
    That's a great idea! Dirty assets cause a lot of trouble for us, when people forget to "Save Project" before committing assets to git.

    The blue line looks nice, but it has a different meaning in the inspector (override). I think I'd prefer a * symbol at the end of asset name instead. The * would be consistent with how Unity communicates a dirty scene already. Other applications also use a * to indicate dirty documents too, so it's well established.

    The dirty state should propagate the folder hierarchy upwards. So you'd see "Assets*" if anything inside assets is dirty. In your example, it would display a line next to the "Tables" and "Assets" folders.

    If it does not propagate upwards, it wouldn't be that useful, because you can't see whether an asset is dirty, unless you open the folder where that asset is located.

    upload_2020-6-13_18-10-8.png
     
    Last edited: Jun 16, 2020
  3. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,136
    Thanks for the suggestion! I'll pass it on to the team.
     
  4. drallcom3

    drallcom3

    Joined:
    Feb 12, 2017
    Posts:
    165
    Uhh, I would like this a lot.
     
    Prodigga and Peter77 like this.
  5. jniac

    jniac

    Joined:
    Nov 16, 2017
    Posts:
    3
    me too