示例#1
0
        public AssetLoadResultByLoader Load(AssetLoadInfo loadInfo)
        {
            try
            {
                if (!skyboxLoader.TryLoad(loadInfo.FileSystem, loadInfo.LoadPath, out var skybox, out var imageFileRelativePathsStr, out var error))
                {
                    return(AssetLoadResultByLoader.Failure("FAILED", error));
                }
                var pathsForHashing    = new List <string>();
                var imageRelativePaths = imageFileRelativePathsStr.Select(x => new FilePath(x)).ToArray();
                var paddingCount       = imageRelativePaths.Max(x => x.UpCount);
                var loadFolderPath     = new FilePath(Path.GetDirectoryName(loadInfo.LoadPath));
                var cacheFolderPath    = new FilePath(Enumerable.Range(0, paddingCount).Select(x => "Padding").ToArray());
                var mainFileName       = Path.GetFileName(loadInfo.LoadPath);
                var mainFileCachePath  = cacheFolderPath.CombineWith(mainFileName).ToString();
                pathsForHashing.Add(mainFileCachePath);

                assetFileCache.CopyCacheFileFrom(loadInfo.AssetName, mainFileCachePath, loadInfo.FileSystem, loadInfo.LoadPath);
                foreach (var imageFileRelativePath in imageRelativePaths)
                {
                    var imageCachePath = cacheFolderPath.CombineWith(imageFileRelativePath).ToString();
                    var imageLoadPath  = loadFolderPath.CombineWith(imageFileRelativePath).ToString();
                    assetFileCache.CopyCacheFileFrom(loadInfo.AssetName, imageCachePath, loadInfo.FileSystem, imageLoadPath);
                    pathsForHashing.Add(imageCachePath);
                }

                var hash  = AssetHashMd5.FromMultipleFiles(x => assetFileCache.ReadCacheFile(loadInfo.AssetName, x), pathsForHashing);
                var asset = new Asset(loadInfo.AssetName, skybox, loadInfo.StorageType, hash, loadInfo.ReferencePath, mainFileCachePath);
                return(AssetLoadResultByLoader.Success(asset));
            }
            catch (Exception ex)
            {
                return(AssetLoadResultByLoader.Failure("EXCEPTION", ex));
            }
        }
        public AssetLoadResultByLoader Load(AssetLoadInfo loadInfo)
        {
            IImage image;
            var    loadPath = loadInfo.LoadPath;
            var    fileData = loadInfo.FileSystem.ReadAllBytes(loadPath);

            using (var stream = new MemoryStream(fileData))
                if (!imageLoader.TryLoad(stream, out image, out var error))
                {
                    return(AssetLoadResultByLoader.Failure("FAILED", error));
                }
            var hash  = AssetHashMd5.FromSingleFile(fileData);
            var asset = new Asset(loadInfo.AssetName, image, loadInfo.StorageType, hash, loadInfo.ReferencePath, Path.GetFileName(loadInfo.ReferencePath));

            return(AssetLoadResultByLoader.Success(asset));
        }