using System.IO;
using System.Reflection;
using UnityEditor.AssetImporters;
namespace UnityEditor.Build.Pipeline.Tests
{
///
/// Minimal non-primary artifact producer for .
/// PreviewImporter paths were empty under batch test runs; scripted importer output is stable for .
/// Release 6000.x: write via so artifacts are listed. Trunk/UDS: SetOutputArtifactFile is required for that listing; it is resolved at runtime so this project still compiles against 6000.x.
///
[ScriptedImporter(1, "uum131143_virt")]
public sealed class VirtualArtifactSerializationIndexTestImporter : ScriptedImporter
{
static readonly MethodInfo s_SetOutputArtifactFile = typeof(AssetImportContext).GetMethod(
"SetOutputArtifactFile",
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
null,
new[] { typeof(string), typeof(string) },
null);
///
/// Writes the imported file out as a single extra artifact file so the asset resolves to a path under
/// VirtualArtifacts/Extra/, using SetOutputArtifactFile when the running editor exposes it
/// and falling back to otherwise.
///
/// Import context supplied by the asset pipeline for the asset being imported.
public override void OnImportAsset(AssetImportContext ctx)
{
if (s_SetOutputArtifactFile != null)
{
s_SetOutputArtifactFile.Invoke(ctx, new object[] { "bin", ctx.assetPath });
return;
}
string outPath = ctx.GetOutputArtifactFilePath("bin");
if (!string.IsNullOrEmpty(outPath))
File.Copy(ctx.assetPath, outPath, overwrite: true);
}
}
}