浏览代码

Merge pull request #149 from Unity-Technologies/check-null-scenario-on-randomizer-tag

Decouple RandomizerTagManager from Scenarios
/main
GitHub 4 年前
当前提交
4f514ec9
共有 7 个文件被更改,包括 27 次插入16 次删除
  1. 2
      com.unity.perception/Runtime/Randomization/Randomizers/Randomizer.cs
  2. 1
      com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Randomizers/BackgroundObjectPlacementRandomizer.cs
  3. 1
      com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Randomizers/ForegroundObjectPlacementRandomizer.cs
  4. 9
      com.unity.perception/Runtime/Randomization/Randomizers/RandomizerTag.cs
  5. 5
      com.unity.perception/Runtime/Randomization/Randomizers/RandomizerTagManager.cs
  6. 17
      com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs
  7. 8
      com.unity.perception/Tests/Runtime/Randomization/RandomizerTests/RandomizerTagTests.cs

2
com.unity.perception/Runtime/Randomization/Randomizers/Randomizer.cs


/// <summary>
/// Retrieves the RandomizerTagManager of the scenario containing this Randomizer
/// </summary>
public RandomizerTagManager tagManager => scenario.tagManager;
public RandomizerTagManager tagManager => RandomizerTagManager.singleton;
internal IEnumerable<Parameter> parameters
{

1
com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Randomizers/BackgroundObjectPlacementRandomizer.cs


GameObject m_Container;
GameObjectOneWayCache m_GameObjectOneWayCache;
/// <inheritdoc/>
protected override void OnCreate()
{
m_Container = new GameObject("BackgroundContainer");

1
com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Randomizers/ForegroundObjectPlacementRandomizer.cs


GameObject m_Container;
GameObjectOneWayCache m_GameObjectOneWayCache;
/// <inheritdoc/>
protected override void OnCreate()
{
m_Container = new GameObject("Foreground Objects");

9
com.unity.perception/Runtime/Randomization/Randomizers/RandomizerTag.cs


using System;
using UnityEngine.Experimental.Perception.Randomization.Scenarios;
namespace UnityEngine.Experimental.Perception.Randomization.Randomizers
{

[Serializable]
public abstract class RandomizerTag : MonoBehaviour
{
RandomizerTagManager tagManager => RandomizerTagManager.singleton;
ScenarioBase.activeScenario.tagManager.AddTag(GetType(), gameObject);
tagManager.AddTag(GetType(), gameObject);
var scenario = ScenarioBase.activeScenario;
if (scenario)
scenario.tagManager.RemoveTag(GetType(), gameObject);
tagManager.RemoveTag(GetType(), gameObject);
}
}
}

5
com.unity.perception/Runtime/Randomization/Randomizers/RandomizerTagManager.cs


/// </summary>
public class RandomizerTagManager
{
/// <summary>
/// Returns the singleton RandomizerTagManager instance
/// </summary>
public static RandomizerTagManager singleton { get; } = new RandomizerTagManager();
Dictionary<Type, HashSet<Type>> m_TypeTree = new Dictionary<Type, HashSet<Type>>();
Dictionary<Type, HashSet<GameObject>> m_TagMap = new Dictionary<Type, HashSet<GameObject>>();

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


using UnityEngine.Experimental.Perception.Randomization.Randomizers;
using UnityEngine.Experimental.Perception.Randomization.Samplers;
using UnityEngine.Perception.GroundTruth;
using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Perception.Randomization.Scenarios
{

bool m_SkipFrame = true;
bool m_FirstScenarioFrame = true;
bool m_WaitingForFinalUploads;
RandomizerTagManager m_TagManager = new RandomizerTagManager();
IEnumerable<Randomizer> activeRandomizers
{

// ReSharper disable once InconsistentNaming
[SerializeReference] internal List<Randomizer> m_Randomizers = new List<Randomizer>();
/// <summary>
/// The RandomizerTagManager attached to this scenario
/// </summary>
public RandomizerTagManager tagManager => m_TagManager;
/// <summary>
/// Return the list of randomizers attached to this scenario

// Don't skip the first frame if executing on Unity Simulation
if (Configuration.Instance.IsSimulationRunningInCloud())
m_SkipFrame = false;
}
void OnEnable()
{
activeScenario = this;
}
void OnDisable()
{
activeScenario = null;
}
void Start()

8
com.unity.perception/Tests/Runtime/Randomization/RandomizerTests/RandomizerTagTests.cs


using System.Linq;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.Experimental.Perception.Randomization.Randomizers;
using UnityEngine.Experimental.Perception.Randomization.Scenarios;
using Assert = Unity.Assertions.Assert;

for (var i = 0; i < copyCount - 1; i++)
Object.Instantiate(gameObject2);
var queriedObjects = m_Scenario.tagManager.Query<ExampleTag>().ToArray();
var tagManager = RandomizerTagManager.singleton;
var queriedObjects = tagManager.Query<ExampleTag>().ToArray();
queriedObjects = m_Scenario.tagManager.Query<ExampleTag2>().ToArray();
queriedObjects = tagManager.Query<ExampleTag2>().ToArray();
queriedObjects = m_Scenario.tagManager.Query<ExampleTag>(true).ToArray();
queriedObjects = tagManager.Query<ExampleTag>(true).ToArray();
Assert.AreEqual(queriedObjects.Length, copyCount * 2);
}
}
正在加载...
取消
保存