SaveFolderPanel() private method

private SaveFolderPanel ( string title, string folder, string defaultName ) : string
title string
folder string
defaultName string
return string
        public static void SetPrefabSaveFolder()
        {
            string absolutePath = EditorUtility.SaveFolderPanel("Choose a folder to save your item prefabs", "", "");

            prefabsSaveFolder = "Assets" + absolutePath.Replace(Application.dataPath, "");

            if (isPrefabsSaveFolderValid)
            {
                CreateFolderIfDoesNotExistAlready(prefabsSaveFolder, "Items");
                CreateFolderIfDoesNotExistAlready(prefabsSaveFolder, typeof(StatDefinition).Name);
                CreateFolderIfDoesNotExistAlready(prefabsSaveFolder, typeof(ItemCategory).Name);
                CreateFolderIfDoesNotExistAlready(prefabsSaveFolder, typeof(ItemRarity).Name);
                CreateFolderIfDoesNotExistAlready(prefabsSaveFolder, typeof(EquipmentType).Name);
                CreateFolderIfDoesNotExistAlready(prefabsSaveFolder, typeof(CurrencyDefinition).Name);
                CreateFolderIfDoesNotExistAlready(prefabsSaveFolder, typeof(CraftingCategory).Name);
                CreateFolderIfDoesNotExistAlready(prefabsSaveFolder, typeof(CraftingBlueprint).Name);
                CreateFolderIfDoesNotExistAlready(prefabsSaveFolder, "Settings");
            }
        }
示例#2
0
        private void ExtractTexturesGUI()
        {
            using (new EditorGUILayout.HorizontalScope())
            {
                EditorGUILayout.PrefixLabel(Styles.Textures);

                using (
                    new EditorGUI.DisabledScope(!m_HasEmbeddedTextures.boolValue &&
                                                !m_HasEmbeddedTextures.hasMultipleDifferentValues))
                {
                    if (GUILayout.Button(Styles.ExtractEmbeddedTextures))
                    {
                        // when extracting textures, we must handle the case when multiple selected assets could generate textures with the same name at the user supplied path
                        // we proceed as follows:
                        // 1. each asset extracts the textures in a separate temp folder
                        // 2. we remap the extracted assets to the respective asset importer
                        // 3. we generate unique names for each asset and move them to the user supplied path
                        // 4. we re-import all the assets to have the internal materials linked to the newly extracted textures

                        List <Tuple <Object, string> > outputsForTargets = new List <Tuple <Object, string> >();
                        // use the first target for selecting the destination folder, but apply that path for all targets
                        string destinationPath = (target as ModelImporter).assetPath;
                        destinationPath = EditorUtility.SaveFolderPanel("Select Textures Folder",
                                                                        FileUtil.DeleteLastPathNameComponent(destinationPath), "");
                        if (string.IsNullOrEmpty(destinationPath))
                        {
                            // cancel the extraction if the user did not select a folder
                            return;
                        }
                        destinationPath = FileUtil.GetProjectRelativePath(destinationPath);

                        try
                        {
                            // batch the extraction of the textures
                            AssetDatabase.StartAssetEditing();

                            foreach (var t in targets)
                            {
                                var tempPath = FileUtil.GetUniqueTempPathInProject();
                                tempPath = tempPath.Replace("Temp", UnityEditorInternal.InternalEditorUtility.GetAssetsFolder());
                                outputsForTargets.Add(Tuple.Create(t, tempPath));

                                var importer = t as ModelImporter;
                                importer.ExtractTextures(tempPath);
                            }
                        }
                        finally
                        {
                            AssetDatabase.StopAssetEditing();
                        }

                        try
                        {
                            // batch the remapping and the reimport of the assets
                            AssetDatabase.Refresh();
                            AssetDatabase.StartAssetEditing();

                            foreach (var item in outputsForTargets)
                            {
                                var importer = item.Item1 as ModelImporter;

                                var guids = AssetDatabase.FindAssets("t:Texture", new string[] { item.Item2 });

                                foreach (var guid in guids)
                                {
                                    var path = AssetDatabase.GUIDToAssetPath(guid);
                                    var tex  = AssetDatabase.LoadAssetAtPath <Texture>(path);
                                    if (tex == null)
                                    {
                                        continue;
                                    }

                                    importer.AddRemap(new AssetImporter.SourceAssetIdentifier(tex), tex);

                                    var newPath = Path.Combine(destinationPath, FileUtil.UnityGetFileName(path));
                                    newPath = AssetDatabase.GenerateUniqueAssetPath(newPath);
                                    AssetDatabase.MoveAsset(path, newPath);
                                }

                                AssetDatabase.ImportAsset(importer.assetPath, ImportAssetOptions.ForceUpdate);

                                AssetDatabase.DeleteAsset(item.Item2);
                            }
                        }
                        finally
                        {
                            AssetDatabase.StopAssetEditing();
                        }
                    }
                }
            }
        }
        private bool ExtractMaterialsGUI()
        {
            using (new EditorGUILayout.HorizontalScope())
            {
                EditorGUILayout.PrefixLabel(Styles.Materials);
                using (new EditorGUI.DisabledScope(!m_CanExtractEmbeddedMaterials))
                {
                    if (GUILayout.Button(Styles.ExtractEmbeddedMaterials))
                    {
                        // use the first target for selecting the destination folder, but apply that path for all targets
                        string destinationPath = (target as ModelImporter).assetPath;
                        destinationPath = EditorUtility.SaveFolderPanel("Select Materials Folder",
                                                                        FileUtil.DeleteLastPathNameComponent(destinationPath), "");
                        if (string.IsNullOrEmpty(destinationPath))
                        {
                            // cancel the extraction if the user did not select a folder
                            return(false);
                        }

                        string assetPath = FileUtil.GetProjectRelativePath(destinationPath);

                        //Where all the required embedded materials are not in the asset database, we need to reimport them
                        if (!AllEmbeddedMaterialsAreImported())
                        {
                            if (EditorUtility.DisplayDialog(L10n.Tr("Are you sure you want to re-extract the Materials?"), L10n.Tr("In order to re-extract the Materials we'll need to reimport the mesh, this might take a while. Do you want to continue?"), L10n.Tr("Yes"), L10n.Tr("No")))
                            {
                                ReimportEmbeddedMaterials();
                            }
                            else
                            {
                                return(false);
                            }
                        }

                        if (!assetPath.StartsWith("Assets"))
                        {
                            destinationPath = FileUtil.NiceWinPath(destinationPath);
                            // Destination could be a package. Need to get assetPath instead of relativePath
                            // The GUID isn't known yet so can't find it from that
                            foreach (var package in PackageManager.PackageInfo.GetAllRegisteredPackages())
                            {
                                if (destinationPath.StartsWith(package.resolvedPath))
                                {
                                    assetPath = package.assetPath + destinationPath.Substring(package.resolvedPath.Length);
                                    break;
                                }
                            }
                        }

                        if (string.IsNullOrEmpty(assetPath))
                        {
                            return(false);
                        }

                        try
                        {
                            // batch the extraction of the textures
                            AssetDatabase.StartAssetEditing();
                            PrefabUtility.ExtractMaterialsFromAsset(targets, assetPath);
                        }
                        finally
                        {
                            AssetDatabase.StopAssetEditing();
                        }

                        // AssetDatabase.StopAssetEditing() invokes OnEnable(), which invalidates all the serialized properties, so we must return.
                        return(true);
                    }
                }
            }

            return(false);
        }
示例#4
0
        private void RefreshUIPSD()
        {
            GUILayout.BeginHorizontal();
            {
                GUILayout.Label("搜索:", GUILayout.Width(100));

                index_search = EditorGUILayout.Popup(index_search, text_seacrch);

                if (index_search != search)
                {
                    search = index_search;

                    LoadSource();
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            {
                if (search == 1)
                {
                    GUILayout.Label(label_inputFolder, GUILayout.Width(100));

                    if (GUILayout.Button(input_inputFolder))
                    {
                        input_inputFolder = EditorUtility.SaveFolderPanel("输出文件夹", input_inputFolder, string.Empty);

                        if (string.IsNullOrEmpty(input_inputFolder))
                        {
                            input_inputFolder = Path.Combine(Utility.Path.Project, InputPath);
                        }
                    }

                    if (GUILayout.Button("刷新", GUILayout.Width(100)))
                    {
                        inputFolder = input_inputFolder;

                        LoadSource();
                    }
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            {
                if (search == 1 && node != null && node.Count > 0)
                {
                    GUILayout.Label("列表:", GUILayout.Width(100));

                    index_searchNode = EditorGUILayout.Popup(index_searchNode, node.ToArray());

                    if (index_searchNode != searchNode)
                    {
                        searchNode = index_searchNode;

                        LoadSource();
                    }
                }
            }
            GUILayout.EndHorizontal();

            if (source.Count > 0)
            {
                GUILayout.Space(5);

                GUILayout.Box(string.Empty, GUILayout.ExpandWidth(true), GUILayout.Height(3));

                GUILayout.BeginHorizontal();
                {
                    GUILayout.BeginVertical();
                    {
                        GUILayout.BeginHorizontal();
                        {
                            GUILayout.Label("※", GUILayout.Width(20));
                            GUILayout.Label("名称", GUILayout.Width(120));
                            GUILayout.Label("路径");
                        }
                        GUILayout.EndHorizontal();

                        scroll = GUILayout.BeginScrollView(scroll);
                        {
                            for (int i = 0; i < source.Count; i++)
                            {
                                GUILayout.BeginHorizontal();
                                {
                                    source[i].output = GUILayout.Toggle(source[i].output, string.Empty, GUILayout.Width(20));
                                    GUILayout.Label(source[i].name, GUILayout.Width(120));
                                    GUILayout.Label(source[i].path);
                                }
                                GUILayout.EndHorizontal();
                            }
                        }
                        GUILayout.EndScrollView();
                    }
                    GUILayout.EndVertical();

                    GUILayout.Box(string.Empty, GUILayout.Width(3), GUILayout.ExpandHeight(true));

                    GUILayout.Space(5);

                    GUILayout.BeginVertical(GUILayout.Width(100));
                    {
                        if (GUILayout.Button("转换", GUILayout.Height(40)))
                        {
                            Convert();
                        }

                        if (GUILayout.Button("全选"))
                        {
                            Select(true);
                        }

                        if (GUILayout.Button("反选"))
                        {
                            Select(false);
                        }

                        if (GUILayout.Button("输入路径"))
                        {
                            OpenFolder(inputFolder);
                        }

                        if (GUILayout.Button("输出路径"))
                        {
                            OpenFolder(Path.Combine(Application.dataPath, outputFolder));
                        }
                    }
                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();
            }
            else
            {
                EditorGUILayout.LabelField("Source is Empty!");
            }

            GUILayout.Space(10);
        }
        public static Dictionary <Vector2Int, TileBase> ConvertToTileSheet(Dictionary <Vector2Int, Object> sheet)
        {
            Dictionary <Vector2Int, TileBase> result = new Dictionary <Vector2Int, TileBase>();

            string defaultPath = ProjectBrowser.s_LastInteractedProjectBrowser
                ? ProjectBrowser.s_LastInteractedProjectBrowser.GetActiveFolderPath()
                : "Assets";

            // Early out if all objects are already tiles
            if (sheet.Values.ToList().FindAll(obj => obj is TileBase).Count == sheet.Values.Count)
            {
                foreach (KeyValuePair <Vector2Int, Object> item in sheet)
                {
                    result.Add(item.Key, item.Value as TileBase);
                }
                return(result);
            }

            UserTileCreationMode userTileCreationMode = UserTileCreationMode.Overwrite;
            string path          = "";
            bool   multipleTiles = sheet.Count > 1;

            if (multipleTiles)
            {
                bool userInterventionRequired = false;
                path = EditorUtility.SaveFolderPanel("Generate tiles into folder ", defaultPath, "");
                path = FileUtil.GetProjectRelativePath(path);

                // Check if this will overwrite any existing assets
                foreach (var item in sheet.Values)
                {
                    if (item is Sprite)
                    {
                        var tilePath = FileUtil.CombinePaths(path, String.Format("{0}.{1}", item.name, k_TileExtension));
                        if (File.Exists(tilePath))
                        {
                            userInterventionRequired = true;
                            break;
                        }
                    }
                }
                // There are existing tile assets in the folder with names matching the items to be created
                if (userInterventionRequired)
                {
                    var option = EditorUtility.DisplayDialogComplex("Overwrite?", String.Format("Assets exist at {0}. Do you wish to overwrite existing assets?", path), "Overwrite", "Create New Copy", "Reuse");
                    switch (option)
                    {
                    case 0:     // Overwrite
                    {
                        userTileCreationMode = UserTileCreationMode.Overwrite;
                    }
                    break;

                    case 1:     // Create New Copy
                    {
                        userTileCreationMode = UserTileCreationMode.CreateUnique;
                    }
                    break;

                    case 2:     // Reuse
                    {
                        userTileCreationMode = UserTileCreationMode.Reuse;
                    }
                    break;
                    }
                }
            }
            else
            {
                // Do not check if this will overwrite new tile as user has explicitly selected the file to save to
                path = EditorUtility.SaveFilePanelInProject("Generate new tile", sheet.Values.First().name, k_TileExtension, "Generate new tile", defaultPath);
            }

            if (string.IsNullOrEmpty(path))
            {
                return(result);
            }

            int i = 0;

            EditorUtility.DisplayProgressBar("Generating Tile Assets (" + i + "/" + sheet.Count + ")", "Generating tiles", 0f);
            foreach (KeyValuePair <Vector2Int, Object> item in sheet)
            {
                TileBase tile;
                string   tilePath = "";
                if (item.Value is Sprite)
                {
                    tile     = CreateTile(item.Value as Sprite);
                    tilePath = multipleTiles
                        ? FileUtil.CombinePaths(path, String.Format("{0}.{1}", tile.name, k_TileExtension))
                        : path;
                    switch (userTileCreationMode)
                    {
                    case UserTileCreationMode.CreateUnique:
                    {
                        if (File.Exists(tilePath))
                        {
                            tilePath = AssetDatabase.GenerateUniqueAssetPath(tilePath);
                        }
                        AssetDatabase.CreateAsset(tile, tilePath);
                    }
                    break;

                    case UserTileCreationMode.Overwrite:
                    {
                        AssetDatabase.CreateAsset(tile, tilePath);
                    }
                    break;

                    case UserTileCreationMode.Reuse:
                    {
                        if (File.Exists(tilePath))
                        {
                            tile = AssetDatabase.LoadAssetAtPath <TileBase>(tilePath);
                        }
                        else
                        {
                            AssetDatabase.CreateAsset(tile, tilePath);
                        }
                    }
                    break;
                    }
                }
                else
                {
                    tile = item.Value as TileBase;
                }
                EditorUtility.DisplayProgressBar("Generating Tile Assets (" + i + "/" + sheet.Count + ")", "Generating " + tilePath, (float)i++ / sheet.Count);
                result.Add(item.Key, tile);
            }
            EditorUtility.ClearProgressBar();

            AssetDatabase.Refresh();
            return(result);
        }
示例#6
0
 private void ExtractTexturesGUI()
 {
     using (new EditorGUILayout.HorizontalScope(new GUILayoutOption[0]))
     {
         EditorGUILayout.PrefixLabel(ModelImporterMaterialEditor.Styles.Textures);
         using (new EditorGUI.DisabledScope(!this.m_HasEmbeddedTextures.boolValue && !this.m_HasEmbeddedTextures.hasMultipleDifferentValues))
         {
             if (GUILayout.Button(ModelImporterMaterialEditor.Styles.ExtractEmbeddedTextures, new GUILayoutOption[0]))
             {
                 List <Tuple <UnityEngine.Object, string> > list = new List <Tuple <UnityEngine.Object, string> >();
                 string text = (base.target as ModelImporter).assetPath;
                 text = EditorUtility.SaveFolderPanel("Select Textures Folder", FileUtil.DeleteLastPathNameComponent(text), "");
                 if (!string.IsNullOrEmpty(text))
                 {
                     text = FileUtil.GetProjectRelativePath(text);
                     try
                     {
                         AssetDatabase.StartAssetEditing();
                         UnityEngine.Object[] targets = base.targets;
                         for (int i = 0; i < targets.Length; i++)
                         {
                             UnityEngine.Object @object = targets[i];
                             string             text2   = FileUtil.GetUniqueTempPathInProject();
                             text2 = text2.Replace("Temp", InternalEditorUtility.GetAssetsFolder());
                             list.Add(Tuple.Create <UnityEngine.Object, string>(@object, text2));
                             ModelImporter modelImporter = @object as ModelImporter;
                             modelImporter.ExtractTextures(text2);
                         }
                     }
                     finally
                     {
                         AssetDatabase.StopAssetEditing();
                     }
                     try
                     {
                         AssetDatabase.Refresh();
                         AssetDatabase.StartAssetEditing();
                         foreach (Tuple <UnityEngine.Object, string> current in list)
                         {
                             ModelImporter modelImporter2 = current.Item1 as ModelImporter;
                             string[]      array          = AssetDatabase.FindAssets("t:Texture", new string[]
                             {
                                 current.Item2
                             });
                             string[] array2 = array;
                             for (int j = 0; j < array2.Length; j++)
                             {
                                 string  guid    = array2[j];
                                 string  text3   = AssetDatabase.GUIDToAssetPath(guid);
                                 Texture texture = AssetDatabase.LoadAssetAtPath <Texture>(text3);
                                 if (!(texture == null))
                                 {
                                     modelImporter2.AddRemap(new AssetImporter.SourceAssetIdentifier(texture), texture);
                                     string text4 = Path.Combine(text, FileUtil.UnityGetFileName(text3));
                                     text4 = AssetDatabase.GenerateUniqueAssetPath(text4);
                                     AssetDatabase.MoveAsset(text3, text4);
                                 }
                             }
                             AssetDatabase.ImportAsset(modelImporter2.assetPath, ImportAssetOptions.ForceUpdate);
                             AssetDatabase.DeleteAsset(current.Item2);
                         }
                     }
                     finally
                     {
                         AssetDatabase.StopAssetEditing();
                     }
                 }
             }
         }
     }
 }