Exemple #1
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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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();
        }