浏览代码

make randomizer state field optional for json config

/0.9.0.preview.1_staging
Aryan Mann 3 年前
当前提交
c06d625b
共有 2 个文件被更改,包括 12 次插入5 次删除
  1. 14
      com.unity.perception/Runtime/Randomization/Scenarios/Serialization/ScenarioSerializer.cs
  2. 3
      com.unity.perception/Runtime/Randomization/Scenarios/Serialization/SerializationStructures.cs

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


static Group SerializeRandomizer(Randomizer randomizer)
{
var randomizerData = new Group();
randomizerData.state.enabled = randomizer.enabled;
randomizerData.state.canBeSwitchedByUser = randomizer.enabledStateCanBeSwitchedByUser;
randomizerData.state = new RandomizerStateData
{
enabled = randomizer.enabled,
canBeSwitchedByUser = randomizer.enabledStateCanBeSwitchedByUser
};
var fields = randomizer.GetType().GetFields();
foreach (var field in fields)

static void DeserializeRandomizer(Randomizer randomizer, Group randomizerData)
{
randomizer.enabled = randomizerData.state.enabled;
randomizer.enabledStateCanBeSwitchedByUser = randomizerData.state.canBeSwitchedByUser;
if (randomizerData.state != null)
{
randomizer.enabled = randomizerData.state.enabled;
randomizer.enabledStateCanBeSwitchedByUser = randomizerData.state.canBeSwitchedByUser;
}
foreach (var pair in randomizerData.items)
{

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


using System.Collections.Generic;
using JetBrains.Annotations;
using Newtonsoft.Json;
namespace UnityEngine.Perception.Randomization.Scenarios.Serialization

class Group
{
public StandardMetadata metadata = new StandardMetadata();
public RandomizerStateData state = new RandomizerStateData();
public RandomizerStateData state = null;
[JsonConverter(typeof(GroupItemsConverter))]
public Dictionary<string, IGroupItem> items = new Dictionary<string, IGroupItem>();
}

正在加载...
取消
保存