예제 #1
0
            public override void Action(int instanceId, string pathName, string resourceFile)
            {
                var fileName = Path.GetFileNameWithoutExtension(pathName);
                var go       = new GameObject(fileName, typeof(MARSEnvironmentSettings));
                var xRayGo   = new GameObject(k_XRayLabel, typeof(XRayRegion));

                xRayGo.transform.parent = go.transform;
                PrefabUtility.SaveAsPrefabAsset(go, pathName);
                var o = AssetDatabase.LoadAssetAtPath <UnityObject>(pathName);

                MarsEnvironmentUtils.EnsureAssetHasEnvironmentLabel(o);
                ProjectWindowUtil.ShowCreatedAsset(o);
                UnityObjectUtils.Destroy(go);
            }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            var settings               = target as MARSEnvironmentSettings;
            var environmentObject      = settings.gameObject;
            var environmentPrefabStage = PrefabStageUtility.GetPrefabStage(environmentObject);

            var prefabAssetPath = environmentPrefabStage != null ?
#if UNITY_2020_1_OR_NEWER
                                  environmentPrefabStage.assetPath :
#else
                                  environmentPrefabStage.prefabAssetPath:
#endif
                                  PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(settings);

            var hasPrefabAsset     = !string.IsNullOrEmpty(prefabAssetPath);
            var environmentAsset   = hasPrefabAsset ? AssetDatabase.LoadAssetAtPath <Object>(prefabAssetPath) : null;
            var environmentManager = MARSEnvironmentManager.instance;

            using (new EditorGUI.DisabledScope(!hasPrefabAsset || MarsEnvironmentUtils.IsDefaultEnvironment(environmentAsset) ||
                                               environmentManager.EnvironmentPrefabPaths.Contains(prefabAssetPath)))
            {
                if (GUILayout.Button(k_AddToSyntheticEnvironmentsContent))
                {
                    MarsEnvironmentUtils.EnsureAssetHasEnvironmentLabel(environmentAsset);
                    EditorUtility.SetDirty(environmentAsset);
                    environmentManager.UpdateSimulatedEnvironmentCandidates();
                }
            }

            EditorGUILayout.Separator();

            var sceneView = SceneView.lastActiveSceneView;
            var isSimView = false;

            if (sceneView != null)
            {
                isSimView = sceneView is SimulationView;
            }

            using (var change = new EditorGUI.ChangeCheckScope())
            {
                m_EnvironmentInfoProperty.isExpanded = EditorGUILayout.Foldout(m_EnvironmentInfoProperty.isExpanded,
                                                                               m_EnvironmentInfoProperty.displayName, true);

                if (m_EnvironmentInfoProperty.isExpanded)
                {
                    using (new EditorGUI.IndentLevelScope())
                    {
                        EditorGUILayout.PropertyField(m_DefaultCameraWorldPoseProperty, true);
                        EditorGUILayout.PropertyField(m_DefaultCameraPivotProperty);
                        EditorGUILayout.PropertyField(m_DefaultCameraSizeProperty);
                        using (new EditorGUI.DisabledScope(sceneView == null))
                        {
                            if (GUILayout.Button(k_SaveViewContent))
                            {
                                settings.SetDefaultEnvironmentCamera(sceneView, isSimView);
                                EditorSceneManager.MarkSceneDirty(settings.gameObject.scene);
                            }
                        }

                        EditorGUILayout.PropertyField(m_SimulationStartingPoseProperty, true);
                        EditorGUILayout.PropertyField(m_EnvironmentBoundsProperty);
                        using (new EditorGUI.DisabledScope(sceneView == null))
                        {
                            if (GUILayout.Button(k_SaveSimStartingPoseContent))
                            {
                                settings.SetSimulationStartingPose(sceneView.camera.transform.GetWorldPose(), isSimView);
                                EditorSceneManager.MarkSceneDirty(settings.gameObject.scene);
                            }
                        }
                    }
                }

                EditorGUILayout.PropertyField(m_RenderSettingsProperty, true);

#if INCLUDE_POST_PROCESSING
                EditorGUILayout.PropertyField(m_PostProcessProfileProperty, true);
#endif

                var simulationSettings        = SimulationSettings.instance;
                var currentEnvironmentPath    = AssetDatabase.GetAssetPath(simulationSettings.EnvironmentPrefab);
                var environmentIsInSimulation = SimulationSceneModule.UsingSimulation &&
                                                simulationSettings.EnvironmentMode == EnvironmentMode.Synthetic &&
                                                environmentPrefabStage != null &&
#if UNITY_2020_1_OR_NEWER
                                                currentEnvironmentPath == environmentPrefabStage.assetPath;
#else
                                                currentEnvironmentPath == environmentPrefabStage.prefabAssetPath;
#endif

                if (!environmentIsInSimulation)
                {
                    EditorGUILayout.HelpBox(
                        "Planes from simulation can only be saved to this environment if it is the active simulation environment.",
                        MessageType.Info);
                }

                using (new EditorGUI.DisabledScope(!environmentIsInSimulation))
                {
                    if (GUILayout.Button(k_SavePlanesFromSimContent))
                    {
                        ModuleLoaderCore.instance.GetModule <PlaneGenerationModule>().SavePlanesFromSimulation(environmentObject);
                    }
                }

                if (change.changed)
                {
                    serializedObject.ApplyModifiedProperties();
                }
            }
        }