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.
}
}
}