浏览代码

Adding support for selecting build id and build zip to run in usim window

/h-i
Jon Hogins 4 年前
当前提交
938ebf2e
共有 2 个文件被更改,包括 129 次插入28 次删除
  1. 149
      com.unity.perception/Editor/Randomization/Editors/RunInUnitySimulationWindow.cs
  2. 8
      com.unity.perception/Editor/Randomization/Uxml/RunInUnitySimulationWindow.uxml

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


Label m_PrevRandomSeedLabel;
RunParameters m_RunParameters;
EnumField m_BuildTypeMenu;
VisualElement m_BuildSelectControls;
TextField m_BuildPathField;
TextField m_SelectedBuildPathTextField;
TextField m_BuildIdField;
[MenuItem("Window/Run in Unity Simulation")]
static void ShowWindow()
{

}
}
enum BuildIdKind
{
BuildPlayer,
ExistingBuildID,
ExistingBuildZip
}
void CreateRunInUnitySimulationUI()
{
var root = rootVisualElement;

copyPrevRandomSeedButton.clicked += () =>
EditorGUIUtility.systemCopyBuffer = PlayerPrefs.GetString("SimWindow/prevRandomSeed");
m_BuildTypeMenu = root.Q<EnumField>("build-type-menu");
m_BuildTypeMenu.Init(BuildIdKind.BuildPlayer);
m_BuildTypeMenu.RegisterValueChangedCallback(evt => { UpdateBuildIdElements((BuildIdKind) evt.newValue); });
m_BuildSelectControls = root.Q<VisualElement>("build-select-controls");
m_SelectedBuildPathTextField = root.Q<TextField>("selected-build-path");
m_SelectedBuildPathTextField.isReadOnly = true;
m_BuildIdField = root.Q<TextField>("build-id");
UpdateBuildIdElements((BuildIdKind) m_BuildTypeMenu.value);
var selectBuildButton = root.Q<Button>("select-build-file-button");
selectBuildButton.clicked += () =>
{
var path = EditorUtility.OpenFilePanel("Select build ZIP file", "", "zip");
if (path.Length != 0)
{
m_SelectedBuildPathTextField.value = path;
}
};
private void UpdateBuildIdElements(BuildIdKind buildIdKind)
{
switch (buildIdKind)
{
case BuildIdKind.ExistingBuildID:
m_BuildSelectControls.SetEnabled(false);
m_BuildIdField.SetEnabled(true);
break;
case BuildIdKind.ExistingBuildZip:
m_BuildSelectControls.SetEnabled(true);
m_BuildIdField.SetEnabled(false);
break;
case BuildIdKind.BuildPlayer:
m_BuildSelectControls.SetEnabled(false);
m_BuildIdField.SetEnabled(false);
break;
}
}
void SetFieldsFromPlayerPreferences()
{
m_RunNameField.value = IncrementRunName(PlayerPrefs.GetString("SimWindow/runName"));

null);
try
{
m_RunButton.SetEnabled(false);
// Upload build
var cancellationTokenSource = new CancellationTokenSource();
var token = cancellationTokenSource.Token;
CreateLinuxBuildAndZip();
await StartUnitySimulationRun(runGuid);
string buildId = null;
var buildIdKind = (BuildIdKind)m_BuildTypeMenu.value;
switch (buildIdKind)
{
case BuildIdKind.BuildPlayer:
CreateLinuxBuildAndZip();
buildId = await UploadBuild(cancellationTokenSource, token);
break;
case BuildIdKind.ExistingBuildZip:
m_BuildZipPath = m_BuildPathField.value;
buildId = await UploadBuild(cancellationTokenSource, token);
break;
case BuildIdKind.ExistingBuildID:
buildId = m_BuildIdField.value;
break;
}
if (buildId == null)
return;
await StartUnitySimulationRun(runGuid, buildId);
EditorUtility.ClearProgressBar();
finally
{
m_RunButton.SetEnabled(true);
EditorUtility.ClearProgressBar();
}
}
private async Task<string> UploadBuild(CancellationTokenSource cancellationTokenSource, CancellationToken token)
{
var buildId = await API.UploadBuildAsync(
m_RunParameters.runName,
m_BuildZipPath,
null, null,
cancellationTokenSource,
progress =>
{
EditorUtility.DisplayProgressBar(
"Unity Simulation Run", "Uploading build...", progress * 0.90f);
});
if (token.IsCancellationRequested)
{
Debug.Log("The build upload process has been cancelled. Aborting Unity Simulation launch.");
EditorUtility.ClearProgressBar();
return null;
}
return buildId;
}
void ValidateSettings()

Path.GetExtension(m_RunParameters.scenarioConfigAssetPath) != ".json")
throw new NotSupportedException(
"Scenario configuration must be a JSON text asset");
if (((BuildIdKind)m_BuildTypeMenu.value) == BuildIdKind.ExistingBuildZip &&
!File.Exists(m_SelectedBuildPathTextField.value))
{
throw new NotSupportedException(
"Selected build path does not exist");
}
if (((BuildIdKind)m_BuildTypeMenu.value) == BuildIdKind.ExistingBuildID &&
String.IsNullOrEmpty(m_BuildIdField.value))
{
throw new NotSupportedException("Empty Build ID");
}
}
void CreateLinuxBuildAndZip()

return appParamIds;
}
async Task StartUnitySimulationRun(Guid runGuid)
async Task StartUnitySimulationRun(Guid runGuid, string buildId)
m_RunButton.SetEnabled(false);
// Upload build
var cancellationTokenSource = new CancellationTokenSource();
var token = cancellationTokenSource.Token;
var buildId = await API.UploadBuildAsync(
m_RunParameters.runName,
m_BuildZipPath,
null, null,
cancellationTokenSource,
progress =>
{
EditorUtility.DisplayProgressBar(
"Unity Simulation Run", "Uploading build...", progress * 0.90f);
});
if (token.IsCancellationRequested)
{
Debug.Log("The build upload process has been cancelled. Aborting Unity Simulation launch.");
EditorUtility.ClearProgressBar();
return;
}
// Generate and upload app-params
EditorUtility.DisplayProgressBar("Unity Simulation Run", "Uploading app-params...", 0.90f);
var appParams = UploadAppParam();

run.Execute();
// Cleanup
m_RunButton.SetEnabled(true);
EditorUtility.ClearProgressBar();
PerceptionEditorAnalytics.ReportRunInUnitySimulationSucceeded(runGuid, run.executionId);
// Set new Player Preferences

8
com.unity.perception/Editor/Randomization/Uxml/RunInUnitySimulationWindow.uxml


tooltip="Selects a scenario JSON configuration to load during the run.
You can leave this option blank to use the scenario settings currently configured in the editor."/>
<editor:EnumField name="build-type-menu" label="Build type" style="flex-grow:1; margin:0; border-width: 1px;"/>
<VisualElement name="build-select-controls" style="margin-bottom: 0; flex-direction: row; justify-content: space-between; align-items: center;">
<TextField name="selected-build-path" label="Build Zip Path" style="flex-grow: 1; flex-shrink: 1;" />
<Button name="select-build-file-button" text="Browse..." style="margin: 0; align-items: flex-end; margin-top: 0; width: 70px;" />
</VisualElement>
<TextField name="build-id" label="Build ID" style="flex-grow: 1; flex-shrink: 1;" />
<VisualElement style="align-items: center; margin-top: 8px;">
<Button name="run-button" text="Build and Run" style="margin: 10px; padding: 2 20; font-size: 13px;"/>
</VisualElement>

正在加载...
取消
保存