Skip to content

Commit b3a5f03

Browse files
authored
Merge pull request #361 from Unity-Technologies/pyrception-integration
Added the Dataset Visualizer installer and corresponding UI
2 parents 8a97caa + eaea105 commit b3a5f03

File tree

12 files changed

+980
-5
lines changed

12 files changed

+980
-5
lines changed

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using UnityEditorInternal;
44
using UnityEngine;
55
using UnityEngine.Perception.GroundTruth;
66

7+
#if UNITY_EDITOR_WIN || UNITY_EDITOR_OSX
8+
using UnityEditor.Perception.Visualizer;
9+
#endif
10+
711
namespace UnityEditor.Perception.GroundTruth
812
{
913
[CustomEditor(typeof(PerceptionCamera))]
@@ -189,6 +193,27 @@ public override void OnInspectorGUI()
189193
GUILayout.EndHorizontal();
190194
GUILayout.EndVertical();
191195

196+
#if UNITY_EDITOR_WIN || UNITY_EDITOR_OSX
197+
GUILayout.Space(10);
198+
EditorGUILayout.LabelField("Visualizer Tool");
199+
200+
GUILayout.BeginHorizontal("TextArea");
201+
if (GUILayout.Button("Open Visualizer"))
202+
{
203+
var project = Application.dataPath;
204+
_=VisualizerInstaller.RunVisualizer(project);
205+
}
206+
207+
if (GUILayout.Button("Check For Updates"))
208+
{
209+
var project = Application.dataPath;
210+
_=VisualizerInstaller.CheckForUpdates();
211+
}
212+
213+
GUILayout.EndHorizontal();
214+
GUILayout.Space(10);
215+
#endif
216+
192217

193218
if (EditorSettings.asyncShaderCompilation)
194219
{

com.unity.perception/Editor/Pyrception.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

com.unity.perception/Editor/Pyrception/pyrception-utils.meta renamed to com.unity.perception/Editor/Visualizer.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#if UNITY_EDITOR_WIN || UNITY_EDITOR_OSX
2+
using System;
3+
using System.Net.Http;
4+
using System.Threading.Tasks;
5+
using Newtonsoft.Json;
6+
using UnityEngine;
7+
8+
namespace UnityEditor.Perception.Visualizer
9+
{
10+
static class PipAPI
11+
{
12+
static readonly HttpClient k_HttpClient;
13+
const string k_PypiServer = "https://pypi.org";
14+
const string k_PackageName = "unity-cv-datasetvisualizer";
15+
16+
static PipAPI()
17+
{
18+
k_HttpClient = new HttpClient();
19+
}
20+
21+
internal static async Task<string> GetLatestVersionNumber()
22+
{
23+
var requestUri = new Uri($"{k_PypiServer}/pypi/{k_PackageName}/json?Accept=application/json");
24+
try
25+
{
26+
var httpResponse = await k_HttpClient.GetAsync(requestUri);
27+
if (httpResponse.IsSuccessStatusCode)
28+
{
29+
var responseString = httpResponse.Content.ReadAsStringAsync().Result;
30+
dynamic responseJson = JsonConvert.DeserializeObject(responseString);
31+
return responseJson.info.version;
32+
}
33+
34+
HandleApiErrors(httpResponse);
35+
}
36+
catch (HttpRequestException e)
37+
{
38+
Debug.LogException(e);
39+
}
40+
return null;
41+
}
42+
43+
static void HandleApiErrors(HttpResponseMessage responseMessage)
44+
{
45+
Debug.LogError("A request to PyPI.org did not successfully complete: " + responseMessage.ReasonPhrase);
46+
}
47+
48+
internal static int CompareVersions(string version1, string version2)
49+
{
50+
var split1 = version1.Split('.');
51+
var split2 = version2.Split('.');
52+
53+
int i;
54+
for(i = 0; i < Math.Min(split1.Length, split2.Length); i++)
55+
{
56+
var compare = Int32.Parse(split1[i]) - Int32.Parse(split2[i]);
57+
if (compare != 0)
58+
{
59+
return compare;
60+
}
61+
}
62+
63+
if (i < split1.Length)
64+
return 1;
65+
66+
if (i < split2.Length)
67+
return -1;
68+
69+
return 0;
70+
}
71+
}
72+
}
73+
#endif

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

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#if UNITY_EDITOR_WIN || UNITY_EDITOR_OSX
2+
using System;
3+
using UnityEditor.PackageManager.Requests;
4+
using UnityEditor.PackageManager;
5+
using UnityEngine;
6+
using System.Threading;
7+
8+
namespace UnityEditor.Perception.Visualizer
9+
{
10+
[InitializeOnLoad]
11+
static class PythonForUnityInstaller
12+
{
13+
static PythonForUnityInstaller()
14+
{
15+
Add();
16+
}
17+
18+
static void Add()
19+
{
20+
if (!CheckIfPackageInstalled())
21+
{
22+
var request = Client.Add("[email protected]");
23+
24+
while (!request.IsCompleted)
25+
{
26+
Thread.Sleep(100);
27+
}
28+
if (request.Status == StatusCode.Success)
29+
Debug.Log("Installed: " + request.Result.packageId);
30+
else if (request.Status >= StatusCode.Failure)
31+
Debug.Log(request.Error.message);
32+
}
33+
}
34+
35+
static bool CheckIfPackageInstalled()
36+
{
37+
var request = Client.List();
38+
while (!request.IsCompleted)
39+
{
40+
Thread.Sleep(100);
41+
}
42+
if (request.Status == StatusCode.Success)
43+
{
44+
foreach (var package in request.Result)
45+
{
46+
if (package.packageId.Contains("com.unity.scripting.python"))
47+
{
48+
return true;
49+
}
50+
}
51+
}
52+
else if (request.Status >= StatusCode.Failure)
53+
Debug.LogError(request.Error.message);
54+
return false;
55+
}
56+
}
57+
}
58+
#endif

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

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)