Esempio n. 1
0
        public string GetFormatBundleName(string formatPath, string assetPath)
        {
            if (!string.IsNullOrEmpty(formatPath))
            {
                string assetRootPath  = Path.GetDirectoryName(assetPath);
                string assetEx        = Path.GetExtension(assetPath);
                string assetName      = Path.GetFileName(assetPath);
                string assetNameNotEx = Path.GetFileNameWithoutExtension(assetPath);
                string assetFlatPath  = GetFlatPath(assetPath);
                string assetKey       = XStringTools.SplitPathKey(assetPath);

                string nameFormat = formatPath;
                nameFormat = nameFormat.Replace("{assetRootPath}", assetRootPath);
                nameFormat = nameFormat.Replace("{assetEx}", assetEx);
                nameFormat = nameFormat.Replace("{assetNameNotEx}", assetNameNotEx);
                nameFormat = nameFormat.Replace("{assetName}", assetName);
                nameFormat = nameFormat.Replace("{assetKey}", assetKey);
                nameFormat = nameFormat.Replace("{assetFlatPath}", assetFlatPath);

                if (isRidofSpecialChar)
                {
                    nameFormat = AssetPathUtil.TrimInvalidCharacter(nameFormat);
                }

                return(nameFormat);
            }
            return(null);
        }
Esempio n. 2
0
        protected override string[] OnOnce(string srcFilePath)
        {
            GameObject srcPrefab = PrefabUtility.LoadPrefabContents(srcFilePath);
            GameObject newPrefab = Object.Instantiate(srcPrefab);

            PrefabUtility.UnloadPrefabContents(srcPrefab);


            //计算特效时长
            {
                EffectLengthMono lenCom = newPrefab.GetComponent <EffectLengthMono>() ?? newPrefab.AddComponent <EffectLengthMono>();
                lenCom.Calculate();
            }

            //特效分级
            {
            }


            //保存
            string saveFolderPath = GetSaveFolderPath();
            string prefabKey      = XStringTools.SplitPathKey(srcFilePath);
            string savePath       = Path.Combine(saveFolderPath, string.Format("{0}.prefab", prefabKey));

            PrefabUtility.SaveAsPrefabAsset(newPrefab, savePath);
            Object.DestroyImmediate(newPrefab);

            return(new string[] { savePath });
        }
Esempio n. 3
0
        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();
            }
        }
Esempio n. 4
0
        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());
        }
Esempio n. 5
0
 //拆成10个
 public static void SaveAllLevelPrefabs(GameObject srcGO, string savePath)
 {
     if (srcGO)
     {
         string effectId  = XStringTools.SplitPathKey(srcGO.name);
         string finalPath = Path.Combine(savePath, effectId);
         if (!XFolderTools.Exists(finalPath))
         {
             XFolderTools.CreateDirectory(finalPath);
         }
         for (int i = 1; i <= EffectLevelUtil.MAX_LEVEL; i++)
         {
             string saveName = Path.Combine(finalPath, string.Format("{0}_{1:D2}.prefab", effectId, i));
             SavePrefabByLevel(srcGO, saveName, i);
         }
     }
 }
Esempio n. 6
0
        public static void MenuGenSelectionAnimaAndController()
        {
            var selection = Selection.objects;

            if (selection != null && selection.Length > 0)
            {
                var    target   = selection[0];
                string filePath = AssetDatabase.GetAssetPath(target);
                string fileRoot = Path.GetDirectoryName(filePath);
                string fileKey  = XStringTools.SplitPathName(target.name);
                string savePath = Path.Combine(fileRoot, string.Format("{0}.anim", fileKey));

                SpriteEditorTools.MakeAnimationClip(selection, 12f, savePath);
            }
            else
            {
                Debug.LogError("没有选中的文件");
            }
        }
Esempio n. 7
0
        protected override string[] OnOnce(string srcFilePath)
        {
            GameObject srcPrefab = PrefabUtility.LoadPrefabContents(srcFilePath);
            GameObject newPrefab = Object.Instantiate(srcPrefab);

            PrefabUtility.UnloadPrefabContents(srcPrefab);

            //装上box collider
            {
            }

            //保存
            string saveFolderPath = GetSaveFolderPath();
            string prefabKey      = XStringTools.SplitPathKey(srcFilePath);
            string savePath       = Path.Combine(saveFolderPath, string.Format("{0}.prefab", prefabKey));

            PrefabUtility.SaveAsPrefabAsset(newPrefab, savePath);
            Object.DestroyImmediate(newPrefab);

            return(new string[] { savePath });
        }
Esempio n. 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);
                            }
                        });
                    }
                }
            }
        }
Esempio n. 9
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();
        }
Esempio n. 10
0
        private void DoAssets()
        {
            string[] assetFiles = OnFiles();
            if (assetFiles == null || assetFiles.Length < 0)
            {
                return;
            }

            List <FileInfo> procressList = new List <FileInfo>();

            foreach (var file in assetFiles)
            {
                if (string.IsNullOrEmpty(file))
                {
                    continue;
                }

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

                if (_assetMap.ContainsKey(realPath))
                {
                    continue;
                }

                string checkKey1 = Path.GetFileNameWithoutExtension(realPath);
                string checkKey2 = XStringTools.SplitPathKey(realPath);
                if (!_processPath2srcAssetPath.ContainsKey(checkKey1))
                {
                    _processPath2srcAssetPath.Add(checkKey1, realPath);
                }
                if (!_processPath2srcAssetPath.ContainsKey(checkKey2))
                {
                    _processPath2srcAssetPath.Add(checkKey2, realPath);
                }


                string checkFilePath = GetCheckfilePath(realPath);

                if (!_checkfilePath2srcAssetPath.ContainsKey(checkFilePath))
                {
                    _checkfilePath2srcAssetPath.Add(checkFilePath, realPath);
                }

                AssetProcessCheckfile checkfile = LoadCheckfile(realPath);
                if (!OnCheck(realPath, checkfile))   //如果生成的文件没了,也应该重新生成
                {
                    continue;
                }

                FileInfo fileInfo = new FileInfo();
                fileInfo.path      = realPath;
                fileInfo.checkfile = checkfile;

                _assetMap.Add(realPath, fileInfo);
                procressList.Add(fileInfo);
            }

            foreach (var doFileInfo in procressList)
            {
                var realPath     = doFileInfo.path;
                var processFiles = OnOnce(realPath);
                if (processFiles != null && processFiles.Length > 0)
                {
                    foreach (var processPath in processFiles)
                    {
                        if (!_processPath2srcAssetPath.ContainsKey(processPath))
                        {
                            _processPath2srcAssetPath.Add(processPath, realPath);
                        }
                    }
                }

                //保存Checkfile
                if (_assetMap.TryGetValue(realPath, out var fileInfo))
                {
                    var newCheckfile = OnUpdate(fileInfo.path, fileInfo.checkfile);
                    SaveCheckfile(fileInfo.path, newCheckfile);
                }
            }
        }