Search Unity

Feedback Addressables checkbox in inspector is not showing its true value

Discussion in 'Addressables' started by Skjalg, Jan 28, 2021.

  1. Skjalg

    Skjalg

    Joined:
    May 25, 2009
    Posts:
    211
    Hi

    I have a small quality of life feature request. I would like that the addressable checkbox in the inspector to show if an item is addressable or not. Currently it only displays if it is addressable if the item itself is, but not if a parent folder is.
    The asset itself:
    upload_2021-1-28_17-19-43.png
    The parent folder:
    upload_2021-1-28_17-20-3.png

    This makes it harder to know what items are actually addressables and which arent. (I just had a new guy on the team not understand why things worked because the assets didnt appear to be addressables).

    I propose that the addressables checbox is greyed out (and showing its path) if it is addressabled (is that a word) through its parent folder.
     
    Kazko likes this.
  2. Kazko

    Kazko

    Joined:
    Apr 2, 2014
    Posts:
    82
    Agreed. However it should also indicate whether it's the asset or the folder that is marked.

    Also a huge quality of life would be if the assets/folders in Project window were somehow visually distinguished from others. I find myself clicking on each asset to check if they are marked way too often. Perhaps a small dot next to a name, or just a font change ... italics or underline?

    There are so many much needed and easy-to-identify QoL improvements. It feels as if the dev team is not using their own tool in any production environment. Addressables is a great concept and I wish nothing more than the devs taking a step back from the advanced features and polish the experience of the basics. Currently it's very confusing, unintuitive and hard to navigate.
     
    Skjalg likes this.
  3. rhys_vdw

    rhys_vdw

    Joined:
    Mar 9, 2012
    Posts:
    110
    It would have to be disabled too, as we currently have no control over the naming of assets addressed by folder (which I have no issue with).
     
  4. Skjalg

    Skjalg

    Joined:
    May 25, 2009
    Posts:
    211
    upload_2021-1-29_17-59-10.png

    This is how I solved it for now. the A means its addressable

    Code (CSharp):
    1. using System.Collections.Generic;
    2. using System.IO;
    3. using UnityEditor;
    4. using UnityEditor.AddressableAssets;
    5. using UnityEditor.AddressableAssets.Settings;
    6. using UnityEngine;
    7. using Object = UnityEngine.Object;
    8.  
    9. public static class ProjectWindowOverride
    10. {
    11.     private static HashSet<string> paths;
    12.     private static GUIStyle lineStyle;
    13.     [InitializeOnLoadMethod]
    14.     private static void Init()
    15.     {
    16.         EditorApplication.projectWindowItemOnGUI += OnHierarchyItemOnGUI;
    17.     }
    18.  
    19.     private static void OnHierarchyItemOnGUI(string guid, Rect rect)
    20.     {
    21.         if (Application.isPlaying || Event.current.type != EventType.Repaint || !IsMainListAsset(rect))
    22.         {
    23.             return;
    24.         }
    25.         string assetPath = AssetDatabase.GUIDToAssetPath(guid);
    26.         if (AssetDatabase.IsValidFolder(assetPath))
    27.         {
    28.             return;
    29.         }
    30.         var asset = AssetDatabase.LoadAssetAtPath<Object>(assetPath);
    31.         if (asset == null)
    32.         {
    33.             // this entry could be Favourites or Packages. Ignore it.
    34.             return;
    35.         }
    36.  
    37.         if (lineStyle == null)
    38.         {
    39.             lineStyle = (GUIStyle) "TV Line";
    40.         }
    41.        
    42.         var textDimensions = lineStyle.CalcSize(new GUIContent(asset.name));
    43.         const float kIndentWidth = 14f;
    44.         const float kIconWidth = 16f;
    45.         const float kSpaceBetweenIconAndText = 2f;
    46.         const float indent = kIndentWidth + kIconWidth + kSpaceBetweenIconAndText;
    47.        
    48.         if (DrawSizeLabel(rect, indent, textDimensions, assetPath)) return;
    49.  
    50.         DrawAddressableA(rect, indent, textDimensions, assetPath);
    51.     }
    52.  
    53.     private static bool DrawSizeLabel(Rect rect, float indent, Vector2 textDimensions, string assetPath)
    54.     {
    55.         float leftOverWidth = rect.width - (indent + textDimensions.x + 60);
    56.         if (leftOverWidth <= 0)
    57.         {
    58.             //Dont draw if theres no room
    59.             return true;
    60.         }
    61.  
    62.         var sizeLabel = new Rect(rect);
    63.         sizeLabel.x += rect.width - 60;
    64.         sizeLabel.width = 60;
    65.         GUI.Label(sizeLabel, GetFormattedFileSize(assetPath));
    66.         return false;
    67.     }
    68.  
    69.     private static bool DrawAddressableA(Rect rect, float indent, Vector2 textDimensions, string assetPath)
    70.     {
    71.         float leftOverWidth = rect.width - (indent + textDimensions.x + 100);
    72.         if (leftOverWidth <= 0)
    73.         {
    74.             //Dont draw if theres no room
    75.             return true;
    76.         }
    77.  
    78.         if (paths == null)
    79.         {
    80.             ExtractAddressablePaths(AddressableAssetSettingsDefaultObject.Settings, out paths);
    81.         }
    82.  
    83.  
    84.         if (paths != null && paths.Contains(assetPath))
    85.         {
    86.             var addressableLabel = new Rect(rect);
    87.             addressableLabel.x += rect.width - 100;
    88.             addressableLabel.width = 12;
    89.             GUI.Label(addressableLabel, "A");
    90.         }
    91.  
    92.         return false;
    93.     }
    94.  
    95.     static void ExtractAddressablePaths(AddressableAssetSettings settings, out HashSet<string> paths)
    96.     {
    97.         paths = new HashSet<string>();
    98.         foreach (AddressableAssetGroup group in settings.groups)
    99.         {
    100.             if (group == null)
    101.                 continue;
    102.             foreach (AddressableAssetEntry entry in group.entries)
    103.             {
    104.                 string convertedPath = entry.AssetPath;
    105.                 if (AssetDatabase.IsValidFolder(convertedPath))
    106.                 {
    107.                     ExtractPathsFromFolder(convertedPath, paths);
    108.                 }
    109.                 else
    110.                 {
    111.                     paths.Add(convertedPath);
    112.                 }
    113.             }
    114.         }
    115.     }
    116.  
    117.     private static void ExtractPathsFromFolder(string path, HashSet<string> hashSet)
    118.     {
    119.         foreach (string filename in Directory.EnumerateFileSystemEntries(path, "*.*", SearchOption.AllDirectories))
    120.         {
    121.             string convertedPath = filename.Replace('\\', '/');
    122.             hashSet.Add(convertedPath);
    123.         }
    124.     }
    125.  
    126.     public static string GetFormattedFileSize(string assetPath)
    127.     {
    128.         return EditorUtility.FormatBytes(GetFileSize(assetPath));
    129.     }
    130.  
    131.     private static long GetFileSize(string assetPath)
    132.     {
    133.         string fullAssetPath = string.Concat(Application.dataPath.Substring(0, Application.dataPath.Length - 7), "/", assetPath);
    134.         long size = new FileInfo(fullAssetPath).Length;
    135.         return size;
    136.     }
    137.  
    138.     private static bool IsMainListAsset(Rect rect)
    139.     {
    140.         // Don't draw details if project view shows large preview icons:
    141.         if (rect.height > 20)
    142.         {
    143.             return false;
    144.         }
    145.         // Don't draw details if this asset is a sub asset:
    146.         if (rect.x > 16)
    147.         {
    148.             return false;
    149.         }
    150.         return true;
    151.     }
    152. }
     
    Kazko likes this.
  5. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,820
    I'll pass this request to the team on your behalf!
     
    Skjalg likes this.
  6. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,820
    Wanted to pass a long that the team love the idea, and are going to look into it!
     
    Skjalg likes this.