using UnityEngine;
using UnityEditor;
using System.IO;

public class GenGameRegister{
    public static string AssetsRoot = Application.dataPath.Replace("\\", "/") + "/"; //F:/repos/ihuman-art/app/Assets/

    [MenuItem("Tool/Game.GenGameRegister", false)]
    [Tooltip("生成 GameSceneRegister.lua 测试")]
    public static void Gen()
    {
        string destFile = AssetsRoot + "app/src/scenes/game/GameSceneRegister.lua";
        var registerFiles = Directory.GetFiles(AssetsRoot+ "gamesrc", "*register.lua", SearchOption.AllDirectories);
        //遍历 files, 把内容拼接起来，生成 destFile
        string destDir = Path.GetDirectoryName(destFile);
        if (!Directory.Exists(destDir))
        {
            Directory.CreateDirectory(destDir);
        }

        using (StreamWriter writer = new StreamWriter(destFile))
        {
            foreach (string file in registerFiles)
            {
                using (StreamReader reader = new StreamReader(file))
                {
                    writer.Write(reader.ReadToEnd()+"\n");
                }
            }
        }
        Debug.Log("GenGameRegister.Gen Suc");
    }
}