/// <summary>
        /// 遍历Resources目录的时候操作文件的函数
        /// </summary>
        /// <param name="fileInfo"></param>
        private static void OprateFile(FileInfo fileInfo)
        {
//            Debug.Log(fileInfo.FullName);
            if (fileInfo.FullName.EndsWith(".meta"))
            {
//                Debug.Log("跳过。meta");
                return;
            }

            var loadPath = fileInfo.FullName.GetAfterSubstring("Resources\\")
                           .GetBeforeSubstring(Path.GetExtension(fileInfo.FullName));
            var fileName = Path.GetFileNameWithoutExtension(fileInfo.FullName);
            var varName  = FileUtil.FileNameToVarName(fileName);

            if (allResPathDic.ContainsKey(varName))
            {
                Debug.LogWarning("相同Key: " + varName);
                Debug.LogWarning("已存:" + allResPathDic[varName]);
                Debug.LogWarning("现在:" + loadPath);
            }
            else
            {
                allResPathDic.Add(varName, loadPath);
                allResFileNameDic.Add(varName, fileName);

                otherResPathDic.Add(varName, loadPath);
                otherResFileNameDic.Add(varName, fileName);
            }
        }
        /// <summary>
        /// 遍历Resources目录时,操作目录的函数
        /// </summary>
        /// <param name="dirInfo"></param>
        /// <param name="rootNs"></param>
        /// <param name="constNs"></param>
        /// <param name="autoDir"></param>
        private static bool OprateDir(DirectoryInfo dirInfo)
        {
            var dirName = dirInfo.FullName.GetAfterLastChar('\\');

            if (dirName == "Resources")
            {
                return(true);
            }

            if (dirName.StartsWith("Global"))
            {
                return(false);
            }

            if (dirName.StartsWith("Class"))
            {
                autoClassName.Add(dirName.GetAfterSubstring("Class"));

                FileUtil.SearchDirectory(dirInfo.FullName,
                                         fileInfo =>
                {
                    if (!fileInfo.FullName.EndsWith(".meta"))
                    {
                        var fileName = Path.GetFileNameWithoutExtension(fileInfo.FullName);
                        var varName  = FileUtil.FileNameToVarName(fileName);
                        var loadPath = fileInfo.FullName.GetAfterSubstring("Resources\\")
                                       .GetBeforeSubstring(Path.GetExtension(fileInfo.FullName));

                        if (allResPathDic.ContainsKey(varName))
                        {
                            Debug.LogWarning("出现同名资源文件:" + fileInfo);
                        }
                        else
                        {
                            allResPathDic.Add(varName, loadPath);
                            allResFileNameDic.Add(varName, fileName);
                        }
                    }
                }, true);
            }

            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// 遍历Resources目录时,操作目录的函数
        /// </summary>
        /// <param name="dirInfo"></param>
        /// <param name="rootNs"></param>
        /// <param name="constNs"></param>
        /// <param name="autoDir"></param>
        private static bool OprateDir(DirectoryInfo dirInfo, string rootNs, string constNs, string autoDir)
        {
//            Debug.Log(dirInfo.FullName);
            var dirName = dirInfo.FullName.GetAfterLastChar('\\');

            if (dirName == "Resources")
            {
                return(true);
            }

//            Debug.Log("operateDir: " + dirName);
            if (dirName.StartsWith("Global"))
            {
                return(false);
            }
            if (dirName.StartsWith("Class"))
            {
                autoClassName.Add(dirName.GetAfterSubstring("Class"));

                if (createPathFile)
                {
                    FileUtil.ReCreateFileNameConstClassFromDir(
                        dirName.GetAfterSubstring("Class") + "Path",
                        Application.dataPath + "/" + rootNs + "/" + constNs + "/" + autoDir,
                        dirInfo.FullName,
                        rootNs + "." + constNs,
                        (fileInfo, stream) =>
                    {
                        if (!fileInfo.FullName.EndsWith(".meta"))
                        {
                            var fileName = Path.GetFileNameWithoutExtension(fileInfo.FullName);
                            var varName  = FileUtil.FileNameToVarName(fileName);
                            var loadPath = fileInfo.FullName.GetAfterSubstring("Resources\\")
                                           .GetBeforeSubstring(Path.GetExtension(fileInfo.FullName));
                            stream.Write("\t\tpublic const string " + varName + " = @\"" + loadPath + "\";\n");
                        }
                    }, true);
                }


                var className = dirName.GetAfterSubstring("Class") + "Name";
                FileUtil.ReCreateFileNameConstClassFromDir(
                    className,
                    Application.dataPath + "/" + rootNs + "/" + constNs + "/" + autoDir,
                    dirInfo.FullName,
                    rootNs + "." + constNs,
                    (fileInfo, stream) =>
                {
                    if (!fileInfo.FullName.EndsWith(".meta"))
                    {
                        var fileName = Path.GetFileNameWithoutExtension(fileInfo.FullName);
                        var varName  = FileUtil.FileNameToVarName(fileName);
                        var loadPath = fileInfo.FullName.GetAfterSubstring("Resources\\")
                                       .GetBeforeSubstring(Path.GetExtension(fileInfo.FullName));

                        if (allResPathDic.ContainsKey(varName))
                        {
                            Debug.LogWarning("出现同名资源文件:" + fileInfo);
                        }
                        else
                        {
                            allResPathDic.Add(varName, loadPath);
                            allResFileNameDic.Add(varName, fileName);
                        }

                        stream.Write("\t\tpublic const string " + varName + " = @\"" + fileName + "\";\n");
                    }
                }, true);
            }
            else
            {
                FileUtil.SearchDirectory(dirInfo.FullName, OprateFile, true);
            }

            return(true);
        }