Ejemplo n.º 1
0
        private void DrawImporterSelectionPopup()
        {
            if (m_AvailableImporterTypes.Count < 2)
            {
                return;
            }
            var mixed = EditorGUI.showMixedValue;

            EditorGUI.showMixedValue = m_SelectedImporterType == k_MultipleSelectedImporterTypes;
            GUILayout.Label(Styles.ImporterSelection);
            var newSelection = EditorGUILayout.Popup(m_SelectedImporterType, m_AvailableImporterTypesOptions);

            if (newSelection != m_SelectedImporterType)
            {
                if (CheckForApplyOnClose(false))
                {
                    // TODO : this should probably be handled by the AssetDatabase code when restoring selection?
                    m_SelectedAssetsPath         = assetTargets.Select(AssetDatabase.GetAssetPath).ToList();
                    EditorApplication.delayCall += () =>
                    {
                        var loaded = m_SelectedAssetsPath.Select(AssetDatabase.LoadMainAssetAtPath);
                        if (m_HasInspectorBeenSeenLocked)
                        {
                            m_Inspector.SetObjectsLocked(loaded.ToList());
                        }
                        else
                        {
                            Selection.objects = loaded.ToArray();
                        }
                    };
                    AssetDatabase.StartAssetEditing();

                    foreach (var importer in targets.Cast <AssetImporter>())
                    {
                        Undo.RegisterImporterUndo(importer.assetPath, string.Empty);
                        //When selecting an override, set it as an override, when selecting the default importer, clear the override
                        if (m_AvailableImporterTypes[newSelection] != AssetDatabase.GetDefaultImporter(importer.assetPath))
                        {
                            AssetDatabase.SetImporterOverrideInternal(importer.assetPath, m_AvailableImporterTypes[newSelection]);
                        }
                        else
                        {
                            AssetDatabase.ClearImporterOverride(importer.assetPath);
                        }
                    }

                    AssetDatabase.StopAssetEditing();
                    GUIUtility.ExitGUI();
                }
            }
            EditorGUI.showMixedValue = mixed;
        }