浏览代码

separated the randomizer tag manager from the active scenario

/main
Steven Leal 4 年前
当前提交
cb11c3b8
共有 5 个文件被更改,包括 11 次插入17 次删除
  1. 2
      com.unity.perception/Runtime/Randomization/Randomizers/Randomizer.cs
  2. 9
      com.unity.perception/Runtime/Randomization/Randomizers/RandomizerTag.cs
  3. 2
      com.unity.perception/Runtime/Randomization/Randomizers/RandomizerTagManager.cs
  4. 7
      com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs
  5. 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
{

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
{
ScenarioBase scenario => ScenarioBase.activeScenario;
RandomizerTagManager tagManager => RandomizerTagManager.singleton;
if (scenario)
scenario.tagManager.AddTag(GetType(), gameObject);
tagManager.AddTag(GetType(), gameObject);
if (scenario)
scenario.tagManager.RemoveTag(GetType(), gameObject);
tagManager.RemoveTag(GetType(), gameObject);
}
}
}

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


/// </summary>
public class RandomizerTagManager
{
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>>();

7
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

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);
}
}
正在加载...
取消
保存