gkngkc / UnityStandaloneFileBrowser

A native file browser for unity standalone platforms
MIT License
2.01k stars 317 forks source link

Problem in full screen #102

Open emmanuelproulx opened 3 years ago

emmanuelproulx commented 3 years ago

When I use the Standalone File Browser (current version) in my game in full screen mode, it hides the game (which is ok) and opens the dialog. After I choose my file and click OK, the dialog disappears and nothing happens. I have to switch back to the game myself. And then the game doesn't show the file. It behaves as if I clicked Cancel.

I'm using Windows 10, 64 bit. I tried with Mono and IL2CPP, and .NET v2 and v4. They all behave the same.

It works perfectly when I run from inside Unity.

The-MAZZTer commented 3 years ago

I was actually wondering about this, since I thought it could be a problem.

You can use this Unity API to switch to windowed mode to show the dialog, and switch back after the file is selected:

https://docs.unity3d.com/ScriptReference/Screen-fullScreen.html

Otherwise you could forcibly focus the Unity game window after the file is selected, but there's no built-in API for it. You'd have to use P/Invoke, which gets messy real fast if you want to be cross-platform.

Matsyir commented 9 months ago

You can use this Unity API to switch to windowed mode to show the dialog, and switch back after the file is selected:

https://docs.unity3d.com/ScriptReference/Screen-fullScreen.html

Edit: I'm getting some issues with my fix actually, don't directly copy it. But it lays out the basic idea for a quick/temporary fix until the issue could actually be fixed.

I've made a PR with this simple workaround, #133 - if you're on exclusive fullscreen and you call any of the SFB functions, it will switch to windowed fullscreen, and back to exclusive after the file browser is closed. It's all in 1 file so you can just replace the StandaloneFileBrowser.cs with the one in that PR. Note that my workaround only works under the assumption you're using 1 file browser at a time.