Documentation for the Unity C# Library
Loading...
Searching...
No Matches
PixoIOSPlatformUtilities.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.Diagnostics;
3using System.IO;
4using UnityEngine;
5using UDebug = UnityEngine.Debug;
6
7namespace PixoVR.Apex
8{
10 {
11 public PixoIOSPlatformUtilities() : base()
12 {
13 UDebug.Log($"Initializing class {GetType().Name}");
14 }
15
16 public override bool OpenURL(string url)
17 {
18 UDebug.Log($"{GetType().Name}::OpenURL");
19 if (string.IsNullOrEmpty(url))
20 {
21 UDebug.Log("Url is empty or null.");
22 return false;
23 }
24
25 Application.OpenURL(url);
26 return true;
27 }
28
29 public override bool OpenApplication(string applicationPath, string[] argumentKeys, string[] argumentValues)
30 {
31 UDebug.Log($"{GetType().Name}::OpenApplication");
32 if (!string.IsNullOrEmpty(applicationPath))
33 {
34 UDebug.Log("Application is empty.");
35 return false;
36 }
37
38 if (!File.Exists(applicationPath))
39 {
40 UDebug.Log($"Application does not exist at {applicationPath}");
41 return false;
42 }
43
44 int argumentCount = Mathf.Max(argumentKeys.Length, argumentValues.Length);
45 if(argumentKeys.Length != argumentValues.Length)
46 {
47 UDebug.LogWarning("The number of argument keys and values are not equal. Extra arguments will not be provided and mapping could be messed up.");
48 }
49
50 string arguments = "";
51 for(int argumentIndex = 0; argumentIndex < argumentCount; argumentIndex++)
52 {
53 if(argumentIndex > 0)
54 arguments += " ";
55
56 // We use space here between the key and value as most OS's that are launched with arguments separate by spaces.
57 // We also escape our values to ensure that strings containing spaces get captured.
58 arguments += $"-{argumentKeys[argumentIndex]} \"{argumentValues[argumentIndex]}\"";
59 }
60
61 using (Process process = new Process())
62 {
63 process.StartInfo.WorkingDirectory = applicationPath;
64 process.StartInfo.Arguments = arguments;
65 process.StartInfo.FileName = applicationPath;
66 process.Start();
67 }
68
69 return true;
70 }
71
72 public override Dictionary<string, string> ParseApplicationArguments()
73 {
74#if UNITY_EDITOR
75 // We don't want to parse any parameters in the editor as it has its own list of arguments.
76 return new Dictionary<string, string>();
77#else
78 string[] args = System.Environment.GetCommandLineArgs();
79
80 UDebug.Log($"First argument: {args[0]}");
81
82 if(!string.IsNullOrEmpty(Application.absoluteURL))
83 {
84 string urlData = Application.absoluteURL;
85 UDebug.Log($"[PixoIOSPlatformUtilities] Parse from URL {urlData}");
86 return ParseURLArguments(urlData);
87 }
88
89 UDebug.Log("[PixoIOSPlatformUtilities] Parsing arguments from commandline.");
90
91
92 Dictionary<string, string> parameters = new Dictionary<string, string>();
93
94 // We skip the first argument, as it's the executables name.
95 for(int argumentIndex = 1; argumentIndex < args.Length; argumentIndex++)
96 {
97 if (args[argumentIndex].StartsWith('-') && ((argumentIndex + 1) < args.Length))
98 {
99 parameters.Add(args[argumentIndex].Remove(0), args[argumentIndex + 1]);
100 argumentIndex++;
101 }
102 }
103
104 return parameters;
105#endif
106 }
107 }
108}
UnityEngine.Debug UDebug
virtual Dictionary< string, string > ParseURLArguments(string url)
override Dictionary< string, string > ParseApplicationArguments()
override bool OpenApplication(string applicationPath, string[] argumentKeys, string[] argumentValues)