﻿using UnityEditor;
using UnityEngine;

namespace JLGames.RocketDriver.Editor
{
    public class LuaImporter : AssetPostprocessor
    {
        public static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            // 遍历所有导入的资源
            foreach (var assetPath in importedAssets)
            {
                // 如果资源是.lua文件
                if (assetPath.EndsWith(".lua") || assetPath.EndsWith(".lua.txt") || assetPath.EndsWith(".lua.bytes"))
                {
                    // 获取资源的导入器
                    var importer = AssetImporter.GetAtPath(assetPath);
                    if (importer == null)
                    {
                        Debug.LogError("Failed to get importer!");
                        continue;
                    }

                    // 修改资源的导入设置，将其识别为TextAsset类型，但不改变其后缀名
                    importer.assetBundleName = "lua";
                    importer.userData = "This is a lua file.";
//                    importer.SetAssetBundleVariant("bytes");
                }
            }
        }
    }
}