浏览代码

merge serialization array change

/0.9.0.preview.1_staging
Aryan Mann 3 年前
当前提交
a7b4cce8
共有 4 个文件被更改,包括 20 次插入14 次删除
  1. 2
      com.unity.perception/CHANGELOG.md
  2. 22
      com.unity.perception/Runtime/Randomization/Scenarios/Serialization/ScenarioSerializer.cs
  3. 3
      com.unity.perception/Runtime/Randomization/Scenarios/Serialization/SerializationStructures.cs
  4. 7
      com.unity.perception/Tests/Runtime/Randomization/ScenarioTests/Resources/SampleScenarioConfiguration.json

2
com.unity.perception/CHANGELOG.md


Changed the JSON serialization key of Normal Sampler's standard deviation property from "standardDeviation" to "stddev".
Changed the JSON serialization of Randomizers in a scenario to an array of groups rather than a dictionary.
### Deprecated
### Removed

22
com.unity.perception/Runtime/Randomization/Scenarios/Serialization/ScenarioSerializer.cs


{
return new TemplateConfigurationOptions
{
groups = SerializeRandomizers(scenario.randomizers)
randomizerGroups = SerializeRandomizers(scenario.randomizers)
static Dictionary<string, Group> SerializeRandomizers(IEnumerable<Randomizer> randomizers)
static List<Group> SerializeRandomizers(IEnumerable<Randomizer> randomizers)
var serializedRandomizers = new Dictionary<string, Group>();
var serializedRandomizers = new List<Group>();
serializedRandomizers.Add(randomizer.GetType().Name, randomizerData);
serializedRandomizers.Add(randomizerData);
}
return serializedRandomizers;
}

};
var fields = randomizer.GetType().GetFields();
randomizerData.randomizerId = randomizer.GetType().Name;
foreach (var field in fields)
{
if (field.FieldType.IsSubclassOf(typeof(Randomization.Parameters.Parameter)))

static void DeserializeTemplateIntoScenario(ScenarioBase scenario, TemplateConfigurationOptions template)
{
DeserializeRandomizers(scenario.randomizers, template.groups);
DeserializeRandomizers(scenario.randomizers, template.randomizerGroups);
static void DeserializeRandomizers(IEnumerable<Randomizer> randomizers, Dictionary<string, Group> groups)
static void DeserializeRandomizers(IEnumerable<Randomizer> randomizers, List<Group> groups)
foreach (var randomizerPair in groups)
foreach (var randomizerData in groups)
if (!randomizerTypeMap.ContainsKey(randomizerPair.Key))
if (!randomizerTypeMap.ContainsKey(randomizerData.randomizerId))
var randomizer = randomizerTypeMap[randomizerPair.Key];
DeserializeRandomizer(randomizer, randomizerPair.Value);
var randomizer = randomizerTypeMap[randomizerData.randomizerId];
DeserializeRandomizer(randomizer, randomizerData);
}
}

3
com.unity.perception/Runtime/Randomization/Scenarios/Serialization/SerializationStructures.cs


#region GroupedObjects
class TemplateConfigurationOptions
{
public Dictionary<string, Group> groups = new Dictionary<string, Group>();
public List<Group> randomizerGroups = new List<Group>();
}
class StandardMetadata

class Group
{
public string randomizerId;
public StandardMetadata metadata = new StandardMetadata();
public RandomizerStateData state = null;
[JsonConverter(typeof(GroupItemsConverter))]

7
com.unity.perception/Tests/Runtime/Randomization/ScenarioTests/Resources/SampleScenarioConfiguration.json


"randomSeed": 539662031
},
"randomizers": {
"groups": {
"RotationRandomizer": {
"randomizerGroups": [
{
"randomizerId": "RotationRandomizer",
"metadata": {
"name": "",
"description": "",

}
}
}
}
]
}
}
正在加载...
取消
保存