浏览代码

need to fix async await stuff

/usim-randomization
Steven Leal 4 年前
当前提交
2753d943
共有 4 个文件被更改,包括 120 次插入47 次删除
  1. 83
      com.unity.perception/Editor/Randomization/RunInUSimWindow.cs
  2. 75
      com.unity.perception/Editor/Randomization/Uxml/RunInUSimWindow.uxml
  3. 6
      com.unity.perception/Editor/Randomization/Uss/RunInUSimStyles.uss
  4. 3
      com.unity.perception/Editor/Randomization/Uss/RunInUSimStyles.uss.meta

83
com.unity.perception/Editor/Randomization/RunInUSimWindow.cs


using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Boo.Lang.Runtime;
using Unity.Simulation.Client;
using UnityEditor;

{
string m_BuildZipPath;
SysParamDefinition m_SysParam;
float m_LastRunStatusPing;
VisualElement m_RunStatusContainer;
Button m_RunButton;
TextElement m_NumNotRun;
TextElement m_NumFailures;

CreateEstablishingConnectionUI(Project.projectIdState);
}
void OnFocus()
{
Application.runInBackground = true;
}
void OnLostFocus()
{
Application.runInBackground = false;
}
void CreateEstablishingConnectionUI(Project.State state)
{
rootVisualElement.Clear();

m_ScenarioField = root.Q<ObjectField>("scenario");
m_ScenarioField.objectType = typeof(ScenarioBase);
m_RunStatusContainer = root.Q<VisualElement>("run-status-container");
m_RunExecutionIdField = root.Q<TextField>("run-execution-id");
SetViewDataKey(m_RunExecutionIdField);

m_NumSuccess = root.Q<TextElement>("num-success");
m_RunState = root.Q<TextElement>("run-state");
var summarizeExecutionButton = root.Q<Button>("summarize-execution");
summarizeExecutionButton.clicked += SummarizeExecution;
var downloadManifestButton = root.Q<Button>("download-manifest");
downloadManifestButton.clicked += DownloadManifest;
var sysParamDefinitions = API.GetSysParams();
var sysParamMenu = root.Q<ToolbarMenu>("sys-param");

m_SysParam = sysParamDefinitions[0];
var runButton = root.Q<Button>("run-button");
runButton.clicked += RunInUSim;
m_RunButton = root.Q<Button>("run-button");
m_RunButton.clicked += RunInUSim;
void SummarizeExecution()
// void ToggleVisibility(VisualElement element, bool visible)
// {
// Debug.Log(visible);
// element.style.display = visible
// ? new StyleEnum<DisplayStyle>(DisplayStyle.Flex)
// : new StyleEnum<DisplayStyle>(DisplayStyle.None);
// }
void OnInspectorUpdate()
{
if (!string.IsNullOrEmpty(m_RunExecutionIdField.value) &&
m_LastRunStatusPing < Time.realtimeSinceStartup - 3f)
{
m_LastRunStatusPing = Time.realtimeSinceStartup;
UpdateRunStatus();
}
}
void UpdateRunStatus()
Debug.Log(summary.state.code);
m_RunState.text = summary.state.ToString();
m_RunState.text = summary.state.code;
}
void DownloadManifest()
{
if (!string.IsNullOrEmpty(m_RunExecutionIdField.value))
{
var manifest = API.GetManifest(m_RunExecutionIdField.value);
var manifestFilePath = EditorUtility.SaveFilePanel("Save Manifest", Application.dataPath, "manifest", "csv");
var lines = new string[manifest.Count + 1];
lines[0] = "run_execution_id,app_param_id,instance_id,attempt_id,file_name,download_uri";
var i = 1;
foreach (var pair in manifest)
{
var e = pair.Value;
lines[i++] = $"{e.executionId},{e.appParamId},{e.instanceId},{e.attemptId},{e.fileName},{e.downloadUri}";
}
File.WriteAllLines(manifestFilePath, lines);
}
void RunInUSim()
async void RunInUSim()
StartUSimRun();
var run = await StartUSimRun();
m_RunExecutionIdField.value = run.executionId;
}
void ValidateSettings()

void CreateLinuxBuildAndZip()
{
// Ensure that scenario serialization is enabled
var scenario = (USimScenario)m_ScenarioField.value;
scenario.deserializeOnStart = true;
// Create build directory
var pathToProjectBuild = Application.dataPath + "/../" + "Build/";
if (!Directory.Exists(pathToProjectBuild + m_RunNameField.value))

return appParamIds;
}
async void StartUSimRun()
async Task<Run> StartUSimRun()
m_RunButton.SetEnabled(false);
var cancellationTokenSource = new CancellationTokenSource();
var token = cancellationTokenSource.Token;

m_BuildZipPath,
cancellationTokenSource: cancellationTokenSource);
return;
return null;
Debug.Log($"Generated app-param ids: {appParams.Count}");
var runDefinitionId = API.UploadRunDefinition(new RunDefinition

var run = Run.CreateFromDefinitionId(runDefinitionId);
run.Execute();
m_RunExecutionIdField.value = run.executionId;
Debug.Log("Executed run");
Debug.Log($"Executing run: {run.executionId}");
return run;
}
}
}

75
com.unity.perception/Editor/Randomization/Uxml/RunInUSimWindow.uxml


<UXML xmlns="UnityEngine.UIElements" xmlns:editor="UnityEditor.UIElements" xmlns:randEditor="UnityEngine.Perception.Randomization.Editor">
<VisualElement>
<TextField name="run-name" label="Run Name"/>
<randEditor:PositiveIntegerField name="total-iterations" label="Total Iterations"/>
<randEditor:PositiveIntegerField name="instance-count" label="Instance Count" max-value="10000"/>
<editor:ObjectField name="main-scene" label="Main Scene" allow-scene-objects="false"/>
<editor:ObjectField name="scenario" label="Scenario"/>
<VisualElement class="unity-base-field">
<Label text="USim worker config" class="unity-base-field__label"/>
<editor:ToolbarMenu name="sys-param" class="unity-base-field__input" style="border-width: 1px;"/>
</VisualElement>
<VisualElement style="align-items: center;">
<Button name="run-button" text="Build and Run" style="margin-top: 20px; padding: 2 20; font-size: 13px;"/>
<Style src="../Uss/RunInUSimStyles.uss"/>
<VisualElement class="dark-viewport" style="margin-bottom: 20px;">
<VisualElement style="">
<TextField name="run-name" label="Run Name"/>
<randEditor:PositiveIntegerField name="total-iterations" label="Total Iterations"/>
<randEditor:PositiveIntegerField name="instance-count" label="Instance Count" max-value="10000"/>
<editor:ObjectField name="main-scene" label="Main Scene" allow-scene-objects="false"/>
<editor:ObjectField name="scenario" label="Scenario"/>
<VisualElement class="unity-base-field">
<Label text="USim worker config" class="unity-base-field__label"/>
<editor:ToolbarMenu name="sys-param" class="unity-base-field__input" style="border-width: 1px;"/>
</VisualElement>
<VisualElement style="align-items: center;">
<Button name="run-button" text="Build and Run" style="margin: 10px; padding: 2 20; font-size: 13px;"/>
</VisualElement>
</VisualElement>
<TextField name="run-execution-id" label="Run Execution ID" style="margin-top: 40px;"/>
<VisualElement class="unity-base-field">
<Label text="Not Run" class="unity-base-field__label"/>
<TextElement name="num-not-run" text="0"/>
</VisualElement>
<VisualElement class="unity-base-field">
<Label text="Failed" class="unity-base-field__label"/>
<TextElement name="num-failures" text="0"/>
</VisualElement>
<VisualElement class="unity-base-field">
<Label text="In Progress" class="unity-base-field__label"/>
<TextElement name="num-in-progress" text="0"/>
</VisualElement>
<VisualElement class="unity-base-field">
<Label text="Succeeded" class="unity-base-field__label"/>
<TextElement name="num-success" text="0"/>
</VisualElement>
<VisualElement class="unity-base-field">
<Label text="State" class="unity-base-field__label"/>
<TextElement name="run-state" text="default"/>
</VisualElement>
<VisualElement style="align-items: center;">
<Button name="summarize-execution" text="Summarize Execution" style="margin-top: 20px; padding: 2 20; font-size: 13px;"/>
<VisualElement name="run-status-container" class="dark-viewport">
<TextField name="run-execution-id" label="Run Execution ID"/>
<VisualElement class="unity-base-field">
<Label text="Not Run" class="unity-base-field__label"/>
<TextElement name="num-not-run"/>
</VisualElement>
<VisualElement class="unity-base-field">
<Label text="Failed" class="unity-base-field__label"/>
<TextElement name="num-failures"/>
</VisualElement>
<VisualElement class="unity-base-field">
<Label text="In Progress" class="unity-base-field__label"/>
<TextElement name="num-in-progress"/>
</VisualElement>
<VisualElement class="unity-base-field">
<Label text="Succeeded" class="unity-base-field__label"/>
<TextElement name="num-success"/>
</VisualElement>
<VisualElement class="unity-base-field">
<Label text="State" class="unity-base-field__label"/>
<TextElement name="run-state"/>
</VisualElement>
<VisualElement style="align-items: center;">
<Button name="download-manifest" text="Download Manifest" style="margin: 10px; padding: 2 20; font-size: 13px;"/>
</VisualElement>
</VisualElement>
</VisualElement>
</UXML>

6
com.unity.perception/Editor/Randomization/Uss/RunInUSimStyles.uss


.dark-viewport {
border-radius: 5px;
background-color: #191919;
padding: 2px;
margin: 2px;
}

3
com.unity.perception/Editor/Randomization/Uss/RunInUSimStyles.uss.meta


fileFormatVersion: 2
guid: 8ee39ab9c50a4f5db26869a0e40a54fa
timeCreated: 1597718729
正在加载...
取消
保存