plyoung / Favourites

Unity Favourites Panel
The Unlicense
83 stars 15 forks source link

Doesn't work in Unity 2022.2.8 #4

Open seannowotny opened 1 year ago

seannowotny commented 1 year ago

In FavouritesTreeView.cs this line results in an exception.

PropertyInfo prop = asm.GetType("UnityEditorInternal.EditorResourcesUtility").GetProperty("folderIconName", (BindingFlags.Static | BindingFlags.Public));

NullReferenceException: Object reference not set to an instance of an object FavouritesEd.FavouritesTreeView.FolderIconName () (at Assets/Favourites/Editor/FavouritesTreeView.cs:296) FavouritesEd.FavouritesTreeView.LoadAndUpdate (FavouritesEd.FavouritesAsset favsAsset) (at Assets/Favourites/Editor/FavouritesTreeView.cs:52) FavouritesEd.FavouritesEdWindow.UpdateTreeview () (at Assets/Favourites/Editor/FavouritesEdWindow.cs:59) FavouritesEd.FavouritesEdWindow.AddCategory (FavouritesEd.TextInputWindow wiz) (at Assets/Favourites/Editor/FavouritesEdWindow.cs:103) FavouritesEd.TextInputWindow.Update () (at Assets/Favourites/Editor/TextInputWindow.cs:35) UnityEditor.HostView.SendUpdate () (at <3d77f9e52a364b2f825fba70966192a5>:0) UnityEditor.EditorApplication.Internal_CallUpdateFunctions () (at <3d77f9e52a364b2f825fba70966192a5>:0)

luty4ng commented 9 months ago

Try this

private static string FolderIconName()
{
#if UNITY_2018_3_OR_NEWER
    return UnityEditor.Experimental.EditorResources.iconsPath;
#else
    if (Invoke_folderIconName == null)
    {
        Assembly asm = Assembly.GetAssembly(typeof(Editor));
        PropertyInfo prop = asm.GetType("UnityEditorInternal.EditorResourcesUtility").GetProperty("folderIconName", (BindingFlags.Static | BindingFlags.Public));
        MethodInfo method = prop.GetGetMethod(true);
        Invoke_folderIconName = (System.Func<string>)System.Delegate.CreateDelegate(typeof(System.Func<string>), method);
    }
    return Invoke_folderIconName();
#endif
}