浏览代码

fix commands for macOS and linux

/pyrception-integration
leopoldo-zugasti 3 年前
当前提交
6506f922
共有 1 个文件被更改,包括 25 次插入11 次删除
  1. 36
      com.unity.perception/Editor/Pyrception/PyrceptionInstaller.cs

36
com.unity.perception/Editor/Pyrception/PyrceptionInstaller.cs


public class PyrceptionInstaller : EditorWindow
{
/// <summary>
/// Runs pyrception instance in default browser
/// </summary>
[MenuItem("Window/Pyrception/Run")]
static void RunPyrception()
{

#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)}/..\"";
#elif (UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX)
command = $"cd {path}/DataInsightsEnv/Scripts; activate; pyrception-utils preview --data=\"{PlayerPrefs.GetString(SimulationState.latestOutputDirectoryKey)}/..\"";
/// <summary>
/// Install pyrception (Assumes python and pip are already installed)
/// - installs virtualenv if it is not already installed
/// - and setups a virtual environment for pyrception
/// </summary>
[MenuItem("Window/Pyrception/Setup")]
static void SetupPyrception()
{

#if UNITY_EDITOR_WIN
path = path.Replace("/", "\\");
#endif
string pyrceptionPath = Path.GetFullPath("Packages/com.unity.perception/Editor/Pyrception/pyrception-utils");
string pyrceptionPath = Path.GetFullPath("Packages/com.unity.perception/Editor/Pyrception/pyrception-utils").Replace("\\","/");
EditorUtility.DisplayProgressBar("Setting up Pyrception", "Installing virtualenv...", 0 / steps);
int ExitCode = 0;

#if UNITY_EDITOR_WIN
ExitCode = ExecuteCMD($"virtualenv \"{path}\\DataInsightsEnv\"");
#elif UNITY_EDITOR_OSX
ExitCode = ExecuteCMD($"virtualenv \"{path}/DataInsightsEnv"");
#elif (UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX)
ExitCode = ExecuteCMD($"virtualenv \"{path}/DataInsightsEnv\"");
#endif
if (ExitCode != 0) return;

ExitCode = ExecuteCMD($"XCOPY /E/I/Y \"{pyrceptionPath}\" \"{path}\\DataInsightsEnv\\pyrception-util\"");
#elif UNITY_EDITOR_OSX
ExitCode = ExecuteCMD($"\cp -r \"{pyrceptionPath}\" \"{path}/DataInsightsEnv/pyrception-util\"");
#elif (UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX)
ExitCode = ExecuteCMD($"\\cp -r \"{pyrceptionPath}\" \"{path}/DataInsightsEnv/pyrception-util\"");
#endif
if (ExitCode != 0) return;

ExitCode = ExecuteCMD($"\"{path}\\DataInsightsEnv\\Scripts\\activate\" && cd {path} && cd .\\DataInsightsEnv\\pyrception-util\\ && pip --no-cache-dir install -e . && deactivate");
#elif UNITY_EDITOR_OSX
ExitCode = ExecuteCMD($"\"{path}/DataInsightsEnv/Scripts/activate\" && cd {path} && cd ./DataInsightsEnv/pyrception-util && pip --no-cache-dir install -e . && deactivate");
#elif (UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX)
ExitCode = ExecuteCMD($"\"{path}/DataInsightsEnv/Scripts/activate\"; cd \"{path}/DataInsightsEnv/pyrception-util\"; pip --no-cache-dir install -e .; deactivate");
#endif
if (ExitCode != 0) return;

/// <summary>
/// Executes command in cmd or console depending on system
/// </summary>
/// <param name="command">The command to execute</param>
/// <param name="waitForExit">Should it wait for exit before returning to the editor (i.e. is it not async?)</param>
/// <param name="displayWindow">Should the command window be displayed</param>
/// <returns></returns>
private static int ExecuteCMD(string command, bool waitForExit = true, bool displayWindow = false) {
string shell = "";
string argument = "";

argument = $"/c {command}";
#elif UNITY_EDITOR_OSX
#elif (UNITY_EDITOR_OSX || UNITY_EDITOR_LINUX)
shell = "/bin/bash";
argument = $"-c \"{command}\"";
#endif

正在加载...
取消
保存