Beispiel #1
0
        //读取filelist
        public static XFileList LoadFileList(string path)
        {
            if (!XUtilities.IsFolder(path) || !Directory.Exists(path))
            {
                return(null);
            }
            var filelistPath = $"{path}/{FILE_LIST_NAME}";

            if (!XUtilities.ExistFile(filelistPath))
            {
                XDebug.Log(Tag, $"文件清单不存在 {filelistPath}");
                return(null);
            }
            try
            {
                var fileData = XUtilities.ReadFile(filelistPath);
                var content  = Encoding.UTF8.GetString(fileData);
                var result   = JsonUtility.FromJson <XFileList>(content);
                XDebug.Log(Tag, result.ToLog());
                return(result);
            }
            catch (Exception e)
            {
                XDebug.LogError(Tag, $"读取文件清单失败 {filelistPath}\n{e.ToString()}");
            }
            return(null);
        }
Beispiel #2
0
        //获取或创建一个配置
        public static T GetOrCreateConfig <T>(string assetPath) where T : ScriptableObject
        {
            var config = AssetDatabase.LoadAssetAtPath <T>(assetPath);

            if (config != null)
            {
                return(config);
            }
            config = ScriptableObject.CreateInstance <T>();
            XUtilities.MakePathExist(assetPath);
            AssetDatabase.CreateAsset(config, assetPath);
            return(config);
        }
Beispiel #3
0
        //创建filelist
        public static bool CreateFileList(string path)
        {
            if (!XUtilities.IsFolder(path) || !Directory.Exists(path))
            {
                return(false);
            }
            var files = Directory.GetFiles(path, "*", SearchOption.AllDirectories);

            if (files.Length < 1)
            {
                return(false);
            }

            try
            {
                var result = new XFileList();
                foreach (var file in files)
                {
                    if (file.Contains(FILE_LIST_NAME))
                    {
                        continue;
                    }
                    FileInfo sysFileInfo = new FileInfo(file);

                    var fileInfo = new XFileInfo();
                    fileInfo.name = sysFileInfo.Name;
                    fileInfo.path = file.Replace(path + "\\", string.Empty);
                    var fileStream = sysFileInfo.OpenRead();
                    fileInfo.md5 = ToMD5(fileStream);
                    fileStream.Close();
                    fileInfo.length = sysFileInfo.Length;
                    result.m_dictFileInfo.Add(fileInfo.name, fileInfo);
                }
                XDebug.Log(Tag, result.ToLog());
                var json         = JsonUtility.ToJson(result);
                var filelistPath = $"{path}/{FILE_LIST_NAME}";
                File.WriteAllText(filelistPath, json);
                return(true);
            }
            catch (Exception e)
            {
                XDebug.LogError(Tag, e.ToString());
            }
            return(false);
        }
Beispiel #4
0
        //保存filelist
        public static bool SaveFileList(string path, XFileList fileList)
        {
            if (!XUtilities.IsFolder(path) || !Directory.Exists(path))
            {
                return(false);
            }
            var filelistPath = $"{path}/{FILE_LIST_NAME}";

            try
            {
                var json = JsonUtility.ToJson(fileList);
                XUtilities.SaveFile(filelistPath, json);
                XDebug.Log(Tag, json);
                return(true);
            }
            catch (Exception e)
            {
                XDebug.LogError(Tag, $"保存文件清单失败 {filelistPath}\n{e.ToString()}");
            }
            return(false);
        }