using System;
using System.IO;
using TriLibCore.Mappers;
using TriLibCore.Utils;
using UnityEngine;
namespace TriLibCore.Samples
{
///
/// Represents a class that finds external resources at the given model base path.
///
public class ExternalDataMapperSample : ExternalDataMapper
{
///
/// Tries to find the given external data source using the original resource filename and the context parameters.
///
/// The Asset Loader Context reference. Asset Loader Context contains the information used during the Model loading process, which is available to almost every Model processing method
/// The source data original filename.
/// The found data final Path.
/// The external data source Stream, if found. Otherwise null.
public override Stream Map(AssetLoaderContext assetLoaderContext, string originalFilename, out string finalPath)
{
finalPath = $"{assetLoaderContext.BasePath}/{FileUtils.GetFilename(originalFilename)}";
if (File.Exists(finalPath))
{
Debug.Log($"Found external file at: {finalPath}");
return File.OpenRead(finalPath);
}
throw new Exception($"File {originalFilename} not found.");
}
}
}