TextureMapperSample.cs 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. #pragma warning disable 672
  2. using System;
  3. using System.IO;
  4. using TriLibCore.Interfaces;
  5. using TriLibCore.Mappers;
  6. using TriLibCore.Utils;
  7. using UnityEngine;
  8. namespace TriLibCore.Samples
  9. {
  10. /// <summary>
  11. /// Represents a class that finds textures at the given model base path.
  12. /// </summary>
  13. public class TextureMapperSample : TextureMapper
  14. {
  15. /// <summary>Tries to retrieve a Stream to the Texture native data based on the given context.</summary>
  16. public override void Map(TextureLoadingContext textureLoadingContext)
  17. {
  18. var finalPath = $"{textureLoadingContext.Context.BasePath}/{FileUtils.GetFilename(textureLoadingContext.Texture.Filename)}";
  19. if (File.Exists(finalPath))
  20. {
  21. textureLoadingContext.Stream = File.OpenRead(finalPath);
  22. Debug.Log($"Found texture at: {finalPath}");
  23. return;
  24. }
  25. throw new Exception($"Texture [{textureLoadingContext.Texture.Filename}] not found.");
  26. }
  27. }
  28. }