#pragma warning disable 672 using System; using System.IO; using TriLibCore.Interfaces; using TriLibCore.Mappers; using TriLibCore.Utils; using UnityEngine; namespace TriLibCore.Samples { /// /// Represents a class that finds textures at the given model base path. /// public class TextureMapperSample : TextureMapper { /// Tries to retrieve a Stream to the Texture native data based on the given context. /// The Asset Loader Context reference. Asset Loader Context contains the Model loading data. /// The source Texture to load the Stream from. /// Return the context containing the texture data. public override TextureLoadingContext Map(AssetLoaderContext assetLoaderContext, ITexture texture) { var finalPath = $"{assetLoaderContext.BasePath}/{FileUtils.GetFilename(texture.Filename)}"; if (File.Exists(finalPath)) { var textureLoadingContext = new TextureLoadingContext { Context = assetLoaderContext, Stream = File.OpenRead(finalPath), Texture = texture }; Debug.Log($"Found texture at: {finalPath}"); return textureLoadingContext; } throw new Exception($"Texture [{texture.Filename}] not found."); } } }