您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
34 行
1.1 KiB
34 行
1.1 KiB
using System.IO;
|
|
|
|
namespace UnityEngine.Perception.Randomization.Scenarios
|
|
{
|
|
public abstract class Scenario<T> : ScenarioBase where T : new()
|
|
{
|
|
public T constants = new T();
|
|
|
|
public override string OnSerialize()
|
|
{
|
|
return JsonUtility.ToJson(constants, true);
|
|
}
|
|
|
|
public override void OnDeserialize(string json)
|
|
{
|
|
constants = JsonUtility.FromJson<T>(json);
|
|
}
|
|
|
|
public sealed override void Serialize()
|
|
{
|
|
Directory.CreateDirectory(Application.dataPath + "/StreamingAssets/");
|
|
using (var writer = new StreamWriter(serializedConstantsFilePath, false))
|
|
writer.Write(OnSerialize());
|
|
}
|
|
|
|
public sealed override void Deserialize()
|
|
{
|
|
if (!File.Exists(serializedConstantsFilePath))
|
|
throw new ScenarioException($"JSON scenario constants file does not exist at path {serializedConstantsFilePath}");
|
|
var jsonText = File.ReadAllText(serializedConstantsFilePath);
|
|
OnDeserialize(jsonText);
|
|
}
|
|
}
|
|
}
|