Tanoda
ZipFileTextureMapper.cs
Go to the documentation of this file.
1using System;
2using ICSharpCode.SharpZipLib.Zip;
3using StbImageSharp;
4using TriLibCore.Interfaces;
5using TriLibCore.Utils;
6
7namespace TriLibCore.Mappers
8{
10 public class ZipFileTextureMapper : TextureMapper
11 {
13 public override TextureLoadingContext Map(AssetLoaderContext assetLoaderContext, ITexture texture)
14 {
15 var zipLoadCustomContextData = assetLoaderContext.CustomData as ZipLoadCustomContextData;
16 if (zipLoadCustomContextData == null)
17 {
18 throw new Exception("Missing custom context data.");
19 }
20 var zipFile = zipLoadCustomContextData.ZipFile;
21 if (zipFile == null)
22 {
23 throw new Exception("Zip file instance is null.");
24 }
25 if (string.IsNullOrWhiteSpace(texture.Filename))
26 {
27 if (assetLoaderContext.Options.ShowLoadingWarnings)
28 {
29 UnityEngine.Debug.LogWarning("Texture name is null.");
30 }
31 return null;
32 }
33 var shortFileName = FileUtils.GetShortFilename(texture.Filename).ToLowerInvariant();
34 foreach (ZipEntry zipEntry in zipFile)
35 {
36 if (!zipEntry.IsFile)
37 {
38 continue;
39 }
40 var checkingFileShortName = FileUtils.GetShortFilename(zipEntry.Name).ToLowerInvariant();
41 if (shortFileName == checkingFileShortName)
42 {
43 string _;
44 var textureLoadingContext = new TextureLoadingContext
45 {
46 Context = assetLoaderContext,
47 Stream = AssetLoaderZip.ZipFileEntryToStream(out _, zipEntry, zipFile),
48 Texture = texture
49 };
50 return textureLoadingContext;
51 }
52 }
53 return null;
54 }
55 }
56}
Represents a mapper class class used to load Textures from Zip files.
override TextureLoadingContext Map(AssetLoaderContext assetLoaderContext, ITexture texture)
Represents a class passed as the custom data to the Asset Loader Context when loading Models from Zip...