Drag and drop files onto string variables in inspector to get the file name?

I have a script that has a string to set a text file name of a file that that the script processes. The text file is in my Resources folder, and I use Resources.Load<TextAsset> to load the file.

What I’d like to be able to do is drag the text file from my project window onto the string field in the inspector, and that sets the string with the file name of the text file I dragged. Is there some way to extend the Unity Editor to do this? I’m not familiar with Editor extending, but I’d like to learn.

You can extend the inspector, but you’d basically have to re-do everything built in for that class to do so.

However, there is a better way. Why not just make it a TextAsset reference instead of a String variable? Then you can totally drag-and-drop, and you won’t need the Resources call to reference the asset.

I’ve managed to find a solution for this courtesy of Bunny83. Really simple to add his code in and repurpose it for whatever you need.

https://github.com/Bunny83/UnityWindowsFileDrag-Drop