Esempio n. 1
0
        private void OnClickFolderTreeItem(FolderElement folderElement)
        {
            if (folderElement == null)
            {
                return;
            }

            curSelectFolder = folderElement;
            ruleTabs.Clear();

            List <T> rules = AssetImporterWindow.Instance.GetRules <T>(folderElement.RelativePath);

            if (rules == null || rules.Count <= 0)
            {
                curRuleTab       = ImportPreferences.AddRule;
                defaultRuleIndex = 0;
                curRule          = null;
                return;
            }


            keyRules.Clear();
            for (int i = 0; i < rules.Count; i++)
            {
                ruleTabs.Add(rules[i].RuleKey);
                keyRules[rules[i].RuleKey] = rules[i];
            }

            curRuleTab = ruleTabs[0];
            curRule    = keyRules[curRuleTab];
        }
Esempio n. 2
0
        /// <summary>
        /// reimport all asset in this folder
        /// </summary>
        /// <param name="folder"></param>
        /// <param name="rules"></param>
        protected void reimportFolder(FolderElement folder, ABaseRule[] rules)
        {
            Dictionary <ABaseRule, List <string> > fileDic = new Dictionary <ABaseRule, List <string> >();

            searchFiles(folder.FullPath, rules, fileDic);

            string dataPath = Application.dataPath;

            float totalCount = 0;

            foreach (List <string> files in fileDic.Values)
            {
                totalCount += files.Count;
            }

            int index = 0;

            foreach (ABaseRule rule in fileDic.Keys)
            {
                List <string> filePaths = fileDic[rule];
                for (int i = 0; i < filePaths.Count; i++)
                {
                    string relativePath = filePaths[i].Replace(dataPath, "Assets");
                    relativePath = relativePath.Replace("\\", "/");

                    rule.ApplySettings(relativePath);

                    EditorUtility.DisplayProgressBar("Tip", "Reimporter...", index / totalCount);
                    index++;
                }
            }
            EditorUtility.ClearProgressBar();
        }
        private static void searchChildDirectory(List <FolderElement> elements, string dir, int depth)
        {
            string[] dirs = Directory.GetDirectories(dir, "*", SearchOption.TopDirectoryOnly);

            if (dir.Length <= 0)
            {
                return;
            }

            for (int i = 0; i < dirs.Length; i++)
            {
                string        rootName    = new DirectoryInfo(dirs[i]).Name;
                FolderElement childFolder = new FolderElement(rootName, dirs[i].Replace("\\", "/"), depth, elements.Count);
                elements.Add(childFolder);

                searchChildDirectory(elements, dirs[i], depth + 1);
            }
        }
        /// <summary>
        /// Get all folders in asset root path
        /// </summary>
        /// <returns></returns>
        public static List <FolderElement> GetAllFolders(string[] rootPaths)
        {
            List <FolderElement> folders = new List <FolderElement>();

            // build the directory tree
            folders.Add(new FolderElement("Root", "", -1, 0));

            if (rootPaths != null)
            {
                int depth = 0;
                for (int i = 0; i < rootPaths.Length; i++)
                {
                    string   fullPath = null;
                    string[] paths    = rootPaths[i].Split('/');
                    if (paths.Length > 2)
                    {
                        for (int j = 1; j < paths.Length; j++)
                        {
                            fullPath = string.Join("/", paths, 0, j + 1);
                            fullPath = fullPath.Replace("Assets", Application.dataPath);
                            string        folderName = new DirectoryInfo(fullPath).Name;
                            FolderElement fe         = new FolderElement(folderName, fullPath, j - 1, folders.Count);
                            folders.Add(fe);
                        }
                        depth = paths.Length - 1;
                    }
                    else
                    {
                        fullPath = rootPaths[i].Replace("Assets", Application.dataPath);
                        string        folderName = new DirectoryInfo(fullPath).Name;
                        FolderElement fe         = new FolderElement(folderName, fullPath, 0, folders.Count);
                        folders.Add(fe);
                        depth = 1;
                    }

                    searchChildDirectory(folders, fullPath, depth);
                }
            }
            return(folders);
        }