I have a custom file “MyFile.myExt” in the project and would like to write a custom editor for this special file. Unity imports the file as a DefaultAsset, so I’ve tried to override the existing editor for DefaultAsset. I believe this should work or at least has worked in the past, so I wanted to confirm if this should be possible or does not work anymore:
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(DefaultAsset), editorForChildClasses: true, isFallback = false)]
public class MyCustomEditor : Editor
{
public override void OnInspectorGUI()
{
Debug.Log("This is never called.");
string path = AssetDatabase.GetAssetPath(target);
if (path.EndsWith(".myExt"))
{
EditorGUILayout.LabelField("My Custom File Type");
}
else
{
base.OnInspectorGUI();
}
}
}
MyCustomEditor is simply never created and no callbacks are received. If I change the type to e.g. Transform, I can replace all Transform component editors. However, it does not seem to work for assets in the project, e.g. SceneAsset also does not work. I still believe that I’ve done exactly that in previous Unity versions, but I’m not entirely sure.