/// <summary>
    /// 生成LuaPanel
    /// </summary>
    /// <param name="document"></param>
    private void GetLuaPanelScript(LuaDocumentNode document)
    {
        var panelName  = $"{gameObject.name}Panel";
        var luaUIPanel = gameObject.GetComponent <MLuaUIPanel>();

        if (luaUIPanel == null)
        {
            EditorUtility.DisplayDialog("导出错误", "目标找不到LuaUIPanel", "ok");
            return;
        }

        document.ModelNode = new LuaModelNode($"UI.{panelName}");
        document.RemoveFunction("Bind");

        //Bind函数
        var bindFunction = new LuaFunctionNode("Bind", LuaMemberType.Global, new List <string>()
        {
            "ctrl"
        },
                                               new List <LuaBaseStatementNode>());

        document.AddFunction(bindFunction);

        bindFunction.statementNodes.Add(new LuaScriptStatementNode("--dont override this function"));
        bindFunction.statementNodes.Add(new LuaScriptStatementNode("local l_panel = {}"));
        bindFunction.statementNodes.Add(new LuaScriptStatementNode("l_panel.PanelRef = ctrl.uObj:GetComponent(\"MLuaUIPanel\")"));

        Dictionary <string, string> comRefsCodes = LuaUIGroupEditor.GetComRefsCodes(luaUIPanel.ComRefs);

        foreach (var item in comRefsCodes)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("l_panel.");
            builder.Append(item.Key);
            if (!string.IsNullOrEmpty(item.Value))
            {
                builder.Append(" = l_panel.PanelRef.");
                builder.Append(item.Value);
            }
            var getComRefStatement = new LuaScriptStatementNode(builder.ToString());
            bindFunction.statementNodes.Add(getComRefStatement);
        }

        var groupsCodes = LuaUIGroupEditor.GetGroupsCodes(luaUIPanel.Groups, "l_panel.", " = l_panel.PanelRef.");

        foreach (var item in groupsCodes)
        {
            var getComRefStatement = new LuaScriptStatementNode(item.Key + item.Value);
            bindFunction.statementNodes.Add(getComRefStatement);
        }

        //返回代码
        bindFunction.statementNodes.Add(new LuaScriptStatementNode("return l_panel"));

        MFileEx.SaveText(document.ToString(), LuaPanelPath);
    }
    private void ShowCreateScriptBtn()
    {
        GUILayout.Space(20);
        GUILayout.BeginHorizontal();
        if (GUILayout.Button("创建LuaPanel代码", GUILayout.Height(20)))
        {
            TryGenScript(LuaPanelPath, GetLuaPanelScript);
            UpdateConst();

            LuaUIGroupEditor.CreateTemplateWithPanel(uiPanel.Groups);
        }
        if (GUILayout.Button("创建LuaMgr代码", GUILayout.Height(20)))
        {
            //GetLuaModelScript();
            //UIModelManagerWindow.NeedRefreshLuaDocument = true;
            // UpdateConst();
        }
        if (!uiPanel.IsHandler)
        {
            if (GUILayout.Button("创建LuaCtrl代码", GUILayout.Height(20)))
            {
                TryGenScript(LuaCtrlPath, GetLuaCtrlScript);
                UpdateConst();
            }
        }
        else
        {
            if (GUILayout.Button("创建LuaHandler代码", GUILayout.Height(20)))
            {
                TryGenScript(LuaHandlerPath, GetLuaHandlerScript);
                UpdateConst();
            }
        }
        GUILayout.EndHorizontal();
        if (GUILayout.Button("创建所有Lua代码", GUILayout.Height(20)))
        {
            TryGenScript(LuaPanelPath, GetLuaPanelScript);
            GetLuaModelScript();
            if (uiPanel.IsHandler)
            {
                TryGenScript(LuaHandlerPath, GetLuaHandlerScript);
            }
            else
            {
                TryGenScript(LuaCtrlPath, GetLuaCtrlScript);
            }
            UpdateConst();
        }
    }
 /// <summary>
 /// 找到所有com
 /// </summary>
 void FindAllCom()
 {
     LuaUIGroupEditor.FillComponents(gameObject, ref uiPanel.Groups, ref uiPanel.ComRefs);
 }