浏览代码

only upload one app param now by detecting instance id

/main
Steven Leal 4 年前
当前提交
4e92caff
共有 2 个文件被更改,包括 34 次插入63 次删除
  1. 94
      com.unity.perception/Editor/Randomization/Editors/RunInUnitySimulationWindow.cs
  2. 3
      com.unity.perception/Runtime/Randomization/Scenarios/UnitySimulationScenario.cs

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


}
}
/// <summary>
/// Enables a visual element to remember values between editor sessions
/// </summary>
/// <param name="element">The visual element to enable view data for</param>
static void SetViewDataKey(VisualElement element)
{
element.viewDataKey = $"RunInUnitySimulation_{element.name}";
}
void CreateRunInUnitySimulationUI()
{
var root = rootVisualElement;

void CreateLinuxBuildAndZip()
{
// Create build directory
// Create Linux build
Debug.Log("Creating Linux build...");
var buildPlayerOptions = new BuildPlayerOptions
{
scenes = new[] { currentOpenScenePath },

var report = BuildPipeline.BuildPlayer(buildPlayerOptions);
var summary = report.summary;
if (summary.result != BuildResult.Succeeded)
throw new Exception($"Build did not succeed: status = {summary.result}");
Debug.Log("Created Linux build");
throw new Exception($"The Linux build did not succeed: status = {summary.result}");
// Zip the build
Debug.Log("Starting to zip...");
EditorUtility.DisplayProgressBar("Unity Simulation Run", "Zipping Linux build...", 0f);
Debug.Log("Created build zip");
List<AppParam> GenerateAppParamIds(CancellationToken token, float progressStart, float progressEnd)
List<AppParam> UploadAppParam()
var constants = configuration["constants"];
var constants = configuration["constants"];
var progressIncrement = (progressEnd - progressStart) / m_InstanceCountField.value;
for (var i = 0; i < m_InstanceCountField.value; i++)
var appParamName = $"{m_RunNameField.value}";
var appParamsString = JsonConvert.SerializeObject(configuration, Formatting.Indented);
var appParamId = API.UploadAppParam(appParamName, appParamsString);
appParamIds.Add(new AppParam
if (token.IsCancellationRequested)
return null;
var appParamName = $"{m_RunNameField.value}_{i}";
constants["instanceIndex"] = i;
var appParamsString = JsonConvert.SerializeObject(configuration, Formatting.Indented);
var appParamId = API.UploadAppParam(appParamName, appParamsString);
appParamIds.Add(new AppParam
{
id = appParamId,
name = appParamName,
num_instances = 1
});
EditorUtility.DisplayProgressBar(
"Unity Simulation Run",
$"Uploading app-param-ids for instances: {i + 1}/{m_InstanceCountField.value}",
progressStart + progressIncrement * i);
}
id = appParamId,
name = appParamName,
num_instances = m_InstanceCountField.value
});
EditorUtility.DisplayProgressBar("Unity Simulation Run", "Uploading build...", 0.1f);
// Upload build
Debug.Log("Uploading build...");
cancellationTokenSource: cancellationTokenSource);
Debug.Log($"Build upload complete: build id {buildId}");
var appParams = GenerateAppParamIds(token, 0.1f, 0.9f);
null, null,
cancellationTokenSource,
progress =>
{
EditorUtility.DisplayProgressBar(
"Unity Simulation Run", "Uploading build...", progress * 0.90f);
});
Debug.Log("Run cancelled");
Debug.Log("The build upload process has been cancelled. Aborting Unity Simulation launch.");
Debug.Log($"Generated app-param ids: {appParams.Count}");
EditorUtility.DisplayProgressBar("Unity Simulation Run", "Uploading run definition...", 0.9f);
// Generate and upload app-params
EditorUtility.DisplayProgressBar("Unity Simulation Run", "Uploading app-params...", 0.90f);
var appParams = UploadAppParam();
// Upload run definition
EditorUtility.DisplayProgressBar("Unity Simulation Run", "Uploading run definition...", 0.95f);
var runDefinitionId = API.UploadRunDefinition(new RunDefinition
{
app_params = appParams.ToArray(),

});
Debug.Log($"Run definition upload complete: run definition id {runDefinitionId}");
EditorUtility.DisplayProgressBar("Unity Simulation Run", "Executing run...", 0.95f);
// Execute run
EditorUtility.DisplayProgressBar("Unity Simulation Run", "Executing run...", 1f);
cancellationTokenSource.Dispose();
Debug.Log($"Executing run: {run.executionId}");
// Cleanup
PlayerPrefs.SetString("SimWindow/prevExecutionId", run.executionId);
m_PrevExecutionId.text = $"Execution ID: {run.executionId}";
}

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


protected override void OnStart()
{
if (Configuration.Instance.IsSimulationRunningInCloud())
{
constants.instanceIndex = int.Parse(Configuration.Instance.GetInstanceId()) - 1;
}
else
base.OnStart();
currentIteration = constants.instanceIndex;

正在加载...
取消
保存