Ejemplo n.º 1
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);
                }
            }
        }
Ejemplo n.º 2
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();
        }