async void RunInUnitySimulation() { m_RunParameters = new RunParameters { runName = m_RunNameField.value, totalIterations = m_TotalIterationsField.value, instanceCount = m_InstanceCountField.value, sysParamIndex = m_SysParamIndex, scenarioConfig = (TextAsset)m_ScenarioConfigField.value, currentOpenScenePath = SceneManager.GetSceneAt(0).path, currentScenario = FindObjectOfType <ScenarioBase>() }; var runGuid = Guid.NewGuid(); PerceptionEditorAnalytics.ReportRunInUnitySimulationStarted( runGuid, m_RunParameters.totalIterations, m_RunParameters.instanceCount, null); try { ValidateSettings(); CreateLinuxBuildAndZip(); await StartUnitySimulationRun(runGuid); } catch (Exception e) { EditorUtility.ClearProgressBar(); PerceptionEditorAnalytics.ReportRunInUnitySimulationFailed(runGuid, e.Message); throw; } }
async Task StartUnitySimulationRun(Guid runGuid) { EditorUtility.DisplayProgressBar("Unity Simulation Run", "Uploading build...", 0.1f); m_RunButton.SetEnabled(false); var cancellationTokenSource = new CancellationTokenSource(); var token = cancellationTokenSource.Token; Debug.Log("Uploading build..."); var buildId = await API.UploadBuildAsync( m_RunNameField.value, m_BuildZipPath, cancellationTokenSource : cancellationTokenSource); Debug.Log($"Build upload complete: build id {buildId}"); var appParams = GenerateAppParamIds(token, 0.1f, 0.9f); if (token.IsCancellationRequested) { Debug.Log("Run cancelled"); EditorUtility.ClearProgressBar(); return; } Debug.Log($"Generated app-param ids: {appParams.Count}"); EditorUtility.DisplayProgressBar("Unity Simulation Run", "Uploading run definition...", 0.9f); var runDefinitionId = API.UploadRunDefinition(new RunDefinition { app_params = appParams.ToArray(), name = m_RunNameField.value, sys_param_id = m_SysParam.id, build_id = buildId }); Debug.Log($"Run definition upload complete: run definition id {runDefinitionId}"); EditorUtility.DisplayProgressBar("Unity Simulation Run", "Executing run...", 0.95f); var run = Run.CreateFromDefinitionId(runDefinitionId); run.Execute(); cancellationTokenSource.Dispose(); Debug.Log($"Executing run: {run.executionId}"); m_RunButton.SetEnabled(true); EditorUtility.ClearProgressBar(); PerceptionEditorAnalytics.ReportRunInUnitySimulationSucceeded(runGuid, run.executionId); }
async void RunInUnitySimulation() { #if PLATFORM_CLOUD_RENDERING if (!m_SysParamDefinitions[m_SysParamIndex].description.Contains(m_SupportedGPUString)) { EditorUtility.DisplayDialog("Unsupported Sysparam", "The current selection of the Sysparam " + m_SysParamDefinitions[m_SysParamIndex].description + " is not supported by this build target. Please select a sysparam with GPU", "Ok"); return; } #endif m_RunParameters = new RunParameters { runName = m_RunNameField.value, totalIterations = m_TotalIterationsField.value, instanceCount = m_InstanceCountField.value, randomSeed = m_RandomSeedField.value, sysParamIndex = m_SysParamIndex, scenarioConfig = (TextAsset)m_ScenarioConfigField.value, currentOpenScenePath = SceneManager.GetSceneAt(0).path, currentScenario = FindObjectOfType <ScenarioBase>() }; var runGuid = Guid.NewGuid(); PerceptionEditorAnalytics.ReportRunInUnitySimulationStarted( runGuid, m_RunParameters.totalIterations, m_RunParameters.instanceCount, null); try { ValidateSettings(); CreateLinuxBuildAndZip(); await StartUnitySimulationRun(runGuid); } catch (Exception e) { EditorUtility.ClearProgressBar(); PerceptionEditorAnalytics.ReportRunInUnitySimulationFailed(runGuid, e.Message); throw; } }
async void RunInUnitySimulation() { var runGuid = Guid.NewGuid(); PerceptionEditorAnalytics.ReportRunInUnitySimulationStarted( runGuid, m_TotalIterationsField.value, m_InstanceCountField.value, null); try { ValidateSettings(); CreateLinuxBuildAndZip(); await StartUnitySimulationRun(runGuid); } catch (Exception e) { EditorUtility.ClearProgressBar(); PerceptionEditorAnalytics.ReportRunInUnitySimulationFailed(runGuid, e.Message); throw; } }
async Task StartUnitySimulationRun(Guid runGuid) { 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(); // Upload run definition EditorUtility.DisplayProgressBar("Unity Simulation Run", "Uploading run definition...", 0.95f); var runDefinitionId = API.UploadRunDefinition(new RunDefinition { app_params = appParams.ToArray(), name = m_RunParameters.runName, sys_param_id = m_SysParamDefinitions[m_RunParameters.sysParamIndex].id, build_id = buildId }); // Execute run EditorUtility.DisplayProgressBar("Unity Simulation Run", "Executing run...", 1f); var run = Run.CreateFromDefinitionId(runDefinitionId); run.Execute(); // Cleanup m_RunButton.SetEnabled(true); EditorUtility.ClearProgressBar(); PerceptionEditorAnalytics.ReportRunInUnitySimulationSucceeded(runGuid, run.executionId); // Set new Player Preferences PlayerPrefs.SetString("SimWindow/runName", m_RunParameters.runName); PlayerPrefs.SetString("SimWindow/prevExecutionId", run.executionId); PlayerPrefs.SetInt("SimWindow/totalIterations", m_RunParameters.totalIterations); PlayerPrefs.SetInt("SimWindow/instanceCount", m_RunParameters.instanceCount); PlayerPrefs.SetInt("SimWindow/sysParamIndex", m_RunParameters.sysParamIndex); PlayerPrefs.SetString("SimWindow/scenarioConfig", m_RunParameters.scenarioConfig != null ? m_RunParameters.scenarioConfigAssetPath : string.Empty); SetFieldsFromPlayerPreferences(); }