浏览代码

Merge pull request #43 from unity/additonal_scenario_configs

Make randomizer state field optional for json config
/0.9.0.preview.1_staging
GitHub Enterprise 3 年前
当前提交
3944e6de
共有 3 个文件被更改,包括 14 次插入5 次删除
  1. 3
      com.unity.perception/Runtime/Randomization/Randomizers/Randomizer.cs
  2. 14
      com.unity.perception/Runtime/Randomization/Scenarios/Serialization/ScenarioSerializer.cs
  3. 2
      com.unity.perception/Runtime/Randomization/Scenarios/Serialization/SerializationStructures.cs

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


/// <summary>
/// Some Randomizers should not be disabled by the user as they are critical to the project. E.g. We might want to mark this as false for a foreground objects placement randomizer in some projects
/// </summary>
#if !SCENARIO_CONFIG_POWER_USER
[field: HideInInspector]
#endif
[field: SerializeField]
public bool enabledStateCanBeSwitchedByUser { get; set; } = true;

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)
{

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


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>();
}

正在加载...
取消
保存