last day (14 days later) » 

5:46 AM
-1
A: Unity Standalone Player Windows Desktop Platform- How to get path from file that is double click using Unity C#?

Ian H.Use System.Environment.GetCommandLineArgs(). When a file is opened with a specific application this returns (at index 0) the path of the file that is trying to be opened. In your code it could look something like this: void Start () { string[] args = System.Environment.GetCommandLineArgs(); ...

 
Thx! Since is a question for "Unity" users,can you add more information and expand the section about using System.Environment? I try to use System.Environment.CommandLineArgs but was not possible by default. Probably my question was negative because there are a lot of similar questions but not for Unity users. Or edit my Eng.
 
@SoaringCode Yeah I can try tomorrow. Can you just further specify what you mean by "not possible by default"? Does it work like this or does it cause an error?
 
Err: `System.Environment' is a type not a namespace. A using namespace directive can only be applied to namespaces. Looks like CommandLineArgs() do not exist. Can be GetCommandLineArgs() instead?
 
@SoaringCode You can try it, System.Environment.CommandLineArgs is what I found on a unity forum for the same question.
 
Was not possible to use System.Environment.CommandLine() and System.Environment.GetCommandLineArgs() do not returns the correct file path. The only way it works in Unity for Windows is to include system on top: using System; and then Environment.CommandLine; but without "()" or directly System.Environment.CommandLine;
And also cannot implicitly convert Environment.CommandLine type string' to args type string[]' array.
 
5:46 AM
@SoaringCode Thats because that is the unformatted command line as a string. Use string.Split(' ') to get the individual arguments.
 
Ok! and it returns at index 1 . Not at index 0
 
@SoaringCode Look I can't do everything for you. Environment.CommandLine returns the whole commandline, meaning also the name of the application. Further starting arguments are at the further indexes.
 
Ok thanks for the help. one more question. Can you pass me the link to the Unity forum where you find the awnser?
 
I found this: answers.unity3d.com/questions/138715/…, it seemed like a pretty good solution to me.
One more question, did you downvote my answer or why is it negative?
 
I push it negative before because it was returning the application path using GetCommandLineArgs() returns only the application. So I correct rolling back your answer taking out () but stackoverflow did not let me to takke out the negative. I did not want to add my solution (a new solution). Now i will put it in neutral as soon as possible, but the solution is not running in Unity. When it runs in Unity then positive and best. Thanks you so far for your time.
using System;
void Awake () {
string args = Environment.CommandLine;
 
6:30 AM
Alright, I edited it. Take a look at it, I would be glad if it helps you :)
 
7:05 AM
Did not work because some path can contain space. But now, if you take out Environment.CommandLine.Split(' '); and you add Environment.GetCommandLineArgs(); works perfect!
 

last day (14 days later) »