|
|
|
|
|
|
[MenuItem("Window/General/Pyrception/Run")] |
|
|
|
static void RunPyrception() |
|
|
|
{ |
|
|
|
string path = Application.dataPath.Replace("/Assets", ""); |
|
|
|
#if UNITY_EDITOR_WIN
|
|
|
|
path = path.Replace("/", "\\"); |
|
|
|
#endif
|
|
|
|
string command = ""; |
|
|
|
string path = Application.dataPath.Replace("/Assets","").Replace("/","\\"); |
|
|
|
string command = $"cd {path}\\DataInsightsEnv\\Scripts\\ && activate && pyrception-utils.exe preview --data=\"{PlayerPrefs.GetString(SimulationState.latestOutputDirectoryKey)}/..\""; |
|
|
|
|
|
|
|
ProcessStartInfo info = new ProcessStartInfo("cmd.exe", "/c " + command); |
|
|
|
info.CreateNoWindow = false; |
|
|
|
info.UseShellExecute = true; |
|
|
|
Process cmd = Process.Start(info); |
|
|
|
#if UNITY_EDITOR_WIN
|
|
|
|
command = $"cd {path}\\DataInsightsEnv\\Scripts\\ && activate && pyrception-utils.exe preview --data=\"{PlayerPrefs.GetString(SimulationState.latestOutputDirectoryKey)}/..\""; |
|
|
|
#elif UNITY_EDITOR_OSX
|
|
|
|
command = $"cd {path}/DataInsightsEnv/Scripts && activate && pyrception-utils preview --data=\"{PlayerPrefs.GetString(SimulationState.latestOutputDirectoryKey)}/..\""; |
|
|
|
#endif
|
|
|
|
int ExitCode = ExecuteCMD(command, false, true); |
|
|
|
if (ExitCode != 0) return; |
|
|
|
int steps = 4; |
|
|
|
int steps = 3; |
|
|
|
string path = Application.dataPath.Replace("/Assets", "").Replace("/", "\\"); |
|
|
|
string path = Application.dataPath.Replace("/Assets", ""); |
|
|
|
#if UNITY_EDITOR_WIN
|
|
|
|
path = path.Replace("/", "\\"); |
|
|
|
#endif
|
|
|
|
string pyrceptionPath = Path.GetFullPath("Packages/com.unity.perception/Editor/Pyrception/pyrception-utils"); |
|
|
|
|
|
|
|
EditorUtility.DisplayProgressBar("Setting up Pyrception", "Installing virtualenv...", 0 / steps); |
|
|
|
|
|
|
|
|
|
|
EditorUtility.DisplayProgressBar("Setting up Pyrception", "Setting up virtualenv instance...", 1f / steps); |
|
|
|
|
|
|
|
#if UNITY_EDITOR_WIN
|
|
|
|
#elif UNITY_EDITOR_OSX
|
|
|
|
ExitCode = ExecuteCMD($"virtualenv \"{path}/DataInsightsEnv""); |
|
|
|
#endif
|
|
|
|
|
|
|
|
#if UNITY_EDITOR_WIN
|
|
|
|
#elif UNITY_EDITOR_OSX
|
|
|
|
ExitCode = ExecuteCMD($"\cp -r \"{pyrceptionPath}\" \"{path}/DataInsightsEnv/pyrception-util\""); |
|
|
|
#endif
|
|
|
|
EditorUtility.DisplayProgressBar("Setting up Pyrception", "Installing pyrception utils...", 3.5f / steps); |
|
|
|
ExitCode = ExecuteCMD($"cd \"{path}\\DataInsightsEnv\\pyrception-util\""); |
|
|
|
if (ExitCode != 0) return; |
|
|
|
EditorUtility.DisplayProgressBar("Setting up Pyrception", "Installing pyrception utils...", 2.5f / steps); |
|
|
|
EditorUtility.DisplayProgressBar("Setting up Pyrception", "Installing pyrception utils...", 3.9f / steps); |
|
|
|
#if UNITY_EDITOR_WIN
|
|
|
|
#elif UNITY_EDITOR_OSX
|
|
|
|
ExitCode = ExecuteCMD($"\"{path}/DataInsightsEnv/Scripts/activate\" && cd {path} && cd ./DataInsightsEnv/pyrception-util && pip --no-cache-dir install -e . && deactivate"); |
|
|
|
#endif
|
|
|
|
|
|
|
|
private static int ExecuteCMD(string command) { |
|
|
|
ProcessStartInfo info = new ProcessStartInfo("cmd.exe", "/c " + command); |
|
|
|
info.CreateNoWindow = true; |
|
|
|
info.UseShellExecute = false; |
|
|
|
private static int ExecuteCMD(string command, bool waitForExit = true, bool displayWindow = false) { |
|
|
|
string shell = ""; |
|
|
|
string argument = ""; |
|
|
|
|
|
|
|
#if UNITY_EDITOR_WIN
|
|
|
|
shell = "cmd.exe"; |
|
|
|
argument = $"/c {command}"; |
|
|
|
#elif UNITY_EDITOR_OSX
|
|
|
|
shell = "/bin/bash"; |
|
|
|
argument = $"-c \"{command}\""; |
|
|
|
#endif
|
|
|
|
ProcessStartInfo info = new ProcessStartInfo(shell, argument); |
|
|
|
|
|
|
|
info.CreateNoWindow = !displayWindow; |
|
|
|
info.UseShellExecute = !waitForExit; |
|
|
|
if (!waitForExit) return 0; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
//UnityEngine.Debug.Log($"Successfully executed: {command}");
|
|
|
|
} |
|
|
|
|
|
|
|
private static void RevertChanges() { |
|
|
|
return; |
|
|
|
} |
|
|
|
} |