- Home /
EditorApplication.projectWindowItemOnGUI and sub assets
I want to provide a custom icon for a classes which extends from ScriptableObject. The class has sub assets of Texture2Ds which you can see here.
The icon needs to be generated dynamically, so I'm using EditorApplication.projectWindowItemOnGUI
which works nicely. However this then causes a problem with the sub assets:
The method is applied not only to the main asset, but also all sub assets. Normally I'd use IsMainAsset / IsSubAsset, but because the method only exposes a Guid, all I can do is GUIDToAssetPath
, and the method invokes for all of the sub assets leaving me no means of telling them apart:
[DidReloadScripts]
static AssetDatabaseIcons()
{
EditorApplication.projectWindowItemOnGUI = AssetDatabaseIcons.ProjectWindowItemOnGUI;
}
// This method is invoked once for the main asset and n times for the sub assets
// The same guid is passed over on all of the calls
private static void ProjectWindowItemOnGUI(string guid, Rect rect)
{
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
ScriptableObject scriptableObject = AssetDatabase.LoadAssetAtPath<ScriptableObject>(assetPath);
//AssetDatabaseIcons.DrawScriptableObjectIcon(rect, scriptableObject);
}
Is there any way of solving this problem? I can't see any way but I'm hoping there might be a method I can use via reflection. I note that this method does not prevent the default icon from being drawn, so can I hook into that somehow?
Your answer
![](https://koobas.hobune.stream/wayback/20220612084826im_/https://answers.unity.com/themes/thub/images/avi.jpg)