Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Call native file manager from Unity Application C#

Discussion in 'Scripting' started by dkova, May 1, 2014.

  1. dkova

    dkova

    Joined:
    Mar 22, 2014
    Posts:
    4
    Good day all. I am writing a project in Unity on C#. I need that user can choose a file from computer and this file will upload to server. How to call a native file browser? (for example, Windows Explorer) and then upload selected file to server? Ihave searched a solution but...

    P.S. Sorry for bad English
     
  2. Fyko-chan

    Fyko-chan

    Joined:
    Sep 29, 2012
    Posts:
    76
  3. shaderop

    shaderop

    Joined:
    Nov 24, 2010
    Posts:
    942
    It can't be done directly form Unity (at least not as far as I know), so you'll need to call the appropriate native operating system implementation using PInvoke, which will be different for each platform. You can probably get this to work on Windows by using PInvoke to call GetOpenFileName, but I don't know the equivalent for that on other OSs, if any.

    It's not bad at all so far :)
     
  4. dkova

    dkova

    Joined:
    Mar 22, 2014
    Posts:
    4
    But it is in C++ and how I can connect it to my project?
     
  5. shaderop

    shaderop

    Joined:
    Nov 24, 2010
    Posts:
    942
  6. dkova

    dkova

    Joined:
    Mar 22, 2014
    Posts:
    4
    Thanks. Are you not sure that it will work on all platforms? I have a multi-platform project.
     
  7. shaderop

    shaderop

    Joined:
    Nov 24, 2010
    Posts:
    942
    It will only work on Windows because it's using Windows specific features. You'll have to find the equivalent in OS X and any flavor of Linus you might be targeting.
     
  8. dkova

    dkova

    Joined:
    Mar 22, 2014
    Posts:
    4
    Please explain this - i'm so noob :)
     
  9. shaderop

    shaderop

    Joined:
    Nov 24, 2010
    Posts:
    942
    That links included in my first and second posts have all the explanation and examples you'll need. All you need is to do some reading and to apply a tiny bit of effort.

    Good luck.
     
    Last edited: May 3, 2014
  10. PygmyMonkey

    PygmyMonkey

    Joined:
    Jan 13, 2014
    Posts:
    306
    Hello,

    I made a Asset to use the Native File Browser from Windows and Mac in Unity at runtime, it's available on the Asset Store: https://www.assetstore.unity3d.com/en/#!/content/68064

    I've been searching for a way to do that for more than a year... and finally found how to do it :)