コード例 #1
0
        public void Freeze(int version)
        {
            if (version <= 0)
            {
                return;
            }

            var repositoryRoot = AssetSyncConfiger.GetInstance().GetRepositoryRootPath();

            if (string.IsNullOrEmpty(repositoryRoot))
            {
                return;
            }

            var syncItems = AssetSyncConfiger.GetInstance().syncItems;

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

            string versionFolderName = string.Format("{0}", version);
            string repositoryPath    = XPathTools.Combine(repositoryRoot, versionFolderName);

            foreach (var syncItem in syncItems)
            {
                string destPath = XPathTools.Combine(repositoryPath, syncItem.realSearcePath);
                if (XFolderTools.Exists(destPath))
                {
                    XFolderTools.DeleteDirectory(destPath, true);
                }
            }
        }
コード例 #2
0
ファイル: SpriteToolsMenu.cs プロジェクト: cnscj/THSTG
        public static void GenPrefabAndmaterial(string assetPath, List <string> exportPathList = null)
        {
            if (exportPathList == null)
            {
                exportPathList = new List <string>();
                string selectRootPath = Path.GetDirectoryName(assetPath);
                string selectFileName = Path.GetFileNameWithoutExtension(assetPath);
                XFolderTools.TraverseFiles(selectRootPath, (fullPath) =>
                {
                    string fileEx = Path.GetExtension(fullPath).ToLower();
                    if (fileEx.Contains("controller"))
                    {
                        string fleRelaPath  = XPathTools.GetRelativePath(fullPath);
                        string fileRootPath = Path.GetDirectoryName(fleRelaPath);

                        exportPathList.Add(fileRootPath);
                    }
                }, true);
            }
            foreach (var exportRootPath in exportPathList)
            {
                string ctrlFilePath = XPathTools.Combine(exportRootPath, SpriteEditorTools.controllerName);

                string folderId         = XStringTools.SplitPathKey(exportRootPath);
                string spriteSavePath   = XPathTools.Combine(exportRootPath, string.Format("{0}.prefab", folderId));
                string materialSavePath = XPathTools.Combine(exportRootPath, string.Format("{0}.mat", folderId));
                var    sprite           = SpriteEditorTools.GeneratePrefabFromAnimationControllerFile(ctrlFilePath, spriteSavePath);
                var    material         = SpriteEditorTools.GenerateMaterialFromAnimationControllerFile(ctrlFilePath, materialSavePath);

                SpriteEditorTools.SetupMaterial(sprite, material);
                SpriteEditorTools.SetupBoxCollider(sprite);
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
            }
        }
コード例 #3
0
ファイル: AssetProcesserConfiger.cs プロジェクト: cnscj/THSTG
        public string GetCheckfileFloderPath()
        {
            string newCheckfileFolderName = string.IsNullOrEmpty(checkfileFolderName) ? DEFAULT_MD5_FOLDER_NAME : checkfileFolderName;
            string checkfileFolderPath    = XPathTools.Combine(GetOutputFolderPath(), newCheckfileFolderName);

            return(checkfileFolderPath);
        }
コード例 #4
0
ファイル: EffectEditorMenu.cs プロジェクト: cnscj/THSTG
        ///
        static void CreateEditor(string assetPath)
        {
            string selectRootPath = XPathTools.GetFileRootPath(assetPath);

            // 处理开始
            var scene = EditorSceneManager.OpenScene(GetEditorPath());

            if (scene != null)
            {
                // 保存新场景
                string savePath = XPathTools.Combine(selectRootPath, string.Format(saveDefaultName));
                savePath = XPathTools.GetUniquePath(savePath);


                //做工,弄一个主角



                EditorSceneManager.SaveScene(scene, savePath);
            }
            else
            {
                Debug.LogWarning("编辑器路径错误");
            }
        }
コード例 #5
0
ファイル: SpriteEditorTools.cs プロジェクト: cnscj/THSTG
        /// <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));
                }
            }
        }
コード例 #6
0
ファイル: AssetProcesserConfiger.cs プロジェクト: cnscj/THSTG
        public string GetCheckfileSaveFolderPath(string progressName)
        {
            string checkfileFolderPath     = GetCheckfileFloderPath();
            string checkfileSaveParentPath = checkfileFolderPath;

            if (createFolderOrAddSuffix)
            {
                checkfileSaveParentPath = XPathTools.Combine(checkfileFolderPath, progressName);
            }
            return(checkfileSaveParentPath);
        }
コード例 #7
0
        /////////////
        private string GetCheckfilePath(string srcPath)
        {
            string checkfileSavePath = AssetProcesserConfiger.GetInstance().GetCheckfileSavePath(_progresersName, srcPath, ".asset");
            var    outName           = OnCheckFileName(srcPath);

            if (!string.IsNullOrEmpty(outName))
            {
                string exName     = Path.GetExtension(checkfileSavePath);
                string parentPath = Path.GetDirectoryName(checkfileSavePath);
                checkfileSavePath = XPathTools.Combine(parentPath, string.Format("{0}{1}", outName, exName));
            }
            return(checkfileSavePath);
        }
コード例 #8
0
ファイル: AssetProcesserConfiger.cs プロジェクト: cnscj/THSTG
        public string GetProcessFloderPath()
        {
            string processFolderPath;

            if (string.IsNullOrEmpty(processFolderName))
            {
                processFolderPath = GetOutputFolderPath();
            }
            else
            {
                processFolderPath = XPathTools.Combine(GetOutputFolderPath(), processFolderName);
            }
            return(processFolderPath);
        }
コード例 #9
0
ファイル: SpriteEditorTools.cs プロジェクト: cnscj/THSTG
        public static void GenerateDBJsonFromDBTextureFile(string assetPath, string savePath = "")
        {
            string          assetFileNonExtName = Path.GetFileNameWithoutExtension(assetPath);
            string          assetRootPath       = Path.GetDirectoryName(assetPath);
            TextureImporter importer            = LoadImporterFromTextureFile(assetPath);

            if (importer)
            {
                //判断是否是精灵图集
                if (!(importer.textureType == TextureImporterType.Sprite && importer.spriteImportMode == SpriteImportMode.Multiple))
                {
                    return;
                }

                Texture texture = AssetDatabase.LoadAssetAtPath <Texture>(assetPath);

                DBSheet sheet = new DBSheet();
                sheet.name      = assetFileNonExtName;
                sheet.imagePath = Path.GetFileName(assetPath);
                sheet.width     = texture.width;
                sheet.height    = texture.height;


                //获取所有精灵帧
                Object[] sheetObjs = AssetDatabase.LoadAllAssetsAtPath(assetPath);
                for (int i = 1; i < sheetObjs.Length; i++)   //第一张不是精灵帧
                {
                    Sprite          sprite = sheetObjs[i] as Sprite;
                    Rect            rect   = sprite.rect;
                    DBSheet.DBFrame frame  = new DBSheet.DBFrame();
                    frame.name   = sprite.name;
                    frame.width  = (int)rect.width;
                    frame.height = (int)rect.height;
                    frame.x      = (int)rect.x;
                    frame.y      = (int)(sheet.height - frame.height - rect.y);

                    sheet.SubTexture.Add(frame);
                }

                var jsonStr = JsonUtility.ToJson(sheet, true);

                if (savePath == "")
                {
                    savePath = XPathTools.Combine(assetRootPath, string.Format("{0}.json", assetFileNonExtName));
                }
                File.WriteAllText(savePath, jsonStr, Encoding.UTF8);
                AssetDatabase.Refresh();
            }
        }
コード例 #10
0
ファイル: AssetBuildConfiger.cs プロジェクト: cnscj/THSTG
        public string GetBuildBundleCommonName(string builderName, string assetPath, bool isCommonKey = false)
        {
            string newBundleSuffix = string.IsNullOrEmpty(bundleSuffix) ? DEFAULT_BUILD_SUFFFIX : bundleSuffix;
            string buildFolderPath = GetBuildFolderPath(builderName);
            string assetNameNotEx  = Path.GetFileNameWithoutExtension(assetPath);
            string assetFinalName  = assetNameNotEx;

            if (isCommonKey)
            {
                assetFinalName = XStringTools.SplitPathKey(assetPath);
            }
            string bundleFileName = string.Format("{0}{1}", assetFinalName, newBundleSuffix);
            string bundleName     = XPathTools.Combine(buildFolderPath, bundleFileName);

            return(bundleName.ToLower());
        }
コード例 #11
0
ファイル: AssetProcesserConfiger.cs プロジェクト: cnscj/THSTG
        public string GetCheckfileSavePath(string progressName, string srcFilePath, string suffix = null)
        {
            string outputName = Path.GetFileNameWithoutExtension(srcFilePath);      //有些可能是同一个Key,二层Key的
            string checkfileSaveParentPath = GetCheckfileSaveFolderPath(progressName);
            string cehckfileSaveName       = outputName;

            if (!createFolderOrAddSuffix)
            {
                if (string.IsNullOrEmpty(suffix))
                {
                    cehckfileSaveName = string.Format("{0}_{1}", cehckfileSaveName, progressName);
                }
                else
                {
                    cehckfileSaveName = string.Format("{0}_{1}{2}", cehckfileSaveName, progressName, suffix);
                }
            }
            else
            {
                if (string.IsNullOrEmpty(suffix))
                {
                    cehckfileSaveName = string.Format("{0}", cehckfileSaveName);
                }
                else
                {
                    cehckfileSaveName = string.Format("{0}{1}", cehckfileSaveName, suffix);
                }
            }

            if (useGUID4SaveCheckfileName)
            {
                cehckfileSaveName = AssetDatabase.AssetPathToGUID(srcFilePath);
            }

            string md5SavePath = XPathTools.Combine(checkfileSaveParentPath, cehckfileSaveName);

            return(md5SavePath);
        }
コード例 #12
0
ファイル: AssetBuildConfiger.cs プロジェクト: cnscj/THSTG
        public string GetExportFolderPath()
        {
            string newExportFolder = string.IsNullOrEmpty(exportFolder) ? DEFAULT_EXPORT_PATH : exportFolder;
            string retExportPath   = newExportFolder;

            if (isCombinePlatformName)
            {
                if (targetType == BuildPlatform.Auto)
                {
                    var    buildPlatform    = GetBuildPlatform();
                    string buildPlatformStr = Enum.GetName(typeof(BuildPlatform), buildPlatform);
                    retExportPath = XPathTools.Combine(newExportFolder, buildPlatformStr);
                }
                else
                {
                    string buildPlatformStr = Enum.GetName(typeof(BuildPlatform), targetType);
                    retExportPath = XPathTools.Combine(newExportFolder, buildPlatformStr);
                }
            }
            string normalRetExportPath = XPathTools.NormalizePath(retExportPath);

            return(normalRetExportPath.ToLower());
        }
コード例 #13
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);
                            }
                        });
                    }
                }
            }
        }
コード例 #14
0
ファイル: AssetBuildConfiger.cs プロジェクト: cnscj/THSTG
        public string GetBuildFolderPath(string builderName)
        {
            string newExportFolderPath = XPathTools.Combine("", builderName);

            return(XPathTools.NormalizePath(newExportFolderPath).ToLower());
        }
コード例 #15
0
ファイル: SpriteToolsMenu.cs プロジェクト: cnscj/THSTG
        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();
        }
コード例 #16
0
ファイル: SpriteEditorTools.cs プロジェクト: cnscj/THSTG
        /// <summary>
        /// 生成动画及控制器
        /// sprite子项命名规则:组_动作名_编号,没有编号的一律不生成Anima
        /// </summary>
        /// <param name="assetPath"></param>
        public static Dictionary <string, Dictionary <string, AnimationClip> > GenerateAnimationClipFromTextureFile(string assetPath, string saveRootPath = "", System.Action <AnimationClip> callback = null)
        {
            string          assetFileNonExtName = Path.GetFileNameWithoutExtension(assetPath);
            string          assetRootPath       = Path.GetDirectoryName(assetPath);
            TextureImporter importer            = LoadImporterFromTextureFile(assetPath);

            if (importer)
            {
                //判断是否是精灵图集
                if (!(importer.textureType == TextureImporterType.Sprite && importer.spriteImportMode == SpriteImportMode.Multiple))
                {
                    return(null);
                }

                //获取所有精灵帧
                Object[] sheetObjs = AssetDatabase.LoadAllAssetsAtPath(assetPath);
                var      sheetDict = new Dictionary <string, Dictionary <string, SortedList <string, SpriteSheetFrameData> > >();
                foreach (var obj in sheetObjs)
                {
                    SpriteSheetFrameData metadata = SpriteSheetFrameData.TryCreate(obj as Sprite);
                    if (metadata != null)
                    {
                        string groupName = metadata.groupName;
                        Dictionary <string, SortedList <string, SpriteSheetFrameData> > actionMaps;
                        if (sheetDict.ContainsKey(groupName))
                        {
                            actionMaps = sheetDict[groupName];
                        }
                        else
                        {
                            actionMaps = new Dictionary <string, SortedList <string, SpriteSheetFrameData> >();
                            sheetDict.Add(groupName, actionMaps);
                        }
                        //
                        string actionName = metadata.actionName;
                        SortedList <string, SpriteSheetFrameData> frameList;
                        if (actionMaps.ContainsKey(actionName))
                        {
                            frameList = actionMaps[actionName];
                        }
                        else
                        {
                            frameList = new SortedList <string, SpriteSheetFrameData>();
                            actionMaps.Add(actionName, frameList);
                        }

                        string idName = metadata.idName;
                        if (frameList.ContainsKey(idName))
                        {
                            Debug.LogWarning(string.Format("{0}_{1}重复ID:{2}", groupName, actionName, idName));

                            metadata.idName = string.Format("{0}_{1}", metadata.idName, frameList.Count);
                            idName          = metadata.idName;
                        }
                        frameList.Add(idName, metadata);
                    }
                }

                if (saveRootPath == "")
                {
                    saveRootPath = assetRootPath;
                }
                Dictionary <string, Dictionary <string, AnimationClip> > outMap = new Dictionary <string, Dictionary <string, AnimationClip> >();
                foreach (var groupPair in sheetDict)
                {
                    //保存资源
                    string   groupName       = groupPair.Key;
                    string[] subFolders      = groupName.Split(new char[] { '@' });
                    string   saveOutRootPath = saveRootPath;
                    for (int i = 0; i < subFolders.Length; i++)
                    {
                        saveOutRootPath = XPathTools.Combine(saveOutRootPath, subFolders[i]);
                        if (!XFolderTools.Exists(saveOutRootPath))
                        {
                            XFolderTools.CreateDirectory(saveOutRootPath);
                        }
                    }

                    Dictionary <string, AnimationClip> outActionMap;
                    if (outMap.ContainsKey(groupName))
                    {
                        outActionMap = outMap[groupName];
                    }
                    else
                    {
                        outActionMap = new Dictionary <string, AnimationClip>();
                        outMap.Add(groupName, outActionMap);
                    }

                    foreach (var actionPair in groupPair.Value)
                    {
                        //保存动画Clip
                        string outName  = actionPair.Key;
                        string saveName = string.Format("{0}.anim", outName);
                        string savePath = Path.Combine(saveOutRootPath, saveName);

                        List <Sprite> spriteList = new List <Sprite>();
                        foreach (var listPair in actionPair.Value)
                        {
                            spriteList.Add(listPair.Value.sprite);
                        }
                        AnimationClip clip = MakeAnimationClip(spriteList.ToArray(), SpriteToolsConfig.GetInstance().defaultFrameRate, savePath);

                        outActionMap.Add(actionPair.Key, clip);
                        if (callback != null)
                        {
                            callback(clip);
                        }
                    }
                }
                return(outMap);
            }
            return(null);
        }
コード例 #17
0
        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;
                    }
                }
            }
        }