浏览代码

Fix async

/pyrception-integration
leopoldo-zugasti 3 年前
当前提交
4feb99d8
共有 2 个文件被更改,包括 20 次插入16 次删除
  1. 5
      com.unity.perception/Editor/GroundTruth/PerceptionCameraEditor.cs
  2. 31
      com.unity.perception/Editor/Visualizer/VisualizerInstaller.cs

5
com.unity.perception/Editor/GroundTruth/PerceptionCameraEditor.cs


using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEditor.Perception.Visualizer;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Perception.GroundTruth;

#if UNITY_EDITOR_WIN || UNITY_EDITOR_OSX
if (GUILayout.Button("Open Visualizer"))
{
Debug.Log("Hello?");
Task.Run(Visualizer.VisualizerInstaller.RunVisualizer);
var project = Application.dataPath;
_=VisualizerInstaller.RunVisualizer(project);
}
#endif
GUILayout.EndVertical();

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


return 0;
}
[MenuItem("Window/Visualizer/Open")]
public static async Task RunVisualizerButton()
{
var project = Application.dataPath;
await RunVisualizer(project);
}
[MenuItem("Window/Visualizer/Run")]
public static async Task RunVisualizer()
public static async Task RunVisualizer(string project)
if (!CheckIfVisualizerInstalled())
if (!CheckIfVisualizerInstalled(project))
//The dataPath is used as a unique identifier for the project
var project = Application.dataPath;
var (pythonPid, port, visualizerPid) = ReadEntry(project);

var before = Process.GetProcesses();
EditorUtility.DisplayProgressBar("Opening Visualizer", "Running executable", 1f / 4);
var errorCode = ExecuteVisualizer();
var errorCode = ExecuteVisualizer(project);
if (errorCode == -1)
{
EditorUtility.ClearProgressBar();

/// <summary>
/// Runs visualizer instance (streamlit) from the python for unity install
/// </summary>
static int ExecuteVisualizer()
static int ExecuteVisualizer(string project)
var packagesPath = Path.GetFullPath(Application.dataPath.Replace("/Assets", "/Library/PythonInstall/Scripts"));
var packagesPath = Path.GetFullPath(project.Replace("/Assets", "/Library/PythonInstall/Scripts"));
var packagesPath = Application.dataPath.Replace("/Assets","/Library/PythonInstall/bin");
var packagesPath = project.Replace("/Assets","/Library/PythonInstall/bin");
#endif
var pathToData = PlayerPrefs.GetString(SimulationState.latestOutputDirectoryKey);

[MenuItem("Window/Visualizer/Check For Updates")]
static async Task CheckForUpdates()
{
if (!CheckIfVisualizerInstalled())
var project = Application.dataPath;
if (!CheckIfVisualizerInstalled(project))
{
if (EditorUtility.DisplayDialog("Visualizer not Installed",
$"The visualizer is not yet installed, do you wish to install it?",

}
}
static bool CheckIfVisualizerInstalled()
static bool CheckIfVisualizerInstalled(string project)
var packagesPath = Path.GetFullPath(Application.dataPath.Replace("/Assets", "/Library/PythonInstall/Scripts"));
var packagesPath = Path.GetFullPath(project.Replace("/Assets", "/Library/PythonInstall/Scripts"));
var packagesPath = Path.GetFullPath(Application.dataPath.Replace("/Assets","/Library/PythonInstall/bin"));
var packagesPath = Path.GetFullPath(project.Replace("/Assets","/Library/PythonInstall/bin"));
#endif
#if UNITY_EDITOR_WIN

正在加载...
取消
保存