コード例 #1
0
        /// <summary>
        ///   绝对路径转换为Unity/Assets相对路径
        /// </summary>
        public static string AbsoluteToRelativePath(string path)
        {
            path = Common.CovertCommonPath(path);
            int last_idx = path.LastIndexOf(ProjectDirectory);

            if (last_idx < 0)
            {
                return(path);
            }

            int start  = last_idx + ProjectDirectory.Length;
            int length = path.Length - start;

            return(path.Substring(start, length));
        }
コード例 #2
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);
                }
            }
        }