/// <summary>
        ///
        /// </summary>
        static void SearchValidAsset(List <string> list, HashSet <string> invalid, ref HashSet <string> output)
        {
            foreach (var name in list)
            {
                if (!output.Contains(name))
                {
                    output.Add(name);
                }

                List <string> assets = new List <string>();
                string[]      array  = AssetDatabase.GetDependencies(name, false);
                foreach (var asset in array)
                {
                    if (!EditorCommon.IsIgnoreFile(asset))
                    {
                        var asset_name = asset.ToLower();
                        if (!invalid.Contains(asset_name))
                        {
                            assets.Add(asset_name);
                        }
                    }
                }

                SearchValidAsset(assets, invalid, ref output);
            }
        }
Beispiel #2
0
 /// <summary>
 ///
 /// </summary>
 public static void ClearSelectionAssetBundleName()
 {
     foreach (var id in Selection.instanceIDs)
     {
         string str = AssetDatabase.GetAssetPath(id);
         if (!EditorCommon.IsIgnoreFile(str))
         {
             ClearAssetBundleName(str);
         }
     }
     AssetDatabase.Refresh();
 }
Beispiel #3
0
        /// <summary>
        ///   添加选中的资源数据至包中
        /// </summary>
        public void AddSelectionAsset(ResourcesPackagesData.Package pack)
        {
            if (pack == null)
            {
                return;
            }

            foreach (var id in Selection.instanceIDs)
            {
                string str       = AssetDatabase.GetAssetPath(id);
                string full_name = EditorCommon.RelativeToAbsolutePath(str);
                if (System.IO.File.Exists(full_name))
                {
                    if (!EditorCommon.IsIgnoreFile(str))
                    {
                        if (!pack.AssetList.Contains(str))
                        {
                            str = str.ToLower();
                            pack.AssetList.Add(str);
                        }
                    }
                }
                else if (System.IO.Directory.Exists(str))
                {
                    System.IO.DirectoryInfo dic = new System.IO.DirectoryInfo(str);
                    foreach (var file in dic.GetFiles("*", System.IO.SearchOption.AllDirectories))
                    {
                        string local = EditorCommon.AbsoluteToRelativePath(file.FullName);
                        if (!string.IsNullOrEmpty(local) && !EditorCommon.IsIgnoreFile(local))
                        {
                            if (!pack.AssetList.Contains(local))
                            {
                                local = local.ToLower();
                                pack.AssetList.Add(local);
                            }
                        }
                    }
                }
            }
        }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        static void ChangeAssetBundleName(string folder_full_name
                                          , string element_path
                                          , AssetBundleBuildData.AssetBuild.Element element
                                          , emAssetBundleNameRule inherit_rule
                                          , System.Action <string> change_report = null)
        {
            if (cancel_running_nametool_)
            {
                return;
            }
            if (string.IsNullOrEmpty(element_path))
            {
                return;
            }
            if (element == null)
            {
                return;
            }
            DirectoryInfo dir = new DirectoryInfo(folder_full_name);

            if (!dir.Exists)
            {
                return;
            }

            if (inherit_rule != emAssetBundleNameRule.Ignore)
            {
                inherit_rule = (emAssetBundleNameRule)element.Rule;
            }

            bool same_directory = folder_full_name == element_path;

            //遍历文件,并设置其AssetBundleName
            FileInfo[] all_files = dir.GetFiles();
            foreach (var f in all_files)
            {
                if (!EditorCommon.IsIgnoreFile(f.Name))
                {
                    if (!same_directory)
                    {
                        ClearAssetBundleName(f.FullName);
                    }
                    else
                    {
                        AssetBundleBuildData.AssetBuild.Element child = element.FindFileElement(f.Name);
                        emAssetBundleNameRule my_rule = child != null ? (emAssetBundleNameRule)child.Rule : emAssetBundleNameRule.None;

                        if (child != null && change_report != null)
                        {
                            change_report(f.FullName);
                        }

                        if (my_rule == emAssetBundleNameRule.SingleFile && inherit_rule != emAssetBundleNameRule.Ignore)
                        {
                            SetAssetBundleName(f.FullName);
                        }
                        else
                        {
                            ClearAssetBundleName(f.FullName);
                        }
                    }
                }
            }

            //遍历文件夹
            DirectoryInfo[] all_dirs = dir.GetDirectories();
            foreach (DirectoryInfo d in all_dirs)
            {
                if (!EditorCommon.IsIgnoreFolder(d.Name))
                {
                    string child_element_path = null;
                    AssetBundleBuildData.AssetBuild.Element child = null;
                    if (!same_directory)
                    {
                        child_element_path = element_path;
                        child = element;
                        ClearAssetBundleName(d.FullName);
                    }
                    else
                    {
                        child_element_path = Common.CovertCommonPath(d.FullName);
                        child = element.FindFolderElement(d.Name);
                        emAssetBundleNameRule my_rule = child != null ? (emAssetBundleNameRule)child.Rule : emAssetBundleNameRule.None;

                        if (child != null && change_report != null)
                        {
                            change_report(d.FullName);
                        }

                        if (my_rule == emAssetBundleNameRule.Folder && inherit_rule != emAssetBundleNameRule.Ignore)
                        {
                            SetAssetBundleName(d.FullName);
                        }
                        else
                        {
                            ClearAssetBundleName(d.FullName);
                        }
                    }

                    ChangeAssetBundleName(Common.CovertCommonPath(d.FullName)
                                          , child_element_path, child, inherit_rule, change_report);
                }
            }
        }
Beispiel #5
0
        /// <summary>
        ///
        /// </summary>
        static void ChangeAssetBundleName(string folder_full_name
                                          , AssetBundleBuildData.AssetBuild.Element element
                                          , System.Action <string> change_callback = null)
        {
            if (cancel_running_nametool_)
            {
                return;
            }
            if (element == null)
            {
                return;
            }

            DirectoryInfo dir = new DirectoryInfo(folder_full_name);

            if (!dir.Exists)
            {
                return;
            }

            //遍历文件,并设置其AssetBundleName
            FileInfo[] all_files = dir.GetFiles();
            foreach (var f in all_files)
            {
                AssetBundleBuildData.AssetBuild.Element child = element.FindFileElement(f.Name);
                emAssetBundleNameRule my_rule = child != null ? (emAssetBundleNameRule)child.Rule : emAssetBundleNameRule.None;

                if (!EditorCommon.IsIgnoreFile(f.Name))
                {
                    if (my_rule == emAssetBundleNameRule.SingleFile)
                    {
                        SetAssetBundleName(f.FullName);
                    }
                    else
                    {
                        ClearAssetBundleName(f.FullName);
                    }
                }

                if (child != null)
                {
                    if (change_callback != null)
                    {
                        change_callback(f.FullName);
                    }
                }
            }

            //遍历文件夹
            DirectoryInfo[] all_dirs = dir.GetDirectories();
            foreach (DirectoryInfo d in all_dirs)
            {
                if (!EditorCommon.IsIgnoreFolder(d.Name))
                {
                    AssetBundleBuildData.AssetBuild.Element child = element.FindFolderElement(d.Name);
                    emAssetBundleNameRule my_rule = child != null ? (emAssetBundleNameRule)child.Rule : emAssetBundleNameRule.None;


                    if (my_rule == emAssetBundleNameRule.Folder)
                    {
                        SetAssetBundleName(d.FullName);
                    }
                    else
                    {
                        ClearAssetBundleName(d.FullName);
                    }


                    if (child != null)
                    {
                        if (change_callback != null)
                        {
                            change_callback(d.FullName);
                        }
                    }

                    ChangeAssetBundleName(d.FullName, child, change_callback);
                }
            }

            //刷新
            AssetDatabase.Refresh();
        }
Beispiel #6
0
        /// <summary>
        ///   调整数据(匹配现有的文件&文件夹结构,删除无用的数据)
        /// </summary>
        static void MatchAssetRuleElement(string path, AssetBundleBuildData.AssetBuild.Element element)
        {
            try
            {
                if (Directory.Exists(path))
                {
                    uint bit_0 = 0x1;   // 存在数据中
                    uint bit_1 = 0x2;   // 存在文件或文件夹
                    Dictionary <string, uint> folder_dic = new Dictionary <string, uint>();
                    Dictionary <string, uint> file_dic   = new Dictionary <string, uint>();

                    if (element.Children != null && element.Children.Count > 0)
                    {
                        foreach (var elem in element.Children)
                        {
                            if (elem.IsFolder)
                            {
                                if (!folder_dic.ContainsKey(elem.Name))
                                {
                                    folder_dic.Add(elem.Name, bit_0);
                                }
                                else
                                {
                                    folder_dic[elem.Name] |= bit_0;
                                }
                            }
                            else
                            {
                                if (!file_dic.ContainsKey(elem.Name))
                                {
                                    file_dic.Add(elem.Name, bit_0);
                                }
                                else
                                {
                                    file_dic[elem.Name] |= bit_0;
                                }
                            }
                        }
                    }

                    DirectoryInfo dir_info = new DirectoryInfo(path);
                    foreach (DirectoryInfo d in dir_info.GetDirectories())
                    {
                        if (EditorCommon.IsIgnoreFolder(d.Name))
                        {
                            continue;
                        }

                        if (!folder_dic.ContainsKey(d.Name))
                        {
                            folder_dic.Add(d.Name, bit_1);
                        }
                        else
                        {
                            folder_dic[d.Name] |= bit_1;
                        }
                    }
                    foreach (FileInfo f in dir_info.GetFiles())
                    {
                        if (EditorCommon.IsIgnoreFile(f.Name))
                        {
                            continue;
                        }
                        if (!file_dic.ContainsKey(f.Name))
                        {
                            file_dic.Add(f.Name, bit_1);
                        }
                        else
                        {
                            file_dic[f.Name] |= bit_1;
                        }
                    }

                    //删除不存在的文件夹或文件
                    if (element.Children != null && element.Children.Count > 0)
                    {
                        element.Children.RemoveAll((elem) =>
                        {
                            if (elem.IsFolder)
                            {
                                return(folder_dic[elem.Name] == bit_0);
                            }
                            else
                            {
                                return(file_dic[elem.Name] == bit_0);
                            }
                        });

                        //更新子文件夹数据
                        for (int i = 0; i < element.Children.Count; ++i)
                        {
                            if (element.Children[i].IsFolder)
                            {
                                string full_name = path + "/" + element.Children[i].Name;
                                MatchAssetRuleElement(full_name, element.Children[i]);
                            }
                        }
                    }

                    //增加文件夹
                    foreach (var pair in folder_dic)
                    {
                        if (pair.Value == bit_1)
                        {
                            string full_name = path + "/" + pair.Key;
                            element.Add(GenerateAssetBundleRuleData(full_name, (emAssetBundleNameRule)element.Rule));
                        }
                    }

                    //增加文件
                    foreach (var pair in file_dic)
                    {
                        if (pair.Value == bit_1)
                        {
                            string full_name = path + "/" + pair.Key;
                            element.Add(GenerateAssetBundleRuleData(full_name, (emAssetBundleNameRule)element.Rule));
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                Debug.LogWarning(ex.Message);
            }
        }
Beispiel #7
0
        /// <summary>
        /// 遍历指定目录以及子目录,生成默认数据
        /// </summary>
        static AssetBundleBuildData.AssetBuild.Element GenerateAssetBundleRuleData(string path
                                                                                   , emAssetBundleNameRule rule = emAssetBundleNameRule.None)
        {
            try
            {
                AssetBundleBuildData.AssetBuild.Element result = null;
                if (Directory.Exists(path))
                {
                    if (!EditorCommon.IsIgnoreFolder(path))
                    {
                        DirectoryInfo dir_info = new DirectoryInfo(path);

                        //生成自身信息
                        result          = new AssetBundleBuildData.AssetBuild.Element(dir_info.Name);
                        result.Rule     = (int)rule;
                        result.IsFolder = true;

                        //遍历所有文件夹
                        foreach (DirectoryInfo d in dir_info.GetDirectories())
                        {
                            string str = d.ToString();
                            AssetBundleBuildData.AssetBuild.Element child = GenerateAssetBundleRuleData(str);
                            if (child != null)
                            {
                                result.Add(child);
                            }
                        }

                        //遍历所有子文件
                        foreach (FileInfo f in dir_info.GetFiles()) //查找文件
                        {
                            string str = f.ToString();
                            AssetBundleBuildData.AssetBuild.Element child = GenerateAssetBundleRuleData(str);
                            if (child != null)
                            {
                                result.Add(child);
                            }
                        }
                    }
                }
                else if (File.Exists(path))
                {
                    if (!EditorCommon.IsIgnoreFile(path))
                    {
                        //生成自身信息
                        FileInfo info = new FileInfo(path);
                        result          = new AssetBundleBuildData.AssetBuild.Element(info.Name);
                        result.Rule     = (int)rule;
                        result.IsFolder = false;
                    }
                }

                return(result);
            }
            catch (System.Exception e)
            {
                Debug.LogWarning(e.Message);
            }

            return(null);
        }
        static Dictionary <string, uint> s_file_dic_temp_;          ///< 辅助操作缓存

        /// <summary>
        ///   调整数据(匹配现有的文件&文件夹结构,删除无用的数据)
        /// </summary>
        static void MatchAssetRuleElement(string path, AssetBundleBuildData.AssetBuild.Element element
                                          , Action <string> progress_report)
        {
            try
            {
                DirectoryInfo dir_info = new DirectoryInfo(path);
                if (!dir_info.Exists)
                {
                    return;
                }

                if (progress_report != null)
                {
                    progress_report(path);
                }

                uint bit_0 = 0x1;   // 存在数据中
                uint bit_1 = 0x2;   // 存在文件或文件夹

                if (s_folder_dic_temp_ == null)
                {
                    s_folder_dic_temp_ = new Dictionary <string, uint>(512);
                }
                else
                {
                    s_folder_dic_temp_.Clear();
                }
                if (s_file_dic_temp_ == null)
                {
                    s_file_dic_temp_ = new Dictionary <string, uint>(512);
                }
                else
                {
                    s_file_dic_temp_.Clear();
                }

                if (element.Children != null && element.Children.Count > 0)
                {
                    foreach (var elem in element.Children)
                    {
                        if (elem.IsFolder)
                        {
                            if (!s_folder_dic_temp_.ContainsKey(elem.Name))
                            {
                                s_folder_dic_temp_.Add(elem.Name, bit_0);
                            }
                        }
                        else
                        {
                            if (!s_file_dic_temp_.ContainsKey(elem.Name))
                            {
                                s_file_dic_temp_.Add(elem.Name, bit_0);
                            }
                        }
                    }
                }

                foreach (DirectoryInfo d in dir_info.GetDirectories())
                {
                    if (EditorCommon.IsIgnoreFolder(d.Name))
                    {
                        continue;
                    }

                    if (!s_folder_dic_temp_.ContainsKey(d.Name))
                    {
                        s_folder_dic_temp_.Add(d.Name, bit_1);
                    }
                    else
                    {
                        s_folder_dic_temp_.Remove(d.Name);
                    }
                }

                foreach (FileInfo f in dir_info.GetFiles())
                {
                    if (EditorCommon.IsIgnoreFile(f.Name))
                    {
                        continue;
                    }
                    if (!s_file_dic_temp_.ContainsKey(f.Name))
                    {
                        s_file_dic_temp_.Add(f.Name, bit_1);
                    }
                    else
                    {
                        s_file_dic_temp_.Remove(f.Name);
                    }
                }

                //删除不存在的数据
                if (element.Children != null && element.Children.Count > 0)
                {
                    element.Children.RemoveAll((elem) =>
                    {
                        if (elem.IsFolder)
                        {
                            return(s_folder_dic_temp_.ContainsKey(elem.Name) && s_folder_dic_temp_[elem.Name] == bit_0);
                        }
                        else
                        {
                            return(s_file_dic_temp_.ContainsKey(elem.Name) && s_file_dic_temp_[elem.Name] == bit_0);
                        }
                    });
                }

                //记录旧的子对象数量
                int oldChildrenCount = element.Children != null ? element.Children.Count : 0;

                //增加文件夹数据
                foreach (var pair in s_folder_dic_temp_)
                {
                    if (pair.Value == bit_1)
                    {
                        string full_name = path + "/" + pair.Key;
                        element.Add(GenerateAssetBundleRuleData(full_name
                                                                , emAssetBundleNameRule.None
                                                                , progress_report));
                    }
                }

                //增加文件数据
                foreach (var pair in s_file_dic_temp_)
                {
                    if (pair.Value == bit_1)
                    {
                        string full_name = path + "/" + pair.Key;
                        element.Add(GenerateAssetBundleRuleData(full_name
                                                                , emAssetBundleNameRule.None
                                                                , progress_report));
                    }
                }

                //更新子文件夹数据
                if (oldChildrenCount > 0)
                {
                    for (int i = 0; i < oldChildrenCount; ++i)
                    {
                        string full_name = path + "/" + element.Children[i].Name;
                        if (element.Children[i].IsFolder)
                        {
                            MatchAssetRuleElement(full_name, element.Children[i], progress_report);
                        }
                    }
                }

                //重新排序
                element.SortChildren();
            }
            catch (System.Exception ex)
            {
                Debug.LogWarning(ex.Message);
            }
        }