浏览代码

Fixing and adding test for PerceptionCamera OnDisable exception and exceptions on entering playmode.

/fix-editor-pause
Jon Hogins 4 年前
当前提交
2b4910d3
共有 4 个文件被更改,包括 84 次插入3 次删除
  1. 6
      com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs
  2. 5
      com.unity.perception/Tests/Editor/Unity.Perception.Editor.Tests.asmdef
  3. 73
      com.unity.perception/Tests/Editor/PerceptionCameraEditorTests.cs
  4. 3
      com.unity.perception/Tests/Editor/PerceptionCameraEditorTests.cs.meta

6
com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs


{
if (camera != GetComponent<Camera>())
return;
#if UNITY_EDITOR
if (UnityEditor.EditorApplication.isPaused)
return;
#endif
ReportAsyncAnnotations();
CaptureRgbData(camera);
}

if (m_RenderedObjectInfoGenerator != null)
{
World.DefaultGameObjectInjectionWorld.GetExistingSystem<GroundTruthLabelSetupSystem>().Deactivate(m_RenderedObjectInfoGenerator);
World.DefaultGameObjectInjectionWorld?.GetExistingSystem<GroundTruthLabelSetupSystem>()?.Deactivate(m_RenderedObjectInfoGenerator);
m_RenderedObjectInfoGenerator?.Dispose();
m_RenderedObjectInfoGenerator = null;
}

5
com.unity.perception/Tests/Editor/Unity.Perception.Editor.Tests.asmdef


"Unity.Mathematics",
"Unity.Perception.Editor",
"Unity.Collections",
"Unity.Entities"
"Unity.Entities",
"Unity.Simulation.Core"
],
"includePlatforms": [
"Editor"

],
"versionDefines": [],
"noEngineReferences": false
}
}

73
com.unity.perception/Tests/Editor/PerceptionCameraEditorTests.cs


using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using NUnit.Framework;
using Unity.Collections;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.Perception;
using UnityEngine.Perception.Sensors;
using UnityEngine.TestTools;
namespace EditorTests
{
[TestFixture]
public class PerceptionCameraEditorTests
{
[UnityTest]
public IEnumerator EditorPause_DoesNotLogErrors()
{
int sceneCount = EditorSceneManager.sceneCount;
for (int i = sceneCount - 1; i >= 0; i--)
{
EditorSceneManager.CloseScene(EditorSceneManager.GetSceneAt(i), true);
}
EditorSceneManager.NewScene(NewSceneSetup.EmptyScene);
SetupCamera(ScriptableObject.CreateInstance<LabelingConfiguration>());
yield return new EnterPlayMode();
var expectedFirstFrame = Time.frameCount;
yield return null;
EditorApplication.isPaused = true;
yield return null;
yield return null;
yield return null;
yield return null;
EditorApplication.isPaused = false;
var expectedLastFrame = Time.frameCount;
yield return null;
SimulationManager.ResetSimulation();
var capturesPath = Path.Combine(SimulationManager.OutputDirectory, "captures_000.json");
var capturesJson = File.ReadAllText(capturesPath);
for (int iFrameCount = expectedFirstFrame; iFrameCount <= expectedLastFrame; iFrameCount++)
{
var imagePath = Path.Combine(PerceptionCamera.RgbDirectory, $"rgb_{iFrameCount}").Replace(@"\", @"\\");
StringAssert.Contains(imagePath, capturesJson);
}
yield return new ExitPlayMode();
}
static GameObject SetupCamera(LabelingConfiguration labelingConfiguration)
{
var cameraObject = new GameObject();
cameraObject.SetActive(false);
var camera = cameraObject.AddComponent<Camera>();
camera.orthographic = true;
camera.orthographicSize = 1;
var perceptionCamera = cameraObject.AddComponent<PerceptionCamera>();
perceptionCamera.LabelingConfiguration = labelingConfiguration;
perceptionCamera.captureRgbImages = true;
perceptionCamera.produceBoundingBoxAnnotations = true;
perceptionCamera.produceObjectCountAnnotations = true;
cameraObject.SetActive(true);
return cameraObject;
}
}
}

3
com.unity.perception/Tests/Editor/PerceptionCameraEditorTests.cs.meta


fileFormatVersion: 2
guid: 6efa744f46fc41e8aa4296d99f4c66c9
timeCreated: 1587395248
正在加载...
取消
保存