浏览代码

Install python for unity dependency only when editor is on Windows or Macos

/pyrception-integration
leopoldo-zugasti 3 年前
当前提交
81297e14
共有 5 个文件被更改,包括 91 次插入10 次删除
  1. 2
      com.unity.perception/Editor/Visualizer/PipAPI.cs
  2. 18
      com.unity.perception/Editor/Visualizer/VisualizerInstaller.cs
  3. 5
      com.unity.perception/package.json
  4. 65
      com.unity.perception/Editor/Visualizer/PythonForUnityInstaller.cs
  5. 11
      com.unity.perception/Editor/Visualizer/PythonForUnityInstaller.cs.meta

2
com.unity.perception/Editor/Visualizer/PipAPI.cs


#if UNITY_EDITOR_WIN || UNITY_EDITOR_OSX
using System;
using System.Collections.Generic;
using System.IO;

}
}
}
#endif

18
com.unity.perception/Editor/Visualizer/VisualizerInstaller.cs


#if UNITY_EDITOR_WIN || UNITY_EDITOR_OSX || true
using System;
using System.Collections.Generic;
using System.Diagnostics;

EditorUtility.DisplayProgressBar("Setting up the Visualizer", "Installing the Visualizer...", 2.5f / steps);
#if UNITY_EDITOR_WIN
ExecuteCMD($"\"{packagesPath}\"\\pip3.bat install --upgrade --no-warn-script-location unity-cv-datasetvisualizer", ref ExitCode, ref output);
ExecuteCMD($"\"{packagesPath}\"\\pip3.bat install --upgrade --no-warn-script-location unity-cv-datasetvisualizer", ref ExitCode, ref output, waitForExit: 0);
ExecuteCMD($"cd \'{packagesPath}\'; ./python3.7 -m pip install --upgrade unity-cv-datasetvisualizer", ref ExitCode, ref output);
ExecuteCMD($"cd \'{packagesPath}\'; ./python3.7 -m pip install --upgrade unity-cv-datasetvisualizer", ref ExitCode, ref output, waitForExit: 0);
#endif
if (ExitCode != 0) {
EditorUtility.ClearProgressBar();

EditorUtility.ClearProgressBar();
UnityEngine.Debug.Log("Successfully installed visualizer");
UnityEngine.Debug.Log("Successfully installed visualizer");
}
/// <summary>

info.CreateNoWindow = !displayWindow;
info.UseShellExecute = false;
info.RedirectStandardOutput = getOutput;
info.RedirectStandardError = waitForExit == 0;
info.RedirectStandardError = waitForExit != 0;
if (!(waitForExit != 0))
if (waitForExit == 0)
{
return cmd.Id;
}

if (getOutput) {
if (getOutput && waitForExit != 0) {
output = cmd.StandardOutput.ReadToEnd();
}

return 0;
}
/// <summary>
/// If an instance is already running for this project it opens the browser at the correct port
/// If no instance is found it launches a new process

{
{
if (!checkIfVisualizerInstalled())
{
SetupVisualizer();

}
}
}
#endif

5
com.unity.perception/package.json


"com.unity.render-pipelines.core": "7.1.6",
"com.unity.simulation.capture": "0.0.10-preview.23",
"com.unity.simulation.client": "0.0.10-preview.10",
"com.unity.simulation.core": "0.0.10-preview.22",
"com.unity.scripting.python": "4.0.0-exp.5"
"com.unity.simulation.core": "0.0.10-preview.22"
},
"description": "Tools for generating large-scale data sets for perception-based machine learning training and validation",
"displayName": "Perception",

"path": "Samples~/Human Pose Labeling and Randomization"
}
]
}
}

65
com.unity.perception/Editor/Visualizer/PythonForUnityInstaller.cs


#if UNITY_EDITOR_WIN || UNITY_EDITOR_OSX || true
using System;
using UnityEditor;
using UnityEditor.PackageManager.Requests;
using UnityEditor.PackageManager;
using UnityEngine;
using System.Threading;
namespace UnityEditor.Perception.Visualizer
{
#if UNITY_EDITOR_WIN || UNITY_EDITOR_OSX
[InitializeOnLoad]
#endif
internal static class PythonForUnityInstaller
{
#if UNITY_EDITOR_WIN || UNITY_EDITOR_OSX
static PythonForUnityInstaller()
{
Add();
}
#endif
internal static void Add()
{
if (!checkIfPackageInstalled())
{
AddRequest request = Client.Add("com.unity.scripting.python@4.0.0-exp.5");
EditorUtility.DisplayProgressBar("Setting up the Visualizer", "Installing the Visualizer...", 0.2f);
while (!request.IsCompleted)
{
Thread.Sleep(100);
}
if (request.Status == StatusCode.Success)
Debug.Log("Installed: " + request.Result.packageId);
else if (request.Status >= StatusCode.Failure)
Debug.Log(request.Error.message);
}
}
static bool checkIfPackageInstalled()
{
ListRequest request = Client.List();
while (!request.IsCompleted)
{
Thread.Sleep(100);
}
if (request.Status == StatusCode.Success)
{
foreach (var package in request.Result)
{
if (package.packageId.Contains("com.unity.scripting.python"))
{
return true;
}
}
}
else if (request.Status >= StatusCode.Failure)
Debug.LogError(request.Error.message);
return false;
}
}
}
#endif

11
com.unity.perception/Editor/Visualizer/PythonForUnityInstaller.cs.meta


fileFormatVersion: 2
guid: a2b3dd102c3620042b77a9d621a05630
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存