示例#1
0
    public static void GenAutoComplete()
    {
        s_api = new LuaApi();
        s_apiIdx.Clear();
        s_apiTypeIdx.Clear();

        //收集要生成的类
        List <ToLuaMenu.BindType> btList = new List <ToLuaMenu.BindType>();

        allTypes.Clear();
        ToLuaExport.allTypes.Clear();
        ToLuaExport.allTypes.AddRange(ToLuaMenu.baseType);
        ToLuaExport.allTypes.AddRange(CustomSettings.staticClassTypes);
        for (int i = 0; i < ToLuaExport.allTypes.Count; i++)
        {
            btList.Add(new ToLuaMenu.BindType(ToLuaExport.allTypes[i]));
        }
        foreach (var bt in CustomSettings.customTypeList)
        {
            if (ToLuaExport.allTypes.Contains(bt.type))
            {
                continue;
            }
            ToLuaExport.allTypes.Add(bt.type);
            btList.Add(bt);
        }
        GenBindTypes(btList.ToArray(), false);
        foreach (var bt in allTypes)//做最后的检查,进一步排除一些类
        {
            if (bt.type.IsInterface && bt.type != typeof(System.Collections.IEnumerator))
            {
                continue;
            }
            s_apiTypeIdx[bt.type] = bt;
        }
        //一些类需要手动加
        {
            ToLuaMenu.BindType bt = new ToLuaMenu.BindType(typeof(Array));
            s_apiTypeIdx[bt.type] = bt;
            GetClassApi("System.Collections.IEnumerable").AddMethod("GetEnumerator", "()", "System.Collections.IEnumerator", "System.Collections.IEnumerator");
        }


        //生成信息
        foreach (var bt in s_apiTypeIdx.Values)
        {
            GenApi(bt);
        }

        //信息转lua类文件
        ToLuaExport.allTypes.Clear();
        string s;

        if (!LuaUtil.TryToLua(s_api.childs, out s))
        {
            return;
        }
        s = "return " + s;
        string path = LuaConst.zbsDir;

        path = path.Replace("lualibs/mobdebug", "api/lua/gameApiGen.lua");
        System.IO.File.WriteAllText(path, s, System.Text.Encoding.UTF8);
        Debug.Log("生成自动提示文件成功:" + path);
    }