예제 #1
0
        protected override void CreateCustomUI()
        {
            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(new GUIContent(
                                           "Prefab Name",
                                           "Filename to save prefab to."), GUILayout.Width(LabelWidth - TextFieldAlignOffset));

            EditorGUI.BeginDisabledGroup(DisableNameSelection);
            // Show the export name with an uneditable ".prefab" at the end
            //-------------------------------------
            EditorGUILayout.BeginVertical();
            EditorGUILayout.BeginHorizontal(EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight));
            EditorGUI.indentLevel--;
            // continually resize to contents
            var textFieldSize = NameTextFieldStyle.CalcSize(new GUIContent(m_prefabFileName));

            m_prefabFileName = EditorGUILayout.TextField(m_prefabFileName, NameTextFieldStyle, GUILayout.Width(textFieldSize.x + 5), GUILayout.MinWidth(5));
            m_prefabFileName = ModelExporter.ConvertToValidFilename(m_prefabFileName);

            EditorGUILayout.LabelField("<color=#808080ff>.prefab</color>", FbxExtLabelStyle, GUILayout.Width(m_prefabExtLabelWidth));
            EditorGUI.indentLevel++;

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();
            //-----------------------------------
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(new GUIContent(
                                           "Prefab Path",
                                           "Relative path for saving FBX Prefab Variants."), GUILayout.Width(LabelWidth - FieldOffset));

            var pathLabels = ExportSettings.GetRelativePrefabSavePaths();

            ExportSettings.instance.SelectedPrefabPath = EditorGUILayout.Popup(ExportSettings.instance.SelectedPrefabPath, pathLabels, GUILayout.MinWidth(SelectableLabelMinWidth));

            if (GUILayout.Button(new GUIContent("...", "Browse to a new location to save prefab to"), EditorStyles.miniButton, GUILayout.Width(BrowseButtonWidth)))
            {
                string initialPath = Application.dataPath;

                string fullPath = EditorUtility.OpenFolderPanel(
                    "Select FBX Prefab Variant Save Path", initialPath, null
                    );

                // Unless the user canceled, make sure they chose something in the Assets folder.
                if (!string.IsNullOrEmpty(fullPath))
                {
                    var relativePath = ExportSettings.ConvertToAssetRelativePath(fullPath);
                    if (string.IsNullOrEmpty(relativePath))
                    {
                        Debug.LogWarning("Please select a location in the Assets folder");
                    }
                    else
                    {
                        ExportSettings.AddPrefabSavePath(relativePath);

                        // Make sure focus is removed from the selectable label
                        // otherwise it won't update
                        GUIUtility.hotControl      = 0;
                        GUIUtility.keyboardControl = 0;
                    }
                }
            }
            GUILayout.EndHorizontal();
        }
        // -------------------------------------------------------------------------------------

        protected void OnGUI()
        {
            // Increasing the label width so that none of the text gets cut off
            EditorGUIUtility.labelWidth = LabelWidth;

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            #if UNITY_2018_1_OR_NEWER
            if (EditorGUILayout.DropdownButton(presetIcon, FocusType.Keyboard, presetIconButton))
            {
                ShowPresetReceiver();
            }
            #endif

            GUILayout.EndHorizontal();

            EditorGUILayout.LabelField("Naming");
            EditorGUI.indentLevel++;

            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(new GUIContent(
                                           "Export Name",
                                           "Filename to save model to."), GUILayout.Width(LabelWidth - TextFieldAlignOffset));

            EditorGUI.BeginDisabledGroup(DisableNameSelection);
            // Show the export name with an uneditable ".fbx" at the end
            //-------------------------------------
            EditorGUILayout.BeginVertical();
            EditorGUILayout.BeginHorizontal(EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight));
            EditorGUI.indentLevel--;
            // continually resize to contents
            var textFieldSize = NameTextFieldStyle.CalcSize(new GUIContent(ExportFileName));
            ExportFileName = EditorGUILayout.TextField(ExportFileName, NameTextFieldStyle, GUILayout.Width(textFieldSize.x + 5), GUILayout.MinWidth(5));
            ExportFileName = ModelExporter.ConvertToValidFilename(ExportFileName);

            EditorGUILayout.LabelField("<color=#808080ff>.fbx</color>", FbxExtLabelStyle, GUILayout.Width(FbxExtLabelWidth));
            EditorGUI.indentLevel++;

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();
            //-----------------------------------
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(new GUIContent(
                                           "Export Path",
                                           "Location where the FBX will be saved."), GUILayout.Width(LabelWidth - FieldOffset));

            var pathLabels = ExportSettings.GetMixedSavePaths(FbxSavePaths);

            if (this is ConvertToPrefabEditorWindow)
            {
                pathLabels = ExportSettings.GetRelativeFbxSavePaths(FbxSavePaths, ref m_selectedFbxPath);
            }

            SelectedFbxPath = EditorGUILayout.Popup(SelectedFbxPath, pathLabels, GUILayout.MinWidth(SelectableLabelMinWidth));

            if (!(this is ConvertToPrefabEditorWindow))
            {
                var exportSettingsEditor = InnerEditor as ExportModelSettingsEditor;
                // Set export setting for exporting outside the project on choosing a path
                var exportOutsideProject = !pathLabels[SelectedFbxPath].Substring(0, 6).Equals("Assets");
                exportSettingsEditor.SetExportingOutsideProject(exportOutsideProject);
            }

            if (GUILayout.Button(new GUIContent("...", "Browse to a new location to export to"), EditorStyles.miniButton, GUILayout.Width(BrowseButtonWidth)))
            {
                string initialPath = Application.dataPath;

                string fullPath = EditorUtility.OpenFolderPanel(
                    "Select Export Model Path", initialPath, null
                    );

                // Unless the user canceled, save path.
                if (!string.IsNullOrEmpty(fullPath))
                {
                    var relativePath = ExportSettings.ConvertToAssetRelativePath(fullPath);

                    // If exporting an fbx for a prefab, not allowed to export outside the Assets folder
                    if (this is ConvertToPrefabEditorWindow && string.IsNullOrEmpty(relativePath))
                    {
                        Debug.LogWarning("Please select a location in the Assets folder");
                    }
                    // We're exporting outside Assets folder, so store the absolute path
                    else if (string.IsNullOrEmpty(relativePath))
                    {
                        ExportSettings.AddSavePath(fullPath, FbxSavePaths, exportOutsideProject: true);
                        SelectedFbxPath = 0;
                    }
                    // Store the relative path to the Assets folder
                    else
                    {
                        ExportSettings.AddSavePath(relativePath, FbxSavePaths, exportOutsideProject: false);
                        SelectedFbxPath = 0;
                    }
                    // Make sure focus is removed from the selectable label
                    // otherwise it won't update
                    GUIUtility.hotControl      = 0;
                    GUIUtility.keyboardControl = 0;
                }
            }
            GUILayout.EndHorizontal();

            CreateCustomUI();

            EditorGUILayout.Space();

            EditorGUI.BeginDisabledGroup(DisableTransferAnim);
            EditorGUI.indentLevel--;
            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(new GUIContent(
                                           "Transfer Animation",
                                           "Transfer transform animation from source to destination. Animation on objects between source and destination will also be transferred to destination."
                                           ), GUILayout.Width(LabelWidth - FieldOffset));
            GUILayout.EndHorizontal();
            EditorGUI.indentLevel++;
            TransferAnimationSource = EditorGUILayout.ObjectField("Source", TransferAnimationSource, typeof(Transform), allowSceneObjects: true) as Transform;
            TransferAnimationDest   = EditorGUILayout.ObjectField("Destination", TransferAnimationDest, typeof(Transform), allowSceneObjects: true) as Transform;
            EditorGUILayout.Space();
            EditorGUI.EndDisabledGroup();

            EditorGUI.indentLevel--;
            m_showOptions = EditorGUILayout.Foldout(m_showOptions, "Options");
            EditorGUI.indentLevel++;
            if (m_showOptions)
            {
                InnerEditor.OnInspectorGUI();
            }

            // if we are exporting or converting a prefab with overrides, then show a warning
            if (SelectionContainsPrefabInstanceWithAddedObjects())
            {
                EditorGUILayout.Space();
                EditorGUILayout.HelpBox("Prefab instance overrides will be exported", MessageType.Warning, true);
            }

            GUILayout.FlexibleSpace();

            GUILayout.BeginHorizontal();
            DoNotShowDialogUI();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Cancel", GUILayout.Width(ExportButtonWidth)))
            {
                this.Close();
            }

            if (GUILayout.Button(ExportButtonName, GUILayout.Width(ExportButtonWidth)))
            {
                if (Export())
                {
                    this.Close();
                }
            }
            GUILayout.EndHorizontal();
            EditorGUILayout.Space(); // adding a space at bottom of dialog so buttons aren't right at the edge

            if (GUI.changed)
            {
                SaveExportSettings();
            }
        }
        // -------------------------------------------------------------------------------------

        protected void OnGUI()
        {
            // Increasing the label width so that none of the text gets cut off
            EditorGUIUtility.labelWidth = LabelWidth;

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            #if UNITY_2018_1_OR_NEWER
            if (EditorGUILayout.DropdownButton(presetIcon, FocusType.Keyboard, presetIconButton))
            {
                ShowPresetReceiver();
            }
            #endif

            GUILayout.EndHorizontal();

            EditorGUILayout.LabelField("Naming");
            EditorGUI.indentLevel++;

            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(new GUIContent(
                                           "Export Name",
                                           "Filename to save model to."), GUILayout.Width(LabelWidth - TextFieldAlignOffset));

            EditorGUI.BeginDisabledGroup(DisableNameSelection);
            // Show the export name with an uneditable ".fbx" at the end
            //-------------------------------------
            EditorGUILayout.BeginVertical();
            EditorGUILayout.BeginHorizontal(EditorStyles.textField, GUILayout.Height(EditorGUIUtility.singleLineHeight));
            EditorGUI.indentLevel--;
            // continually resize to contents
            var textFieldSize = NameTextFieldStyle.CalcSize(new GUIContent(ExportFileName));
            ExportFileName = EditorGUILayout.TextField(ExportFileName, NameTextFieldStyle, GUILayout.Width(textFieldSize.x + 5), GUILayout.MinWidth(5));
            ExportFileName = ModelExporter.ConvertToValidFilename(ExportFileName);

            EditorGUILayout.LabelField("<color=#808080ff>.fbx</color>", FbxExtLabelStyle, GUILayout.Width(FbxExtLabelWidth));
            EditorGUI.indentLevel++;

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.EndVertical();
            //-----------------------------------
            EditorGUI.EndDisabledGroup();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(new GUIContent(
                                           "Export Path",
                                           "Relative path for saving Model Prefabs."), GUILayout.Width(LabelWidth - FieldOffset));

            var pathLabels = ExportSettings.GetRelativeFbxSavePaths();

            ExportSettings.instance.SelectedFbxPath = EditorGUILayout.Popup(ExportSettings.instance.SelectedFbxPath, pathLabels, GUILayout.MinWidth(SelectableLabelMinWidth));

            if (GUILayout.Button(new GUIContent("...", "Browse to a new location to export to"), EditorStyles.miniButton, GUILayout.Width(BrowseButtonWidth)))
            {
                string initialPath = Application.dataPath;

                string fullPath = EditorUtility.OpenFolderPanel(
                    "Select Export Model Path", initialPath, null
                    );

                // Unless the user canceled, make sure they chose something in the Assets folder.
                if (!string.IsNullOrEmpty(fullPath))
                {
                    var relativePath = ExportSettings.ConvertToAssetRelativePath(fullPath);
                    if (string.IsNullOrEmpty(relativePath))
                    {
                        Debug.LogWarning("Please select a location in the Assets folder");
                    }
                    else
                    {
                        ExportSettings.AddFbxSavePath(relativePath);

                        // Make sure focus is removed from the selectable label
                        // otherwise it won't update
                        GUIUtility.hotControl      = 0;
                        GUIUtility.keyboardControl = 0;
                    }
                }
            }
            GUILayout.EndHorizontal();

            CreateCustomUI();

            EditorGUILayout.Space();

            EditorGUI.BeginDisabledGroup(DisableTransferAnim);
            EditorGUI.indentLevel--;
            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(new GUIContent(
                                           "Transfer Animation",
                                           "Transfer transform animation from source to destination. Animation on objects between source and destination will also be transferred to destination."
                                           ), GUILayout.Width(LabelWidth - FieldOffset));
            GUILayout.EndHorizontal();
            EditorGUI.indentLevel++;
            TransferAnimationSource = EditorGUILayout.ObjectField("Source", TransferAnimationSource, typeof(Transform), allowSceneObjects: true) as Transform;
            TransferAnimationDest   = EditorGUILayout.ObjectField("Destination", TransferAnimationDest, typeof(Transform), allowSceneObjects: true) as Transform;
            EditorGUILayout.Space();
            EditorGUI.EndDisabledGroup();

            EditorGUI.indentLevel--;
            m_showOptions = EditorGUILayout.Foldout(m_showOptions, "Options");
            EditorGUI.indentLevel++;
            if (m_showOptions)
            {
                InnerEditor.OnInspectorGUI();
            }

            GUILayout.FlexibleSpace();

            GUILayout.BeginHorizontal();
            DoNotShowDialogUI();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Cancel", GUILayout.Width(ExportButtonWidth)))
            {
                this.Close();
            }

            if (GUILayout.Button(ExportButtonName, GUILayout.Width(ExportButtonWidth)))
            {
                if (Export())
                {
                    this.Close();
                }
            }
            GUILayout.EndHorizontal();

            if (GUI.changed)
            {
                SaveExportSettings();
            }
        }