Exemple #1
0
        ////////////
        protected string GetFilesMd5(string[] filesPath)
        {
            if (filesPath == null || filesPath.Length <= 0)
            {
                return("");
            }

            //遍历文件夹,遍历所有文件Md5
            SortedDictionary <string, string> md5Map = new SortedDictionary <string, string>();

            foreach (var filePath in filesPath)
            {
                string md5 = XFileTools.GetMD5(filePath);
                if (!md5Map.ContainsKey(md5))
                {
                    md5Map.Add(md5, filePath);
                }
            }

            StringBuilder stringBuilder = new StringBuilder();

            foreach (var pair in md5Map)
            {
                stringBuilder.Append(pair.Key);
                stringBuilder.Append("|");
            }
            stringBuilder = stringBuilder.Remove(stringBuilder.Length - 1, 1);

            string finalMd5 = stringBuilder.ToString();

            return(finalMd5);
        }
Exemple #2
0
        private Dictionary <string, Item> _dictByMd5;  //字典

        public AssetUpdateAssetList Scan(string assetFolder)
        {
            if (string.IsNullOrEmpty(assetFolder))
            {
                return(this);
            }

            var assetFolderLow = assetFolder.ToLower();
            var fileList       = new List <Item>();

            XFolderTools.TraverseFiles(assetFolder, (fullPath) =>
            {
                var assetPath = XPathTools.GetRelativePath(fullPath);
                var relaPath  = XPathTools.SubRelativePath(assetFolder, assetPath);

                var updateItem      = new Item();
                updateItem.filePath = relaPath.ToLower();
                updateItem.fileMd5  = XFileTools.GetMD5(assetPath);
                updateItem.fileSize = XFileTools.GetLength(assetPath);

                fileList.Add(updateItem);
            }, true);

            path      = assetFolder;
            fileItems = fileList.ToArray();
            return(this);
        }
Exemple #3
0
        public static void MenuGetFileMd5()
        {
            var    selected   = Selection.activeObject;
            string selectPath = AssetDatabase.GetAssetPath(selected);

            if (selectPath != "")
            {
                string[]      checkList     = AssetDatabase.GetDependencies(selectPath);
                StringBuilder stringBuilder = new StringBuilder();
                foreach (var filePath in checkList)
                {
                    string exName = Path.GetExtension(filePath).ToLower();
                    if (exName.Contains("cs"))
                    {
                        continue;
                    }

                    string code = XFileTools.GetMD5(filePath);
                    stringBuilder.Append(filePath);
                    stringBuilder.AppendLine();
                    stringBuilder.Append(code);
                    stringBuilder.AppendLine();
                    stringBuilder.AppendLine();
                }
                Debug.Log(string.Format("{0}", stringBuilder.ToString()));
            }
            else
            {
                Debug.LogError("没有选中文件或文件夹");
            }
        }
Exemple #4
0
        protected AssetProcessCheckfile LoadCheckfile(string srcPath)
        {
            //没有或读取有问题则创建
            AssetProcessCheckfile checkfile;
            string checkfileSavePath = GetCheckfilePath(srcPath);

            if (XFileTools.Exists(checkfileSavePath))
            {
                var srcAsset = AssetDatabase.LoadAssetAtPath <AssetProcessCheckfile>(checkfileSavePath); //脚本丢失可能造成信息丢失
                if (srcAsset == null)
                {
                    checkfile = ScriptableObject.CreateInstance <AssetProcessCheckfile>();
                }
                else
                {
                    checkfile = Object.Instantiate(srcAsset);
                }
            }
            else
            {
                checkfile = ScriptableObject.CreateInstance <AssetProcessCheckfile>();
            }

            return(checkfile);
        }
Exemple #5
0
        public static AnimatorController GenerateAnimationControllerFromAnimationClipFile(string assetPath, string savePath = "", bool isDefault = false)
        {
            //没有就创建,有就添加
            AnimatorController ctrl = null;

            if (!XFileTools.Exists(savePath))
            {
                //不存在就创建
                ctrl = AnimatorController.CreateAnimatorControllerAtPath(savePath);
            }
            else
            {
                ctrl = AssetDatabase.LoadAssetAtPath <AnimatorController>(savePath);
            }
            if (assetPath != "")
            {
                AnimationClip animClip = AssetDatabase.LoadAssetAtPath <AnimationClip>(assetPath);
                if (animClip)
                {
                    SetupAnimationState(ctrl, animClip, isDefault);
                }
            }

            AssetDatabase.SaveAssets(); //保存变更,不然没得内容
            AssetDatabase.Refresh();
            return(ctrl);
        }
Exemple #6
0
        public static SkillTimelineData LoadFromFile(string filePath)
        {
            var content = XFileTools.ReadAllText(filePath);
            var data    = JsonUtility.FromJson <SkillTimelineData>(content);

            return(data);
        }
Exemple #7
0
        private bool VerifyFiles(int packageIndex, List <string> urlPaths, List <string> savePaths)
        {
            string folderPath = _updateList.GetSaveFolderPath(packageIndex);

            if (string.IsNullOrEmpty(folderPath))
            {
                return(false);
            }

            if (!Directory.Exists(folderPath))
            {
                return(false);
            }

            bool isVerify = true;
            var  package  = _updateList.GetPackage(packageIndex);

            var pathsList  = package.GetSaveList();
            var urlsList   = package.GetUrlList();
            int totalCount = Math.Max(pathsList.Count, urlsList.Count);

            for (int i = 0; i < totalCount; ++i)
            {
                var savePath = pathsList[i];
                var urlPath  = urlsList[i];

                bool isFailed = true;
                var  item     = _updateList.GetItemByPath(savePath);
                if (item != null)
                {
                    if (File.Exists(savePath))
                    {
                        string fileMd5 = XFileTools.GetMD5(savePath);
                        if (string.Compare(item.itemSrc.fileMd5, fileMd5) == 0)
                        {
                            isFailed = false;
                        }
                    }
                }

                if (isFailed)
                {
                    urlPaths?.Add(urlPath);
                    savePaths?.Add(savePath);

                    isVerify = false;
                    if (urlPaths == null && savePaths == null)
                    {
                        break;
                    }
                }
            }

            return(isVerify);
        }
Exemple #8
0
        /// <summary>
        /// 从对应的json文件生成精灵帧(DragonBones 5.5)
        /// </summary>
        /// <param name="assetPath">图集路径</param>
        public static void SetupSpriteFrameFromDBJsonFile(string assetPath)
        {
            string assetFileNonExtName = Path.GetFileNameWithoutExtension(assetPath);
            string assetRootPath       = Path.GetDirectoryName(assetPath);

            //查看是否有对应的json文件

            string jsonFilePath = XPathTools.Combine(assetRootPath, string.Format("{0}.json", assetFileNonExtName));

            if (!XFileTools.Exists(jsonFilePath))
            {
                Debug.LogWarning("找不到DragonBones 5.5图集Json文件");
                return;
            }
            TextureImporter importer = LoadImporterFromTextureFile(assetPath);

            if (importer)
            {
                var jsonFile = AssetDatabase.LoadAssetAtPath(jsonFilePath, typeof(TextAsset)) as TextAsset;
                if (jsonFile == null)
                {
                    return;
                }

                var atlas = JsonUtility.FromJson <DBSheet>(jsonFile.text);
                if (atlas != null)
                {
                    if (atlas.SubTexture.Count > 0)
                    {
                        List <SpriteMetaData> spriteDataList = new List <SpriteMetaData>();
                        foreach (var frameData in atlas.SubTexture)
                        {
                            SpriteMetaData md = new SpriteMetaData();

                            int width  = frameData.width;
                            int height = frameData.height;
                            int x      = frameData.x;
                            int y      = atlas.height - height - frameData.y;//TexturePacker以左上为原点,Unity以左下为原点

                            md.rect  = new Rect(x, y, width, height);
                            md.pivot = md.rect.center;
                            md.name  = frameData.name;

                            spriteDataList.Add(md);
                        }
                        importer.textureType      = TextureImporterType.Sprite;     //设置为精灵图集
                        importer.spriteImportMode = SpriteImportMode.Multiple;      //设置为多个
                        importer.spritesheet      = spriteDataList.ToArray();
                        importer.SaveAndReimport();
                    }
                    Debug.Log(string.Format("图集:{0},共生成{1}帧", atlas.name, atlas.SubTexture.Count));
                }
            }
        }
Exemple #9
0
        protected override string[] OnOnce(string srcFilePath)
        {
            //拷贝所有文件
            string fileName       = Path.GetFileName(srcFilePath);
            string saveFolderPath = GetSaveFolderPath();
            string savePath       = Path.Combine(saveFolderPath, fileName);

            XFileTools.Copy(srcFilePath, savePath, true);

            return(new string[] { savePath });
        }
Exemple #10
0
        static T GetOrCreateAsset()
        {
            T asset = null;

            if (XFileTools.Exists(_configAssetsPath))
            {
                asset = AssetDatabase.LoadAssetAtPath <T>(_configAssetsPath);
            }
            else
            {
                asset = ScriptableObject.CreateInstance <T>();
                if (!XFolderTools.Exists(_saveFolder))
                {
                    XFolderTools.CreateDirectory(_saveFolder);
                }
                AssetDatabase.CreateAsset(asset, _configAssetsPath);
                AssetDatabase.Refresh();
            }
            return(asset);
        }
Exemple #11
0
        //验证某个文件夹的文件是否符合
        public bool Verify(string folderPath, List <Item> retList = null)
        {
            if (string.IsNullOrEmpty(folderPath))
            {
                return(false);
            }

            if (!Directory.Exists(folderPath))
            {
                return(false);
            }

            bool isVerify = true;
            var  dict     = GetDictByPath();

            foreach (var pair in dict)
            {
                bool   isFailed = true;
                string path     = Path.Combine(folderPath, pair.Value.filePath);
                if (File.Exists(path))
                {
                    string fileMd5 = XFileTools.GetMD5(path);
                    if (string.Compare(pair.Value.fileMd5, fileMd5) == 0)
                    {
                        isFailed = false;
                    }
                }

                if (isFailed)
                {
                    retList?.Add(pair.Value);
                    isVerify = false;
                    if (retList == null)
                    {
                        break;
                    }
                }
            }

            return(isVerify);
        }
Exemple #12
0
        public static AnimatorOverrideController GenerateAnimationOverrideControllerFromAnimationClipFile(string assetPath, string ctrlTmplPath, string savePath = "")
        {
            //没有就创建,有就添加
            AnimatorOverrideController ovrrideCtrl = null;

            if (XFileTools.Exists(ctrlTmplPath))
            {
                AnimatorController ctrlTmpl = AssetDatabase.LoadAssetAtPath <AnimatorController>(ctrlTmplPath);
                if (ctrlTmpl != null)
                {
                    if (!XFileTools.Exists(savePath))
                    {
                        //不存在就创建
                        ovrrideCtrl = new AnimatorOverrideController();
                        AssetDatabase.CreateAsset(ovrrideCtrl, savePath);
                    }
                    else
                    {
                        ovrrideCtrl = AssetDatabase.LoadAssetAtPath <AnimatorOverrideController>(savePath);
                    }
                    //赋予模板
                    ovrrideCtrl.runtimeAnimatorController = ovrrideCtrl.runtimeAnimatorController != null ? ovrrideCtrl.runtimeAnimatorController : ctrlTmpl;

                    if (assetPath != "")
                    {
                        AnimationClip animClip = AssetDatabase.LoadAssetAtPath <AnimationClip>(assetPath);
                        if (animClip)
                        {
                            SetupOverrideMotion(ovrrideCtrl, animClip);
                        }
                    }

                    AssetDatabase.SaveAssets(); //保存变更,不然没得内容
                }
            }
            AssetDatabase.Refresh();
            return(ovrrideCtrl);
        }
Exemple #13
0
        public static Material GenerateMaterialFromAnimationControllerFile(string assetPath, string savePath = "")
        {
            string assetFileNonExtName = Path.GetFileNameWithoutExtension(assetPath);
            string assetRootPath       = Path.GetDirectoryName(assetPath);

            if (savePath == "")
            {
                string assetRootPathName = Path.GetFileNameWithoutExtension(assetRootPath);
                savePath = Path.Combine(assetRootPath, string.Format("{0}.mat", assetRootPathName));
            }
            Material mat = new Material(SpriteToolsConfig.GetInstance().defaultShader);

            if (XFileTools.Exists(savePath))
            {
                mat = AssetDatabase.LoadAssetAtPath <Material>(savePath);
            }
            else
            {
                AssetDatabase.CreateAsset(mat, savePath);
            }
            AssetDatabase.Refresh();
            return(mat);
        }
Exemple #14
0
        protected bool SaveCheckfile(string srcPath, AssetProcessCheckfile checkfile)
        {
            if (checkfile == null)
            {
                return(false);
            }

            string checkfileSavePath = GetCheckfilePath(srcPath);

            if (!XFileTools.Exists(checkfileSavePath))
            {
                string checkfileParentPath = Path.GetDirectoryName(checkfileSavePath);
                if (!XFolderTools.Exists(checkfileParentPath))
                {
                    XFolderTools.CreateDirectory(checkfileParentPath);
                }
            }

            AssetDatabase.DeleteAsset(checkfileSavePath);
            AssetDatabase.CreateAsset(checkfile, checkfileSavePath);

            return(true);
        }
Exemple #15
0
        public static void GenAnimaAndCtrler(string assetPath, List <string> exportPathList = null)
        {
            string selectRootPath = Path.GetDirectoryName(assetPath);
            string selectFileName = Path.GetFileNameWithoutExtension(assetPath);
            //处理逻辑
            var ctrlMap = SpriteEditorTools.GenerateAnimationClipFromTextureFile(assetPath, "", (clip) =>
            {
                bool isLoop = SpriteToolsConfig.GetInstance().IsNeedLoop(clip.name);
                if (isLoop)
                {
                    SpriteEditorTools.SetupAnimationClipLoop(clip, isLoop);
                }
            });

            foreach (var groupPair in ctrlMap)
            {
                foreach (var clipPair in groupPair.Value)
                {
                    var    clip         = clipPair.Value;
                    string clipFilePath = AssetDatabase.GetAssetPath(clip);
                    string clipRootPath = Path.GetDirectoryName(clipFilePath);

                    bool isDefault = SpriteToolsConfig.GetInstance().IsDefaultState(clip.name);

                    //上层目录检查
                    //如果上层有公共的,直接用公共的
                    //如果上层有模板,生成继承控制器
                    string prevRootPath   = XPathTools.GetParentPath(clipRootPath);
                    string parentCtrl     = XPathTools.Combine(prevRootPath, SpriteEditorTools.controllerName);
                    string parentCtrlTmpl = XPathTools.Combine(prevRootPath, SpriteEditorTools.controllerTmplName);
                    if (XFileTools.Exists(parentCtrl))
                    {
                        var ctrl = AssetDatabase.LoadAssetAtPath <AnimatorController>(parentCtrl);
                        SpriteEditorTools.SetupAnimationState(ctrl, clip, isDefault);
                    }
                    else if (XFileTools.Exists(parentCtrlTmpl))
                    {
                        string overrideCtrlSavePath = XPathTools.Combine(clipRootPath, SpriteEditorTools.overrideControllerName);
                        var    overrideCtrl         = SpriteEditorTools.GenerateAnimationOverrideControllerFromAnimationClipFile("", parentCtrlTmpl, overrideCtrlSavePath);
                        SpriteEditorTools.SetupOverrideMotion(overrideCtrl, clip);
                    }
                    else
                    {
                        string ctrlSavePath = XPathTools.Combine(clipRootPath, SpriteEditorTools.controllerName);

                        var ctrl = SpriteEditorTools.GenerateAnimationControllerFromAnimationClipFile("", ctrlSavePath);
                        SpriteEditorTools.SetupAnimationState(ctrl, clip, isDefault);
                    }
                }

                if (exportPathList != null)
                {
                    string groupPath      = SpriteEditorTools.GroupName2Path(groupPair.Key);
                    string exportRootPath = XPathTools.Combine(selectRootPath, groupPath);

                    exportPathList.Add(exportRootPath);
                }
            }
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
Exemple #16
0
        public void Sync(int version)
        {
            var syncItems = AssetSyncConfiger.GetInstance().syncItems;

            if (syncItems == null || syncItems.Count <= 0)
            {
                return;
            }

            string fullPath          = XPathTools.Combine(AssetSyncConfiger.GetInstance().repositoryRootPath, string.Format("{0}", version));
            string repositoryPath    = fullPath;
            string versionFolderName = Path.GetFileNameWithoutExtension(fullPath);
            int    curVersion        = AssetSyncConfiger.GetInstance().GetRepositoryVersion(versionFolderName);

            if (curVersion > 0 && curVersion >= AssetSyncConfiger.GetInstance().minVersion)
            {
                foreach (var syncItem in syncItems)
                {
                    string srcPath    = syncItem.srcPath;
                    string searchPath = XPathTools.Combine(repositoryPath, syncItem.realSearcePath);
                    string syncPath   = XPathTools.Combine(repositoryPath, syncItem.realSyncPath);
                    if (XFolderTools.Exists(srcPath) && XFolderTools.Exists(searchPath) && XFolderTools.Exists(syncPath))
                    {
                        List <string> syncFileList   = new List <string>();
                        List <string> syncFolderList = new List <string>();
                        if (syncItem.searchMode == AssetSyncItem.SearchMode.Forward)     //根据搜索文件找资源
                        {
                            string srcEx = GetFolderFirstFileExtension(srcPath);
                            XFolderTools.TraverseFiles(searchPath, (filePath) =>
                            {
                                string fileKey = null;
                                if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetName)
                                {
                                    fileKey = Path.GetFileNameWithoutExtension(filePath);
                                }
                                else if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetPrefix)
                                {
                                    fileKey = XStringTools.SplitPathKey(filePath);
                                }

                                string srcFilePath = XPathTools.Combine(srcPath, string.Format("{0}{1}", fileKey, srcEx));
                                if (XFileTools.Exists(srcFilePath))
                                {
                                    syncFileList.Add(srcFilePath);
                                }
                            });

                            XFolderTools.TraverseFolder(searchPath, (folderPath) =>
                            {
                                string fileKey = null;
                                if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetName)
                                {
                                    fileKey = Path.GetFileNameWithoutExtension(folderPath);
                                }
                                else if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetPrefix)
                                {
                                    fileKey = XStringTools.SplitPathKey(folderPath);
                                }

                                string srcFolderPath = XPathTools.Combine(srcPath, string.Format("{0}", fileKey));
                                if (XFolderTools.Exists(srcFolderPath))
                                {
                                    syncFolderList.Add(srcFolderPath);
                                }
                            });
                        }
                        else if (syncItem.searchMode == AssetSyncItem.SearchMode.Reverse)   //根据资源匹对文件
                        {
                            XFolderTools.TraverseFiles(srcPath, (filePath) =>
                            {
                                string fileKey = null;
                                if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetName)
                                {
                                    fileKey = Path.GetFileNameWithoutExtension(filePath);
                                }
                                else if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetPrefix)
                                {
                                    fileKey = XStringTools.SplitPathKey(filePath);
                                }

                                string searchFilePath = XPathTools.Combine(searchPath, string.Format("{0}", fileKey));
                                if (XFileTools.Exists(searchFilePath))
                                {
                                    syncFileList.Add(filePath);
                                }
                            });

                            XFolderTools.TraverseFolder(srcPath, (folderPath) =>
                            {
                                string fileKey = null;
                                if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetName)
                                {
                                    fileKey = Path.GetFileNameWithoutExtension(folderPath);
                                }
                                else if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetPrefix)
                                {
                                    fileKey = XStringTools.SplitPathKey(folderPath);
                                }

                                string searchFilePath = XPathTools.Combine(searchPath, string.Format("{0}", fileKey));
                                if (XFileTools.Exists(searchFilePath))
                                {
                                    syncFolderList.Add(folderPath);
                                }
                            });
                        }

                        HashSet <string> syncFileDict = new HashSet <string>();
                        foreach (var syncSrcFile in syncFileList)
                        {
                            //把文件拷贝到同步目录
                            string syncFileName = Path.GetFileName(syncSrcFile);
                            string syncDestPath = XPathTools.Combine(syncPath, syncFileName);
                            XFileTools.Delete(syncDestPath);
                            XFileTools.Copy(syncSrcFile, syncDestPath);

                            if (!syncFileDict.Contains(syncDestPath))
                            {
                                syncFileDict.Add(syncDestPath);
                            }
                        }

                        HashSet <string> syncFolderDict = new HashSet <string>();
                        foreach (var syncSrcFolder in syncFolderList)
                        {
                            //把文件拷贝到同步目录
                            string syncFileName = Path.GetFileName(syncSrcFolder);
                            string syncDestPath = XPathTools.Combine(syncPath, syncFileName);

                            XFolderTools.DeleteDirectory(syncDestPath, true);
                            XFolderTools.CopyDirectory(syncSrcFolder, syncDestPath);

                            if (!syncFolderDict.Contains(syncDestPath))
                            {
                                syncFolderDict.Add(syncDestPath);
                            }
                        }

                        //移除不在同步的文件
                        XFolderTools.TraverseFiles(syncPath, (syncFullPath) =>
                        {
                            if (!syncFileDict.Contains(syncFullPath))
                            {
                                XFileTools.Delete(syncFullPath);
                            }
                        });

                        XFolderTools.TraverseFolder(syncPath, (syncFullPath) =>
                        {
                            if (!syncFolderDict.Contains(syncFullPath))
                            {
                                XFolderTools.DeleteDirectory(syncFullPath, true);
                            }
                        });
                    }
                }
            }
        }
Exemple #17
0
        private void DoEnd()
        {
            //处理无效的Checkfile文件
            string checkfileFolderPath     = AssetProcesserConfiger.GetInstance().GetCheckfileSaveFolderPath(_progresersName); //TODO:这里如果全部放到一个路径下,会被别的干扰到了
            bool   isUseGUID               = AssetProcesserConfiger.GetInstance().useGUID4SaveCheckfileName;
            bool   createFolderOrAddSuffix = AssetProcesserConfiger.GetInstance().createFolderOrAddSuffix;

            XFolderTools.TraverseFiles(checkfileFolderPath, (fullPath) =>
            {
                string exName = Path.GetExtension(fullPath).ToLower();
                if (exName.Contains("meta"))
                {
                    return;
                }

                string realPath    = XPathTools.GetRelativePath(fullPath); //路径做Key,有的资源可能名字相同
                string realPathLow = realPath.ToLower();
                if (isUseGUID)
                {
                    string srcPath = AssetDatabase.GUIDToAssetPath(realPath);

                    if (string.IsNullOrEmpty(srcPath) || !_assetMap.ContainsKey(realPathLow))
                    {
                        XFileTools.Delete(fullPath);
                    }
                }
                else
                {
                    bool canDelete = true;
                    if (!createFolderOrAddSuffix)
                    {
                        string fileNameWithoutEx = Path.GetFileNameWithoutExtension(realPath);
                        if (!fileNameWithoutEx.EndsWith(_progresersName))
                        {
                            canDelete = false;
                        }
                    }

                    if (canDelete && !_checkfilePath2srcAssetPath.ContainsKey(realPath))
                    {
                        XFileTools.Delete(fullPath);
                    }
                }
            });

            //处理无效输出文件
            string outputFolderPath = AssetProcesserConfiger.GetInstance().GetProcessSaveFolderPath(_progresersName);

            XFolderTools.TraverseFolder(outputFolderPath, (fullPath) =>
            {
                string realPath = XPathTools.GetRelativePath(fullPath);

                string checkKey1 = Path.GetFileNameWithoutExtension(fullPath);
                string checkKey2 = XStringTools.SplitPathKey(fullPath);
                //但凡在名字上有点关系都移除,多重key检测
                if (!_processPath2srcAssetPath.ContainsKey(checkKey1) && !_processPath2srcAssetPath.ContainsKey(checkKey2) && !_processPath2srcAssetPath.ContainsKey(realPath))
                {
                    XFolderTools.DeleteDirectory(fullPath, true);
                }
            });

            XFolderTools.TraverseFiles(outputFolderPath, (fullPath) =>
            {
                string exName = Path.GetExtension(fullPath).ToLower();
                if (exName.Contains("meta"))
                {
                    return;
                }

                string realPath = XPathTools.GetRelativePath(fullPath); //路径做Key,有的资源可能名字相同

                string checkKey1 = Path.GetFileNameWithoutExtension(fullPath);
                string checkKey2 = XStringTools.SplitPathKey(fullPath);
                //但凡在名字上有点关系都移除,多重key检测
                if (!_processPath2srcAssetPath.ContainsKey(checkKey1) && !_processPath2srcAssetPath.ContainsKey(checkKey2) && !_processPath2srcAssetPath.ContainsKey(realPath))
                {
                    XFileTools.Delete(fullPath);
                }
            });


            OnEnd();
        }
        static void BuildAssembly(bool wait)
        {
            for (int i = 0; i < AssembliesToolsConfig.GetInstance().buildPathList.Count; i++)
            {
                var buildInfo = AssembliesToolsConfig.GetInstance().buildPathList[i];

                if (!string.IsNullOrEmpty(buildInfo.srcPath) && !string.IsNullOrEmpty(buildInfo.buildPath) && !string.IsNullOrEmpty(buildInfo.projectPath))
                {
                    bool[] editorFlags = { true, true, true, true };

                    List <string> csFilePaths = new List <string>();

                    XFolderTools.TraverseFiles(buildInfo.srcPath, (string fullPath) =>
                    {
                        if (Path.GetExtension(fullPath) == ".cs")
                        {
                            csFilePaths.Add(fullPath);
                        }
                    }, true);


                    string srcPathName         = Path.GetFileNameWithoutExtension(buildInfo.srcPath);
                    string outputAssembly      = XPathTools.Combine(buildInfo.buildPath, string.Format("{0}.dll", srcPathName));
                    string assemblyProjectPath = XPathTools.Combine(buildInfo.projectPath, string.Format("{0}.dll", srcPathName));
                    if (csFilePaths.Count > 0)
                    {
                        if (!XFolderTools.Exists(buildInfo.buildPath))
                        {
                            XFolderTools.CreateDirectory(buildInfo.buildPath);
                        }
                        if (!XFolderTools.Exists(buildInfo.projectPath))
                        {
                            XFolderTools.CreateDirectory(buildInfo.projectPath);
                        }

                        bool editorFlag = editorFlags[i];

                        var assemblyBuilder = new AssemblyBuilder(outputAssembly, csFilePaths.ToArray());

                        // Exclude a reference to the copy of the assembly in the Assets folder, if any.
                        assemblyBuilder.excludeReferences = new string[] { assemblyProjectPath };

                        if (editorFlag)
                        {
                            assemblyBuilder.flags = AssemblyBuilderFlags.EditorAssembly;
                        }

                        // Called on main thread
                        assemblyBuilder.buildStarted += delegate(string assemblyPath)
                        {
                            Debug.LogFormat("Assembly build started for {0}", assemblyPath);
                        };

                        // Called on main thread
                        assemblyBuilder.buildFinished += delegate(string assemblyPath, CompilerMessage[] compilerMessages)
                        {
                            foreach (var v in compilerMessages)
                            {
                                if (v.type == CompilerMessageType.Error)
                                {
                                    Debug.LogError(v.message);
                                }
                                else
                                {
                                    Debug.LogWarning(v.message);
                                }
                            }

                            var errorCount   = compilerMessages.Count(m => m.type == CompilerMessageType.Error);
                            var warningCount = compilerMessages.Count(m => m.type == CompilerMessageType.Warning);

                            Debug.LogFormat("Assembly build finished for {0}", assemblyPath);
                            Debug.LogFormat("Warnings: {0} - Errors: {0}", errorCount, warningCount);

                            if (errorCount == 0)
                            {
                                File.Copy(outputAssembly, assemblyProjectPath, true);
                                AssetDatabase.ImportAsset(assemblyProjectPath);
                            }
                        };

                        // Start build of assembly
                        if (!assemblyBuilder.Build())
                        {
                            Debug.LogErrorFormat("Failed to start build of assembly {0}!", assemblyBuilder.assemblyPath);
                            return;
                        }

                        if (wait)
                        {
                            while (assemblyBuilder.status != AssemblyBuilderStatus.Finished)
                            {
                                System.Threading.Thread.Sleep(10);
                            }
                        }
                    }
                    else
                    {
                        XFileTools.Delete(assemblyProjectPath);
                        continue;
                    }
                }
            }
        }
Exemple #19
0
        public static void SaveToFile(SkillTimelineData timelineData, string filePath)
        {
            string content = JsonUtility.ToJson(timelineData, true);

            XFileTools.WriteAllText(filePath, content);
        }