示例#1
0
        /// <summary>
        /// 导入项目的Assets文件夹,并修改.cs文件解决冲突
        /// </summary>
        /// <param name="path">需要导入Assets文件夹的项目路径</param>
        /// <param name="currentProjectTempPath">临时文件夹</param>
        /// <param name="projectName">需要导入项目名称</param>
        public override void Import(string path, string currentProjectTempPath, string projectName)
        {
            //当前项目的Assets文件夹的全路径,路径中使用"/"分隔,不是"\"。
            string assetsPath = Application.dataPath;

            //备份当前项目的所有GUID用于判断是否重复
            string[] oldGuidList = GuidUtil.GetAllMetaFileGuidList(assetsPath, true);
            //创建子项目目录,如果目录存在则先删除
            string childProjectPath = assetsPath + "/" + projectName;

            FileUtil2.CreateDirectory(childProjectPath, true);
            EditorUtility.ClearProgressBar();
            //子项目Assets目录
            string childProjectAssetsPath = childProjectPath + "/Assets";

            //复制项目的Assets文件夹到子项目路径
            FileUtil2.CopyDirectory(path + "/Assets", childProjectAssetsPath);
            //删除DOTweenSettings.asset
            DeleteDOTweenSettingsAsset(childProjectAssetsPath);
            //删除不需要导入的文件夹,如Editor、Gizmos、Plugins等
            ForeachAndDeleteIgnoreFolders(childProjectAssetsPath);
            //修改文件夹下的.cs文件解决冲突
            ForeachAndEditCSharpFiles(childProjectAssetsPath, projectName);
            //修改文件夹下的.unity文件,修正SortingLayer等
            ForeachAndEditUnityFiles(childProjectAssetsPath, projectName);
            //修改冲突的GUID
            ForeachAndEditGuids(childProjectAssetsPath, oldGuidList);
        }
示例#2
0
        /// <summary>
        /// 遍历和修改指定文件夹下各个文件有冲突的guid
        /// </summary>
        /// <param name="folderPath">要修改的文件夹</param>
        /// <param name="excludeGuidList">如果文件夹下各个文件的guid与该列表中项重复,则需要修改</param>
        private void ForeachAndEditGuids(string folderPath, string[] excludeGuidList)
        {
            EditorUtility.DisplayProgressBar("Hold on...", "Edit guids...", 0f);
            //重复的guid列表
            string[] duplicateGuidList = GetDuplicateGuidList(folderPath, excludeGuidList);
            //用于替换重复的guid列表
            string[] replaceGuidList = GuidUtil.GetUniqueNewGuids(duplicateGuidList);
            //查找并替换guid的文件类型列表
            string[] testExtensions = new string[] { ".meta", ".unity", ".asset", ".prefab", ".mat" };
            //
            DirectoryInfo directoryInfo = new DirectoryInfo(folderPath);

            FileInfo[] fileInfos = directoryInfo.GetFiles("*", SearchOption.AllDirectories);
            int        len       = fileInfos.Length;

            for (int i = 0; i < len; i++)
            {
                FileInfo fileInfo       = fileInfos[i];
                string   extension      = fileInfo.Extension;
                string   filePath       = fileInfo.FullName;
                bool     isTestFileType = Array.IndexOf(testExtensions, extension) > -1;
                if (isTestFileType)
                {
                    EditorUtility.DisplayProgressBar("Hold on...", "Edit guid with " + fileInfo.Name, (i + 1f) / (float)len);
                    ReplaceFileDuplicateGuid(filePath, duplicateGuidList, replaceGuidList);
                }
            }
            EditorUtility.ClearProgressBar();
        }
示例#3
0
        /// <summary>
        /// 返回一个随机小写字母开头的名称,格式:小写字母+32位GUID
        /// </summary>
        /// <returns></returns>
        public static string GetStartLowerName()
        {
            char   letter = GetRandomLowerCase();
            string guid   = GuidUtil.GetNewGuid("N");

            return(letter + guid);
        }
示例#4
0
        /// <summary>
        /// 返回指定文件夹所有与excludeGuidList中项重复的Guid
        /// </summary>
        /// <param name="folderPath">查找的文件夹路径</param>
        /// <param name="excludeGuidList">用于判断重复的guid列表</param>
        /// <returns></returns>
        private string[] GetDuplicateGuidList(string folderPath, string[] excludeGuidList)
        {
            List <string> results = new List <string>();

            string[] folderAllMetaGuids = GuidUtil.GetAllMetaFileGuidList(folderPath);
            int      i = folderAllMetaGuids.Length;

            while (--i >= 0)
            {
                string guidString  = folderAllMetaGuids[i];
                bool   isDuplicate = Array.IndexOf(excludeGuidList, guidString) > -1;
                if (isDuplicate)
                {
                    results.Add(guidString);
                }
            }
            return(results.ToArray());
        }