浏览代码

Updated RunInUnitySimulationWindow for new serialization format

/main
Steven Leal 4 年前
当前提交
4ce3c145
共有 5 个文件被更改,包括 32 次插入19 次删除
  1. 20
      com.unity.perception/Editor/Randomization/Editors/RunInUnitySimulationWindow.cs
  2. 3
      com.unity.perception/Editor/Randomization/Editors/ScenarioBaseEditor.cs
  3. 13
      com.unity.perception/Runtime/Randomization/Scenarios/Scenario.cs
  4. 13
      com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs
  5. 2
      com.unity.perception/Runtime/Randomization/Scenarios/UnitySimulationScenario.cs

20
com.unity.perception/Editor/Randomization/Editors/RunInUnitySimulationWindow.cs


using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Unity.Simulation.Client;
using UnityEditor;
using UnityEditor.Build.Reporting;

List<AppParam> GenerateAppParamIds(CancellationToken token)
{
var appParamIds = new List<AppParam>();
var scenario = (ScenarioBase)m_ScenarioField.value;
var configuration = JObject.Parse(scenario.Serialize());
var constants = configuration["constants"];
constants["totalIterations"] = m_TotalIterationsField.value;
constants["instanceCount"]= m_InstanceCountField.value;
var appParamId = API.UploadAppParam(appParamName, new UnitySimulationScenarioConstants
{
totalIterations = m_TotalIterationsField.value,
instanceCount = m_InstanceCountField.value,
instanceIndex = i
});
constants["instanceIndex"]= i;
var appParamsString = JsonConvert.SerializeObject(configuration, Formatting.Indented);
var appParamId = API.UploadAppParam(appParamName, appParamsString);
appParamIds.Add(new AppParam()
{
id = appParamId,

}
return appParamIds;
}

3
com.unity.perception/Editor/Randomization/Editors/ScenarioBaseEditor.cs


var serializeConstantsButton = m_Root.Q<Button>("serialize-constants");
serializeConstantsButton.clicked += () =>
{
m_Scenario.Serialize();
m_Scenario.SerializeToConfigFile();
AssetDatabase.Refresh();
var newConfigFileAsset = AssetDatabase.LoadAssetAtPath<Object>(m_Scenario.defaultConfigFileAssetPath);
EditorGUIUtility.PingObject(newConfigFileAsset);
};

13
com.unity.perception/Runtime/Randomization/Scenarios/Scenario.cs


public override ScenarioConstants genericConstants => constants;
/// <summary>
/// Serializes this scenario's constants to a json file in the Unity StreamingAssets folder
/// Serializes the scenario's constants and randomizer configuration to a JSON string
public override void Serialize()
{
Directory.CreateDirectory(Application.dataPath + "/StreamingAssets/");
using (var writer = new StreamWriter(defaultConfigFilePath, false))
writer.Write(SerializeConfig());
}
string SerializeConfig()
public override string Serialize()
{
var configObj = new JObject
{

DeserializeConfig(jsonText);
}
else
Debug.LogError($"A scenario configuration file does not exist at path {defaultConfigFilePath}");
Debug.LogError($"A scenario configuration file does not exist at path {configFilePath}");
}
void DeserializeConfig(string json)

13
com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs


using System;
using System.Collections.Generic;
using System.IO;
using Unity.Simulation;
using UnityEngine;
using UnityEngine.Experimental.Perception.Randomization.Randomizers;

}
/// <summary>
/// Serializes the scenario's constants and randomizer configuration to a JSON string
/// </summary>
public abstract string Serialize();
/// <summary>
public abstract void Serialize();
public virtual void SerializeToConfigFile()
{
Directory.CreateDirectory(Application.dataPath + "/StreamingAssets/");
using (var writer = new StreamWriter(defaultConfigFilePath, false))
writer.Write(Serialize());
}
/// <summary>
/// Deserializes constants saved in a JSON file located at serializedConstantsFilePath

2
com.unity.perception/Runtime/Randomization/Scenarios/UnitySimulationScenario.cs


public sealed override void Deserialize(string configFilePath)
{
base.Deserialize(Configuration.Instance.IsSimulationRunningInCloud()
? Configuration.Instance.SimulationConfig.app_param_uri
? new Uri(Configuration.Instance.SimulationConfig.app_param_uri).LocalPath
: configFilePath);
currentIteration = constants.instanceIndex;
}
正在加载...
取消
保存