Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public static string[] FindReferences(string assetPath, string searchPath = null, string[] searchSuffix = null)
        {
            searchPath   = string.IsNullOrEmpty(searchPath) ? Application.dataPath : searchPath;
            searchSuffix = searchSuffix != null ? searchSuffix : SERIALIZABLE_FILE_SUFFIX;
            string assetPathLow = XPathTools.GetRelativePath(assetPath.ToLower());

            string[] files = Directory.GetFiles(searchPath, "*.*", SearchOption.AllDirectories)
                             .Where(s => searchSuffix.Contains(Path.GetExtension(s).ToLower()))
                             .ToArray();


            HashSet <string> refDict = new HashSet <string>();

            foreach (var file in files)
            {
                string   relativePath = XPathTools.GetRelativePath(file);
                string[] dps          = AssetDatabase.GetDependencies(relativePath);
                foreach (string path in dps)
                {
                    string pathLow = path.ToLower();
                    if (pathLow.Contains(assetPathLow))
                    {
                        if (!refDict.Contains(path))
                        {
                            refDict.Add(path);
                        }
                    }
                }
            }

            return(refDict.ToArray());
        }
Exemplo 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();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 从选择项中获取路径
        /// </summary>
        /// <param name="suffixs"></param>
        /// <param name="isTrans"></param>
        /// <returns></returns>
        public static string[] GetPathsBySelections(string[] suffixs = null, bool isTraverse = false)
        {
            var           selectedObjs = Selection.objects;
            List <string> retPathList  = new List <string>();

            if (selectedObjs != null && selectedObjs.Length > 0)
            {
                List <string> filePathList = new List <string>();
                foreach (var selected in selectedObjs)
                {
                    string selectPath = AssetDatabase.GetAssetPath(selected);
                    if (File.Exists(selectPath))            //如果是文件
                    {
                        filePathList.Add(selectPath);
                    }
                    else if (Directory.Exists(selectPath))   //如果是文件夹
                    {
                        XFolderTools.TraverseFiles(selectPath, (fullPath) =>
                        {
                            string realPath = XPathTools.GetRelativePath(fullPath);
                            filePathList.Add(realPath);
                        }, isTraverse);
                    }
                }

                //筛选
                HashSet <string> suffixSet = null;
                if (suffixs != null && suffixs.Length > 0)
                {
                    suffixSet = new HashSet <string>();
                    foreach (var suffix in suffixs)
                    {
                        string lowSuffix = suffix.ToLower();
                        if (!suffixSet.Contains(lowSuffix))
                        {
                            suffixSet.Add(lowSuffix);
                        }
                    }
                }


                foreach (var path in filePathList)
                {
                    if (suffixSet != null)
                    {
                        string fileExtName = Path.GetExtension(path).ToLower();
                        if (suffixSet.Contains(fileExtName))
                        {
                            retPathList.Add(path);
                        }
                    }
                    else
                    {
                        retPathList.Add(path);
                    }
                }
            }
            return(retPathList.ToArray());
        }
Exemplo n.º 5
0
 public string GetBuildBundleShareName(string assetPath)
 {
     if (!string.IsNullOrEmpty(shareBundleName))
     {
         return(GetFormatBundleName(shareBundleName, assetPath));
     }
     else
     {
         assetPath = XPathTools.GetRelativePath(assetPath);
         string newBundleSuffix = string.IsNullOrEmpty(bundleSuffix) ? DEFAULT_BUILD_SUFFFIX : bundleSuffix;
         string assetNameLow    = Path.GetFileNameWithoutExtension(assetPath).ToLower();
         string assetFlatPath   = GetFlatPath(assetPath);
         string bundleName      = string.Format("share/{0}_{1}{2}", assetFlatPath, assetNameLow, newBundleSuffix);
         return(bundleName.ToLower());
     }
 }
Exemplo n.º 6
0
        public string GetFlatPath(string assetPath)
        {
            assetPath = XPathTools.GetRelativePath(assetPath);
            string assetParentPath = Path.GetDirectoryName(assetPath).ToLower();
            string relaPath        = assetParentPath.Replace("assets", "");
            string flatPath        = relaPath.Replace("/", "_");

            if (!string.IsNullOrEmpty(flatPath))
            {
                string newFlatPath = flatPath.Remove(0, 1);
                newFlatPath = string.Format("{0}_", newFlatPath);
                return(newFlatPath);
            }
            else
            {
                return("");
            }
        }
Exemplo n.º 7
0
        private static void UpdateReferences()
        {
            m_gridDict.Clear();
            string assetDir = Application.dataPath;

            var withoutExtensions = new List <string>()
            {
                ".prefab", ".unity", ".mat", ".asset", ".controller", ".playable"
            };

            string[] files = Directory.GetFiles(assetDir, "*.*", SearchOption.AllDirectories)
                             .Where(s => withoutExtensions.Contains(Path.GetExtension(s).ToLower()))
                             .ToArray();

            int startIndex = 0;

            EditorApplication.update = delegate()
            {
                string file     = files[startIndex];
                bool   isCancel = EditorUtility.DisplayCancelableProgressBar("匹配资源中", file, (float)startIndex / (float)files.Length);

                string   relativePath = XPathTools.GetRelativePath(file);
                string[] dps          = AssetDatabase.GetDependencies(relativePath);
                foreach (string path in dps)
                {
                    if (!m_gridDict.ContainsKey(path))
                    {
                        m_gridDict.Add(path, new ArrayList());
                    }
                    ArrayList existFiles = m_gridDict[path];
                    existFiles.Add(relativePath);
                }

                startIndex++;
                if (isCancel || startIndex >= files.Length)
                {
                    EditorUtility.ClearProgressBar();
                    EditorApplication.update = null;
                    startIndex = 0;
                }
            };
        }
Exemplo n.º 8
0
        public static Dictionary <string, string[]> GetAllReferences(string searchPath = null, string[] searchSuffix = null)
        {
            searchPath   = string.IsNullOrEmpty(searchPath) ? Application.dataPath : searchPath;
            searchSuffix = searchSuffix != null ? searchSuffix : SERIALIZABLE_FILE_SUFFIX;
            Dictionary <string, HashSet <string> > refSetMap = new Dictionary <string, HashSet <string> >();

            string[] files = Directory.GetFiles(searchPath, "*.*", SearchOption.AllDirectories)
                             .Where(s => searchSuffix.Contains(Path.GetExtension(s).ToLower()))
                             .ToArray();

            foreach (var file in files)
            {
                string   relativePath = XPathTools.GetRelativePath(file);
                string[] dps          = AssetDatabase.GetDependencies(relativePath);
                foreach (string path in dps)
                {
                    string depRelatPath = XPathTools.GetRelativePath(path);
                    if (depRelatPath.Contains(relativePath))
                    {
                        if (!refSetMap.ContainsKey(relativePath))
                        {
                            refSetMap[relativePath] = new HashSet <string>();
                        }
                        var fileSet = refSetMap[relativePath];
                        if (!fileSet.Contains(depRelatPath))
                        {
                            fileSet.Add(path);
                        }
                    }
                }
            }

            Dictionary <string, string[]> refMap = new Dictionary <string, string[]>();

            foreach (var kv in refSetMap)
            {
                refMap[kv.Key] = kv.Value.ToArray();
            }

            return(refMap);
        }
Exemplo n.º 9
0
        //路径条
        public static string ShowPathBar(string label, string text, string desc = "Source Folder Path", Func <string, string> callback = null)
        {
            EditorGUILayout.BeginHorizontal();
            string path = EditorGUILayout.TextField(label, text);

            if (GUILayout.Button("浏览"))
            {
                var selectedFolderPath = EditorUtility.SaveFolderPanel(desc, "Assets", "");
                if (!string.IsNullOrEmpty(selectedFolderPath))
                {
                    path = XPathTools.GetRelativePath(selectedFolderPath);
                    if (callback != null)
                    {
                        path = callback.Invoke(selectedFolderPath);
                    }
                }
            }

            EditorGUILayout.EndHorizontal();
            return(path);
        }
Exemplo n.º 10
0
        public static void MenuGenSheetJson()
        {
            var    selected   = Selection.activeObject;
            string selectPath = AssetDatabase.GetAssetPath(selected);

            if (selectPath != "")
            {
                List <string> assetsList = new List <string>();
                if (Directory.Exists(selectPath))    //是文件夹
                {
                    //对所有操作
                    XFolderTools.TraverseFiles(selectPath, (fullPath) =>
                    {
                        string fileNameNExt = Path.GetFileNameWithoutExtension(fullPath).ToLower();
                        string fileExt      = Path.GetExtension(fullPath).ToLower();

                        if (!AssetRuntimeUtil.IsImageFile(fullPath))
                        {
                            return;
                        }

                        string assetPath = XPathTools.GetRelativePath(fullPath);
                        assetsList.Add(assetPath);
                    });
                }
                else
                {
                    assetsList.Add(selectPath);
                }
                foreach (var assetPath in assetsList)
                {
                    GenSheetJson(assetPath);
                }
            }
            else
            {
                Debug.LogError("没有选中文件或文件夹");
            }
        }
Exemplo n.º 11
0
        public List <string> GetFileList()
        {
            if (m_files == null)
            {
                m_files = new List <string>();
                var files = OnFiles();
                if (files == null || files.Length <= 0)
                {
                    return(m_files);
                }

                foreach (var fullPath in files)
                {
                    if (string.IsNullOrEmpty(fullPath))
                    {
                        continue;
                    }

                    string assetPath = XPathTools.GetRelativePath(fullPath);
                    m_files.Add(assetPath);
                }
            }
            return(m_files);
        }
Exemplo n.º 12
0
        private List <string> CollectShare()
        {
            Dictionary <string, int> refCounts = new Dictionary <string, int>();

            foreach (var kv in m_buildAssetMap)
            {
                foreach (var fullPath in kv.Value)
                {
                    string   assetPath = XPathTools.GetRelativePath(fullPath);
                    string[] dps       = AssetBuildRelationship.GetDependencies(assetPath);
                    foreach (var dp in dps)
                    {
                        if (refCounts.TryGetValue(dp, out var refCount))
                        {
                            refCounts[dp] = refCount + 1;
                        }
                        else
                        {
                            refCounts.Add(dp, 1);
                        }
                    }
                }
            }

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

            foreach (var refKV in refCounts)
            {
                if (refKV.Value > 1)
                {
                    shareAssetList.Add(refKV.Key);
                }
            }

            return(shareAssetList);
        }
Exemplo n.º 13
0
 protected virtual string[] GetDependencies(string assetPath)
 {
     assetPath = XPathTools.GetRelativePath(assetPath);
     return(AssetBuildRelationship.GetDependencies(assetPath));
 }
Exemplo n.º 14
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();
        }
Exemplo n.º 15
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);
                }
            }
        }
Exemplo n.º 16
0
        public static string[] FindDependencies(string assetPath, bool recursive = false)
        {
            string path = XPathTools.GetRelativePath(assetPath);

            return(AssetDatabase.GetDependencies(path, recursive));
        }