浏览代码

Merge pull request #148 from Unity-Technologies/on-create-randomizer-fix

On create randomizer fix
/main
GitHub 4 年前
当前提交
a4509db7
共有 4 个文件被更改,包括 68 次插入0 次删除
  1. 2
      com.unity.perception/CHANGELOG.md
  2. 5
      com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs
  3. 58
      com.unity.perception/Tests/Editor/RandomizerEditorTests.cs
  4. 3
      com.unity.perception/Tests/Editor/RandomizerEditorTests.cs.meta

2
com.unity.perception/CHANGELOG.md


Fixed memory leak or crash occurring at the end of long simulations when using BackgroundObjectPlacementRandomizer or ForegroundObjectPlacementRandomizer
Randomizer.OnCreate() is no longer called in edit-mode when adding a randomizer to a scenario
## [0.6.0-preview.1] - 2020-12-03
### Added

5
com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs


$"Two Randomizers of the same type ({randomizerType.Name}) cannot both be active simultaneously");
var newRandomizer = (Randomizer)Activator.CreateInstance(randomizerType);
m_Randomizers.Add(newRandomizer);
#if UNITY_EDITOR
if (Application.isPlaying)
newRandomizer.Create();
#else
#endif
return newRandomizer;
}

58
com.unity.perception/Tests/Editor/RandomizerEditorTests.cs


using System;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.Experimental.Perception.Randomization.Randomizers;
using UnityEngine.Experimental.Perception.Randomization.Scenarios;
using Object = UnityEngine.Object;
namespace EditorTests
{
[TestFixture]
public class RandomizerEditorTests
{
GameObject m_TestObject;
FixedLengthScenario m_Scenario;
[SetUp]
public void Setup()
{
m_TestObject = new GameObject();
m_Scenario = m_TestObject.AddComponent<FixedLengthScenario>();
}
[TearDown]
public void TearDown()
{
Object.DestroyImmediate(m_TestObject);
}
[Test]
public void RandomizerOnCreateMethodNotCalledInEditMode()
{
// TestRandomizer.OnCreate() should NOT be called here while in edit-mode
// if ScenarioBase.CreateRandomizer<>() was coded correctly
Assert.DoesNotThrow(() =>
{
m_Scenario.CreateRandomizer<ErrorsOnCreateTestRandomizer>();
});
}
}
[Serializable]
[AddRandomizerMenu("Test Randomizers/Errors OnCreate Test Randomizer")]
class ErrorsOnCreateTestRandomizer : Randomizer
{
public GameObject testGameObject;
protected override void OnCreate()
{
// This line should throw a NullReferenceException
testGameObject.transform.position = Vector3.zero;
}
protected override void OnIterationStart()
{
testGameObject = new GameObject("Test");
}
}
}

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


fileFormatVersion: 2
guid: 26d4a82fa0c640349e6d89fe1c536b72
timeCreated: 1610137610
正在加载...
取消
保存