EditorUtility.OpenFilePanel() Multiple Extensions

How do I implement multiple extensions for selection?

I’m looking at selecting JPEG images, which have the annoying habit of an interchangeable extension (.jpg and .jpeg).

I’ve been trying to get this to work since Unity 3.5 (We’re now on Unity 4.3), and I’ve yet to find any solution or a response from a Unity team member.

I’ve tried a long list of everything anyone has said to work.

".jpg;*.jpeg;"
'".jpg;*.jpeg;"'
".jpg;jpeg"
"jpg;jpeg"
"jpg|jpeg"
".jpg|.jpeg"
'".jpg|.jpeg"'
".jpg|*.jpeg"
'".jpg|*.jpeg"'
"jpg jpeg"
"jpg/jpeg"
"jpg:jpeg"
"*.jpg;*.jpeg;"
"*jpg;*jpeg"
"jpg,jpeg"
"\"jpg\",\"jpeg\""

It really shouldn’t be this hard to get this to work, it’s a common functionality expected in all file selection windows.

Here’s some other threads from years ago that show people having the same problem:

For the last few years developing our Unity plugin, I’ve set this problem down and come back to it hoping there’d be a solution in the future. At this point it’s just frustrating; it’s not that big of a deal to ignore in our plugin, but we still get customer complaints that they can’t select .jpeg images. Simply because Unity has failed to document how to handle multiple extensions, and their staff that look at these forums always seem to skip this question.

I really do appreciate any and all help in this matter, thank you for your future help in solving this obnoxious problem.

Has anyone had any success with this? I've taken a peek at some things and it seems Unity supports a multiple extension file browser for importing new assets, but it isn't exposed to developers. I believe it's RunOpenPanel() vs RunComplexOpenPanel() on the C++ side. Can I get a response from someone at Unity about this?

Maybe you can give some [feedback][1] or add an [issue][2] asking to expose the API for that. [1]: http://feedback.unity3d.com/ [2]: http://issuetracker.unity3d.com/

4 Answers

4

Simply using a comma worked on Windows.

“fbx,prefab” resulted in both *.fbx and *.prefab files being shown.

Here is a simple workaround try passing this: "Jpeg Interchange;*.jpg;*.jpeg" to the OpenFilePanel extension parameter.

It works because the first parameter being passed to the OS seems to not be passed correctly. Further parameters are passed correctly. It is ugly but it works.

In Unity 5.5 and later, they added a new method that accepts an array of file extensions:

EditorUtility.OpenFilePanelWithFilters(string title, string directory, string[] filters);

void Start()
{
extensions = new List();
ExtensionFilter extensions2 = new ExtensionFilter(“*”,extensionsString);
extensions.Add(extensions2);
}

 private void OnClick()
    {
        string[] paths = StandaloneFileBrowser.OpenFilePanel("Title","", extensions.ToArray(), false);
        
        if (paths.Length > 0)
        {
            output.text = paths[0] + "";
           // StartCoroutine(OutputRoutine(new System.Uri(paths[0]).AbsoluteUri));
        }
    }