Adding the "open with ..." function to my game

When you right-click on a file, you can choose the option "open with ..." any program / executable file that launches this program and automatically opens the file inside this program. I think everyone knows that.

Now I create the game in unity (the scripts are in C #), and I want my finished build to support this functionality, so that my user / player can right-click on, say, savegame, select open with and then select executable game file. Then the game should start and load the saved game.

How to implement this functionality? What happens under the hood when this option is used from the file system, and how do I handle it inside my game?

I do not ask how to actually download the game (this is the same for every game), I just need to know how I will “catch” the case when the user opens the file with my game.exe.

+4
source share
1 answer

If you want to add your program to the "Open With" context menu (What you need to do in the installer, add the registry key, pointing to your application, as described here If you do not have an installer (I think Unity 5 can build you), you can just do it in the game by calling

Microsoft.Win32.Registry.SetValue(key, valueName, value, Microsoft.Win32.RegistryValueKind.String);

with a script inside your scene. Or you can write an installer in C # that does this.)

, , , , . script , 1-, , System.Environment.GetCommandLineArgs(). - , :

string filepath;
string arguments = System.Environment.GetCommandLineArgs();
if (arguments.Length >= 2)
{
    filepath = arguments[1];
    DoYourThing(filepath);
}
return;

, , 2- , , .

+5

All Articles