using System; using System.Collections.Generic; using System.IO; using System.Threading; using System.Threading.Tasks; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Unity.Simulation.Client; using UnityEditor.Build.Reporting; using UnityEditor.UIElements; using UnityEngine; using UnityEngine.Perception.Randomization.Samplers; using UnityEngine.Perception.Randomization.Scenarios; using UnityEngine.SceneManagement; using UnityEngine.UIElements; using ZipUtility; using Random = System.Random; namespace UnityEditor.Perception.Randomization { class RunInUnitySimulationWindow : EditorWindow { string m_BuildDirectory; string m_BuildZipPath; SysParamDefinition[] m_SysParamDefinitions; IntegerField m_InstanceCountField; TextField m_RunNameField; IntegerField m_TotalIterationsField; UIntField m_RandomSeedField; ToolbarMenu m_SysParamMenu; int m_SysParamIndex; ObjectField m_ScenarioConfigField; Button m_RunButton; Label m_PrevRunNameLabel; Label m_ProjectIdLabel; Label m_PrevExecutionIdLabel; Label m_PrevRandomSeedLabel; RunParameters m_RunParameters; [MenuItem("Window/Run in Unity Simulation")] static void ShowWindow() { var window = GetWindow(); window.titleContent = new GUIContent("Run In Unity Simulation"); window.minSize = new Vector2(250, 50); window.Show(); } void OnEnable() { m_BuildDirectory = Application.dataPath + "/../Build"; Project.Activate(); Project.clientReadyStateChanged += CreateEstablishingConnectionUI; CreateEstablishingConnectionUI(Project.projectIdState); } void OnFocus() { Application.runInBackground = true; } void OnLostFocus() { Application.runInBackground = false; } void CreateEstablishingConnectionUI(Project.State state) { rootVisualElement.Clear(); if (Project.projectIdState == Project.State.Pending) { var waitingText = new TextElement(); waitingText.text = "Waiting for connection to Unity Cloud..."; rootVisualElement.Add(waitingText); } else if (Project.projectIdState == Project.State.Invalid) { var waitingText = new TextElement(); waitingText.text = "The current project must be associated with a valid Unity Cloud project " + "to run in Unity Simulation"; rootVisualElement.Add(waitingText); } else { CreateRunInUnitySimulationUI(); } } void CreateRunInUnitySimulationUI() { var root = rootVisualElement; AssetDatabase.LoadAssetAtPath( $"{StaticData.uxmlDir}/RunInUnitySimulationWindow.uxml").CloneTree(root); m_RunNameField = root.Q("run-name"); m_TotalIterationsField = root.Q("total-iterations"); m_InstanceCountField = root.Q("instance-count"); m_RandomSeedField = root.Q("random-seed"); var randomizeSeedButton = root.Q