/// <summary>
        /// 同步资源配置
        /// </summary>
        static void SyncAssetConfig(string path, AssetBundleBuildData.AssetBuild.Element element, ResourcesManifestData data
                                    , bool is_write)
        {
            if (element.Rule == (int)emAssetBundleNameRule.Ignore)
            {
                return;
            }

            string key = EditorCommon.ConvertToAssetBundleName(path);

            ResourcesManifestData.AssetBundle ab_data;
            if (data.AssetBundles.TryGetValue(key, out ab_data))
            {
                if (is_write)
                {
                    ab_data.IsCompress    = element.IsCompress;
                    ab_data.IsNative      = element.IsNative;
                    ab_data.IsPermanent   = element.IsPermanent;
                    ab_data.IsStartupLoad = element.IsStartupLoad;
                }
                else
                {
                    element.IsCompress    = ab_data.IsCompress;
                    element.IsNative      = ab_data.IsNative;
                    element.IsPermanent   = ab_data.IsPermanent;
                    element.IsStartupLoad = ab_data.IsStartupLoad;
                }
            }

            if (element.Children != null && element.Children.Count > 0)
            {
                foreach (var child in element.Children)
                {
                    string child_path = path + "/" + child.Name.ToLower();
                    SyncAssetConfig(child_path, child, data, is_write);
                }
            }
        }
            /// <summary>
            ///
            /// </summary>
            public int Build(AssetBundleBuildData.AssetBuild.Element elem, int index)
            {
                if (elem == null)
                {
                    return(index);
                }

                Element = elem;
                Index   = index++;

                Children.Clear();
                if (elem.Children != null)
                {
                    for (int i = 0; i < elem.Children.Count; ++i)
                    {
                        AssetNode ctrl = new AssetNode();
                        index       = ctrl.Build(elem.Children[i], index);
                        ctrl.Parent = this;
                        Children.Add(ctrl);
                    }
                }

                return(index);
            }
        /// <summary>
        /// 更改打包资源起始路径
        /// </summary>
        public void ModifyAssetStartPath(string build_start_path, Action <string> progress_report)
        {
            if (!Directory.Exists(build_start_path))
            {
                return;
            }

            int startIndex = Common.PROJECT_ASSET_ROOT_NAME.Length;

            build_start_path = EditorCommon.AbsoluteToRelativePath(build_start_path);
            string new_native_path = build_start_path.Substring(startIndex);
            string old_native_path = Data.BuildStartLocalPath.Substring(startIndex);

            List <string> new_native_folders = new List <string>(new_native_path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries));
            List <string> old_native_folders = new List <string>(old_native_path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries));

            AssetBundleBuildData.AssetBuild.Element root = null;
            CompareBuildData(ref root, Data.Assets.Root
                             , new_native_folders, old_native_folders
                             , EditorCommon.ASSET_START_PATH, progress_report);

            Data.Assets.Root         = root;
            Data.BuildStartLocalPath = build_start_path;
        }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 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();
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
        }
        /// <summary>
        /// 对比新旧打包资源起始路径,返回最新的配置数据
        /// </summary>
        static void CompareBuildData(ref AssetBundleBuildData.AssetBuild.Element result
                                     , AssetBundleBuildData.AssetBuild.Element old_root
                                     , List <string> new_native_folder_list
                                     , List <string> old_native_folder_list
                                     , string path
                                     , Action <string> progress_report)
        {
            if (new_native_folder_list.Count == 0 && old_native_folder_list.Count == 0)
            {
                result = old_root;
                return;
            }
            if (new_native_folder_list.Count == 0)
            {
                new_native_folder_list = null;
            }
            if (old_native_folder_list.Count == 0)
            {
                old_native_folder_list = null;
            }
            if (new_native_folder_list != null && old_native_folder_list != null)
            {
                if (new_native_folder_list[0] == old_native_folder_list[0])
                {
                    path = path + "/" + new_native_folder_list[0];
                    new_native_folder_list.RemoveAt(0);
                    old_native_folder_list.RemoveAt(0);
                    CompareBuildData(ref result, old_root
                                     , new_native_folder_list, old_native_folder_list
                                     , path, progress_report);
                }
                else
                {
                    foreach (var name in new_native_folder_list)
                    {
                        path = path + "/" + name;
                    }
                    result = GenerateAssetBundleRuleData(path
                                                         , emAssetBundleNameRule.None, progress_report);
                    return;
                }
            }

            //新路径是旧路径的父路径,保留旧的配置数据并生成其它的配置数据
            if (new_native_folder_list == null)
            {
                result = GenerateAssetBundleRuleData(path
                                                     , emAssetBundleNameRule.None, progress_report);

                var temp = result;
                for (int i = 0; i < old_native_folder_list.Count; ++i)
                {
                    if (temp == null)
                    {
                        break;
                    }
                    temp = temp.FindFolderElement(old_native_folder_list[i]);
                }
                if (temp != null)
                {
                    old_root.CopyTo(temp);
                }

                return;
            }

            //旧路径是新路径的父路径, 拷贝旧的配置数据中包含的新路径配置数据
            if (old_native_folder_list == null)
            {
                var temp = old_root;
                for (int i = 0; i < new_native_folder_list.Count; ++i)
                {
                    if (temp == null)
                    {
                        break;
                    }
                    temp = temp.FindFolderElement(new_native_folder_list[i]);
                }
                result = temp;

                if (result == null)
                {
                    foreach (var name in new_native_folder_list)
                    {
                        path = path + "/" + name;
                    }
                    result = GenerateAssetBundleRuleData(path
                                                         , emAssetBundleNameRule.None, progress_report);
                }
                return;
            }
        }
        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);
            }
        }