Kursach_StealthAction/Assets/Tremble/Editor/AssetImporters/WadFileAssetImporter.cs
2026-10-11 19:16:11 +03:00

42 lines
1.3 KiB
C#

//
// This file is part of the Tremble package by Tiny Goose.
// Copyright (c) 2024-2026 TinyGoose Ltd., All Rights Reserved.
//
using UnityEditor.AssetImporters;
using UnityEngine;
using System.IO;
using UnityEditor;
namespace TinyGoose.Tremble.Editor
{
[ScriptedImporter(1, "wad", -1000)]
public class WadFileAssetImporter : ScriptedImporter
{
// -----------------------------------------------------------------------------------------------------------------------------
// Entry Point
// -----------------------------------------------------------------------------------------------------------------------------
public override void OnImportAsset(AssetImportContext ctx)
{
string assetName = Path.GetFileNameWithoutExtension(ctx.assetPath);
WadFileAsset wadAsset = ScriptableObject.CreateInstance<WadFileAsset>();
wadAsset.Modify(so =>
{
SerializedProperty materials = so.FindBackedProperty(nameof(wadAsset.MaterialNames));
WadParser parser = new(ctx.assetPath);
WadFile wadFile = parser.Parse();
foreach (WadEntry entry in wadFile.Entries)
{
materials.AppendArrayElement().stringValue = entry.Name;
}
});
wadAsset.name = assetName;
ctx.AddObjectToAsset(assetName, wadAsset);
ctx.SetMainObject(wadAsset);
}
}
}