Associating File Types with a Unity App
Simple enough question, is it possible to associate a file type with a Unity app so that file type will open with said app, then have the app decide what to do with the file via a script?
Just checking -- telling a file to open using a particular Unity-created exe is trivial, right? Your real question is how the OS communicates the filename to the application, and how Unity-code can retrieve that?
Yes, how Unity can retrieve and decide what to do with the filename sent by the OS.
I imagine http://answers.unity3d.com/questions/36066/pass-arguments-to-a-unity-exe.html is a start. I'm not sure if a clicked filename is packaged this way, but it's got to be something like that.
Hmm, but would this work on other platforms? I'm planning on making the app available to all of the PC platforms supported by Unity.
$$anonymous$$aking the API work consistantly on various machines is Unity's problem. They already translate C3/dot-NET into whatever iOS and Linux use. Hopefully, probably, they also have getting external arguments handled in a consistent way, through one command. Or not, like the way you have to handle wrong-way slashes in windows pathnames.
Well, I know people who could these things on different operating systems, so I'll try to have this tested as soon as I can. Thanks for your support! =)
Answer by febozzo · May 23, 2019 at 10:35 PM
Hi, this is what I'm trying to do with my Unity app. I have a json file, with my own extension, containing some scene configuration. I want to double click on it, so my app starts the file content can be deserialized and my game objects configured on the fly. I associated the file extension with my Unity built app by double clicking on it and then choosing "open with". To check if it works I set this in the Start:
void Start() { var arguments = Environment.GetCommandLineArgs(); outputText.text = $"GetCommandLineArgs: {String.Join(", ", arguments)}"; }
But seems that no argument is passed. So I don't know how to access the file. Does anyone has some tips? Thank you
Your answer
Follow this Question
Related Questions
How to display .tif images via script? 1 Answer
What am i doing wrong here? (file.exists) 2 Answers
move file inside streamingAssets during build 0 Answers
Syntax 501 error, How to upload without error to FTP Server 1 Answer
How do I add all images from a folder like "C:\Users\User\Desktop" to a sprite array?? 0 Answers