How to limit an ObjectField to assets with specific file extension

I am building a custom editor/inspector for a custom asset type.
Currently my editor has an EditorGUILayout.ObjectField onto which I can drag and drop any object from my assets in order to associate that asset with my script pretty much in the same way you can drag an drop a .wav file onto an audiosource component.
I would like the same behavior but only for my specific assets files (which are binary files with a custom filename extension “.myext”). So I would like my object field to only accept “.myfile” dropped in. How to properly achieve that?

So far my code looks like this:

[CustomEditor( typeof (MyClass)) ]
public class MyClassEditor : Editor {

	
	System.Type myType = typeof(Object); //this will accept objects of *any* types. I would like to limit to objects whose file extensions is ".myext"
	MyClass mc;



	public override void OnInspectorGUI()
	{
		newFileObj = (Object)EditorGUILayout.ObjectField ("file", newFileObj, myType, false);
    

		if(GUI.changed)
		{      
              mc.Load(newFileObj);  //MyClass has a method to actually load the  file.
		}
	}

}

Object field can only filter by type, not by extension. If you want to filter by extension, you’ll need to do your own file finding, probably using the .NET Directory and File APIs.

It’s just an idea, but you can maybe get the filepath using AssetDatabase.FindAssets and confirm that it’s extension matches the one you want - then displaying a dialog telling the user that the file they selected wasn’t a csv and cancelling out of it.

It’s sort of hacky, but it might work.