浏览代码

removed c# 8 code

/main
Steven Leal 4 年前
当前提交
9c47d0a8
共有 2 个文件被更改,包括 21 次插入20 次删除
  1. 39
      com.unity.perception/Runtime/Randomization/Scenarios/Serialization/ScenarioSerializer.cs
  2. 2
      com.unity.perception/Tests/Runtime/Randomization/ScenarioTests/ScenarioTests.cs

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


static ISampler DeserializeSampler(ISamplerOption samplerOption)
{
return samplerOption switch
{
ConstantSampler constantSampler => new Samplers.ConstantSampler
if (samplerOption is ConstantSampler constantSampler)
return new Samplers.ConstantSampler
},
UniformSampler uniformSampler => new Samplers.UniformSampler
};
if (samplerOption is UniformSampler uniformSampler)
return new Samplers.UniformSampler
{
range = new FloatRange
{

},
NormalSampler normalSampler => new Samplers.NormalSampler
};
if (samplerOption is NormalSampler normalSampler)
return new Samplers.NormalSampler
{
range = new FloatRange
{

mean = (float)normalSampler.mean,
standardDeviation = (float)normalSampler.standardDeviation
},
_ => throw new ArgumentException(
$"Cannot deserialize unsupported sampler type {samplerOption.GetType()}")
};
};
throw new ArgumentException($"Cannot deserialize unsupported sampler type {samplerOption.GetType()}");
object value = scalar.value switch
{
StringScalarValue stringValue => stringValue.str,
BooleanScalarValue booleanValue => booleanValue.boolean,
DoubleScalarValue doubleValue => doubleValue.num,
_ => throw new ArgumentException(
$"Cannot deserialize unsupported scalar type {scalar.value.GetType()}")
};
object value;
if (scalar.value is StringScalarValue stringValue)
value = stringValue.str;
else if (scalar.value is BooleanScalarValue booleanValue)
value = booleanValue.boolean;
else if (scalar.value is DoubleScalarValue doubleValue)
value = doubleValue;
else
throw new ArgumentException(
$"Cannot deserialize unsupported scalar type {scalar.value.GetType()}");
field.SetValue(obj, Convert.ChangeType(value, field.FieldType));
}
#endregion

2
com.unity.perception/Tests/Runtime/Randomization/ScenarioTests/ScenarioTests.cs


m_Scenario = m_TestObject.AddComponent<FixedLengthScenario>();
m_Scenario.CreateRandomizer<RotationRandomizer>();
static string RemoveWhitespace(string str) =>
string RemoveWhitespace(string str) =>
string.Join("", str.Split(default(string[]), StringSplitOptions.RemoveEmptyEntries));
var expectedConfigAsset = (TextAsset)Resources.Load("SampleScenarioConfiguration");

正在加载...
取消
保存