04.辅助工具.模块proto.odin版本

依赖tolua odin proto文件

C#脚本.CSHelpScript_Odin.cs

using Sirenix.OdinInspector;
using Sirenix.OdinInspector.Editor;
using Sirenix.Utilities;
using Sirenix.Utilities.Editor;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;
#region << 脚 本 注 释 >>
//作  用:    ModuleProtoHelpTool_Odin
//作  者:    曾思信
//创建时间:  2023/01/14
#endregion

namespace MEditor
{
    public enum ProtoViewEnum
    {
        Req_CS = 0,
        Res_SC = 1,
        Client_SendSC = 2,
        ViewScript = 3
    }

    public class ModuleProtoHelpTool : OdinEditorWindow
    {
        private string uiViewStr = @"--[[
@Description: 页面
@Author: 工具
@Date: Created in {2}
--]]
local UIView = require('UI.UIView')
--local Proxy{0}Module=require('{0}.Proxy{0}Module') 
--local {0}Manager=require('{0}.{0}Manager')
--local DialogTipManager=require('DialogTip.DialogTipManager')
--local TipManager=require('Tip.TipManager')
--local lang = require('Language.LanguageManager').GetText
--local {0}Manager = require('{0}.{0}Manager')
local {1} = fgui.window_class(UIView)

function {1}:OnLoadFinished()
  --self.uiComs = require('UI.Packages.{0}.UI_{1}'):OnConstruct(self.contentPane)--UIView.lua已有定义
end
--[[
local EventManager = require('Event.EventManager')
local GameEvent = require('Event.GameEvent')
function {1}:BindGlobalEvent()
    return{{
 {{GameEvent.{1},function()end,999}},
}}
end
--]]
function {1}:SetData(pDto)
end
function {1}:RefreshViewAll()
end
function {1}:OnShown()
   UIView.OnShown(self) 
end
function {1}:OnHide()
  UIView.OnHide(self)  
end
return {1}

--{1} = {{
--        [CLASS_NAME] = '{0}.{1}',
--        [PAKAGE_NAME] = '{0}',
--        [PANEL_NAME] = '{1}',
--        [PARET_LAYER] = UI_LAYER_MAIN_2,
--        [SORTING_ORDER] = 1,
--    }},

function Proxy{0}Module:Close{1}()
  UIManager.CloseWindow(CustomUIConfig.{1},true)
end
function Proxy{0}Module:Open{1}Data(data)
  UIManager.OpenWindow(CustomUIConfig.{1},function (code,view)view:SetData(data)end)
end
]]
";

        private string uiViewStr_Module = @"--[[
@Description: 页面
@Author: 工具
@Date: Created in {2}
--]]
local UIView = require('UI.UIView')
--local Proxy{0}Module=require('{0}.Proxy{0}Module') 
--local {0}Manager=require('{0}.{0}Manager')
--local DialogTipManager=require('DialogTip.DialogTipManager')
--local TipManager=require('Tip.TipManager')
--local lang = require('Language.LanguageManager').GetText
--local {0}Manager = require('{0}.{0}Manager')
local {1} = fgui.window_class(UIView)

function {1}:OnLoadFinished()
  --self.uiComs = require('UI.Packages.{0}.UI_{1}'):OnConstruct(self.contentPane)--UIView.lua已有定义
end
--[[
local EventManager = require('Event.EventManager')
local GameEvent = require('Event.GameEvent')
function {1}:BindGlobalEvent()    return{{ {{GameEvent.{1},function()end,999}}, }} end
--]]
function {1}:SetData(pDto)
end
function {1}:RefreshViewAll()
end
function {1}:OnShown()
   UIView.OnShown(self) 
end
function {1}:OnHide()
  UIView.OnHide(self)  
end
return {1}

--{1} = {{
--        [CLASS_NAME] = '{0}.{1}',
--        [PAKAGE_NAME] = '{0}',
--        [PANEL_NAME] = '{1}',
--        [PARET_LAYER] = UI_LAYER_MAIN_2,
--        [SORTING_ORDER] = 1,
--    }},

--local Proxy{0}Module=require('{0}.Proxy{0}Module')
--[[
@Description: 模块代理
@Author: 工具
@Date: Created in {2}
--]]
--[[ local Proxy{0}Module = {{}}
local CustomUIConfig = require('ViewConfig.CustomUIConfig')
local UIManager = require('UI.UIManager')
--local DialogTipManager=require('DialogTip.DialogTipManager')
--local TipManager=require('Tip.TipManager')
--local ProxyDialogTipModule = require('DialogTip.ProxyDialogTipModule')
--local CurrencyManager = require('Currency.CurrencyManager')
--local ItemTab = require('Tables.ItemConfig')
--local GameTab = require('Tables.GameConfig')

function Proxy{0}Module:Close{1}()
  UIManager.CloseWindow(CustomUIConfig.{1},true)
end
function Proxy{0}Module:Open{1}Data(data)
  UIManager.OpenWindow(CustomUIConfig.{1},function (code,view)view:SetData(data)end)
end
return Proxy{0}Module ]]

--[[
@Description: 模块Mgr
@Author: 工具
@Date: Created in {2}
--]]
--[[ local {0}Manager={{}}
local DialogTipManager=require('DialogTip.DialogTipManager')
local TipManager=require('Tip.TipManager')
local ProxyDialogTipModule = require('DialogTip.ProxyDialogTipModule')
local CurrencyManager = require('Currency.CurrencyManager')
local ItemTab = require('Tables.ItemConfig')
local GameTab = require('Tables.GameConfig')

function {0}Manager:Init()
end

----sc-**Res-start---

----sc-**Res-end---
 
function {0}Manager:Reset()
end

return {0}Manager ]]";

        private string uiViewRecvRes = @"ProtoComResponse:Regist(g_MsgID.{1}, function(pIsSuccess)
        self:RecvRes_{1}(pIsSuccess)
    end)
function Protocal{0}:RecvRes_{1}(pIsSuccess)
    if pIsSuccess then
    end
end";

        private string mProtoStartStr = @"--[[
@Description: 接口
@Author: ~
@Date: Created in {4}
--]]
local g_MsgID = g_MsgID
local Protocal{0} = {{}}
--local {0}Manager
function Protocal{0}:Init()
 --{0}Manager=require('{0}.{0}Manager')
    return {{
    {1}   }}
end
---cs--start---
{2}---cs--end---

---sc--end---
{3}---sc--end---
return Protocal{0}";

        private string mProtoSCMethod = @"---@{0}
function Protocal{1}:{2}(msg)
   --logerror('{2}' .. table.tostring(msg))
   --{1}Manager:Set{2}(msg) 
   --@{0}{2}
   --function {1}Manager:Set{2}(msg) end
end";

        public static string mProtoSCMethod_one = @"[g_MsgID.{0}] = '{0}',
---@{2}
function Protocal{1}:{0}(msg)
    --logerror('{0}' .. table.tostring(msg))
    --{1}Manager:Set{0}(msg)
    --@{2}{0} 
    --function {1}Manager:Set{0}(msg) end
end";

        public static string mProtoCSMethod = @"---@{4}
function Protocal{0}:{1}({2})
    local data = self.getData()
    {3}    self.send(g_MsgID.{1}, data)
end";




        [MenuItem("Tools/辅助工具/模块Proto工具 _F8")]
        private static void OpenProtoEditor()
        {
            var win = GetWindow<ModuleProtoHelpTool>("模块Proto工具");
            win.position = GUIHelper.GetEditorWindowRect().AlignCenter(700, 900);
        }

        [PropertyOrder(Order = 1), LabelText("模块名"), LabelWidth(100), HorizontalGroup("module")]
        public string mProtocalName = "league";

        [EnableIf("@mProtoFileNameList.Count>0")]
        [PropertyOrder(Order = 1f), ValueDropdown("mProtoFileNameList"), OnValueChanged("OnSelectProto"), HideLabel, HorizontalGroup("module", Width = 130)]
        public string mSelectProto;

        [EnableIf("@mProtoFileNameList.Count>0")]
        [PropertyOrder(Order = 1f), HorizontalGroup("module", Width = 80)]
        [Button("清空下拉框", ButtonSizes.Small)]
        public void ClearSelected()
        {
            PlayerPrefs.SetString("protocalNames_New", mProtocalName);
            mProtoFileNameList = new List<string>() { mProtocalName };
            mSelectProto = mProtocalName;
        }

        [Space(5)]
        [EnumToggleButtons, HideLabel, PropertyOrder(Order = 3)]
        public ProtoViewEnum ShowType = ProtoViewEnum.Req_CS;

        string mStr_PB_Path { get { return Application.dataPath + "/_Resources/Proto/"; } }

        [Space(5)]
        [ShowIf("@(ShowType==ProtoViewEnum.ViewScript)")]
        [PropertyOrder(Order = 4), LabelText("页面名字"), LabelWidth(100)]
        public string mViewNameInput;

        [Space(14)]
        [HorizontalGroup("view1", 150), PropertyOrder(Order = 4), LabelText("是否需要模块文字"), LabelWidth(105)]
        [ShowIf("@(ShowType==ProtoViewEnum.ViewScript)")]
        public bool mIsOnce = false;

        [HorizontalGroup("view1"), PropertyOrder(Order = 5)]
        [ShowIf("@(ShowType==ProtoViewEnum.ViewScript)")]
        [EnableIf("@ string.IsNullOrEmpty(mViewNameInput)==false")]
        [Button("生成View代码", ButtonSizes.Large)]
        public void LoadViewLua()//--view   {{转义   }}转义
        {
            if (mIsOnce)
            {
                var str = string.Format(uiViewStr_Module, mProtocalName, mViewNameInput, DateTime.Now.ToString());
                TipForCopy(str);
            }
            else
            {
                var str = string.Format(uiViewStr, mProtocalName, mViewNameInput, DateTime.Now.ToString());
                TipForCopy(str);
            }
        }

        void TipForCopy(string str)
        {
            UnityEngine.GUIUtility.systemCopyBuffer = "";
            UnityEngine.GUIUtility.systemCopyBuffer = str;
            ShowNotification(new GUIContent("已copy到剪切板了"));
        }

        [Space(12)]
        [ShowIf("@(ShowType==ProtoViewEnum.ViewScript)")]
        [LabelText("RecvRes***接口"), LabelWidth(105), HorizontalGroup("view2", 250), PropertyOrder(Order = 6)]
        public string RecvRes_Temp;

        //[Button("@\"Expression label: \" + DateTime.Now.ToString(\"HH:mm:ss\")")]
        [ShowIf("@(ShowType==ProtoViewEnum.ViewScript)")]
        [EnableIf("@ string.IsNullOrEmpty(RecvRes_Temp)==false"), GUIColor(0.8f, 0.1f, 0.3f), HorizontalGroup("view2"), PropertyOrder(Order = 6)]
        [Button(("@\"生成RecvRes_\"+ RecvRes_Temp"), ButtonSizes.Large)]
        void LoadSCRecvProto()//--sc
        {
            var str = string.Format(uiViewRecvRes, mProtocalName, RecvRes_Temp);
            TipForCopy(str);
        }

        [ShowIf("@(ShowType==ProtoViewEnum.Req_CS||ShowType==ProtoViewEnum.Res_SC)")]
        [Button("加载_proto", ButtonHeight = 25)]
        [HorizontalGroup("btn3"), PropertyOrder(Order = 4)]
        //[OnInspectorGUI]
        void OnClickLoad()//--sc
        {
            var hasFile = GetCSNameTypes();
            //if (hasFile && SC_Res_List.Count <= 0 && CS_Req_List.Count <= 0)
            if (hasFile)
            {
                SetListProNameList();

                GUI.FocusControl("");//让其失去焦点
            }
        }

        [ShowIf("@(ShowType==ProtoViewEnum.Req_CS||ShowType==ProtoViewEnum.Res_SC)")]
        [HorizontalGroup("btn3"), PropertyOrder(Order = 4), Button("打开_proto", ButtonHeight = 25)]
        void OnClickOpen()
        {
            var filePath = mStr_PB_Path + mProtocalName + ".proto";
            System.Diagnostics.Process.Start("notepad++.exe", filePath);
            GUI.FocusControl("");
        }

        [ShowIf("@(ShowType==ProtoViewEnum.Req_CS||ShowType==ProtoViewEnum.Res_SC)")]
        [Button("生成代码", ButtonHeight = 25), PropertyTooltip("点击后.代码会copy到系统粘贴板了")]
        [HorizontalGroup("btn3"), PropertyOrder(Order = 4)]
        [EnableIf("@CS_Req_List.Count>0||SC_Res_List.Count>0")]
        void OnClickGeneral()
        {
            var strAdd_pos1 = new StringBuilder();
            var strSC_pos3 = new StringBuilder();
            foreach (var item in SC_Res_List)
            {
                strAdd_pos1.AppendLine(string.Format(" [g_MsgID.{0}] = '{0}',", item.mInterfaceName));
                strSC_pos3.AppendLine(string.Format(mProtoSCMethod, item.mRemarks, mProtocalName, item.mInterfaceName));
            }
            var strCS_pos2 = new StringBuilder();
            foreach (var item in CS_Req_List)
            {
                strCS_pos2.AppendLine(item.CopyCS_Txt(true));
            }
            var str = string.Format(mProtoStartStr, mProtocalName, strAdd_pos1.ToString(), strCS_pos2.ToString(), strSC_pos3.ToString(), DateTime.Now.ToString());
            TipForCopy(str);
        }



        [Space(5)]
        [InfoBox("1.若bool填true或false.\r\n2.若msgID=nil,让前端git工程更新下,操作下[打包机同步Lua].\r\n3.若repeated就用冒号:分隔\r\n4.若是结构体,自行建table<->eg:要造DeviceInfo,则传{['modelName']='1',['gpuName']='1'}")]
        [ShowIf("@(SC_Res_List.Count>0||CS_Req_List.Count>0)&&(ShowType==ProtoViewEnum.Req_CS)"), PropertyOrder(Order = 6)]
        [TableList(ShowPaging = false, CellPadding = 5, IsReadOnly = true, DefaultMinColumnWidth = 350, AlwaysExpanded = true, HideToolbar = true)]
        public List<SomeCustom_CS> CS_Req_List = new List<SomeCustom_CS>();

        [Space(3)]
        [TextArea(42, 47), PropertyOrder(Order = 6), LabelText("发送数据到UnityEditor--仿后端下发数据给客户端 数据自行编辑")]
        [ShowIf("@(ShowType==ProtoViewEnum.Client_SendSC)")]
        public string mContentSC = @"接口;数据
        
步骤:-->
1.编辑好table数据  2.点击发送数据
        
使用场景  
1.等待 服务端 数据完善,,,,等不了的 可自行构建table下发给自己 
2.想自行构建一些特殊数据下发给自己的        
        
LoginRes;;;{
[""offset""] = 11,
[""roleBriefs""] = {
    [1] = {
        [""roleId""] = ""GRRSn5B00c"",
        [""name""] = ""66666"",
    },
},
[""resultCode""] = 0,
[""token""] = """",
[""userId""] = ""GRRSn5w00b"",
}";


        [PropertyOrder(Order = 6), LabelText("发送数据到Editor--仿后端下发数据给客户端 数据自行编辑")]
        [ShowIf("@(ShowType==ProtoViewEnum.Client_SendSC)")]
        [Button("发送仿数据给前端", ButtonHeight = 35), PropertyTooltip("得到一个响应")]
        [EnableIf("@mContentSC.Length>0")]
        public void SendSC()
        {
            LuaInterface.LuaState L = LuaClient.GetMainState();
            if (mContentSC.Contains(";;;"))
            {
                L.Call("ValueClickSendSCParams", mContentSC, true);
            }
            else
            {
                Debug.LogError("数据有问题!必须包含 分号 ;");
            }
        }

        [Space(5)]
        [PropertyOrder(Order = 6)]
        [ShowIf("@(SC_Res_List.Count>0||CS_Req_List.Count>0)&&(ShowType==ProtoViewEnum.Res_SC)")]
        [TableList(ShowPaging = false, CellPadding = 5, IsReadOnly = true, DefaultMinColumnWidth = 350, AlwaysExpanded = true, HideToolbar = true)]
        public List<SomeCustom_SC> SC_Res_List = new List<SomeCustom_SC>();

        bool GetCSNameTypes()
        {
            CS_Req_List.Clear();
            SC_Res_List.Clear();
            var tCSReqDic = new Dictionary<string, List<string>>();

            var tFilePath = mStr_PB_Path + mProtocalName + ".proto";
            if (File.Exists(tFilePath))
            {
                var tStr = File.ReadAllLines(tFilePath);
                bool isStartReq = false;
                string lastKey = string.Empty;
                string item = string.Empty;

                for (int indexReq = 0; indexReq < tStr.Length; indexReq++)
                {
                    item = tStr[indexReq];
                    if (item.Contains("Req"))
                    {
                        var reg = Regex.Replace(item, @"[\s]+", "~");
                        var value = reg.Split('~');
                        lastKey = value[1].Replace("{", "");
                        isStartReq = true;
                        if (tCSReqDic.ContainsKey(lastKey) == false)
                        {
                            tCSReqDic[lastKey] = new List<string>() { tStr[indexReq - 1] };
                        }
                    }
                    if (item.Contains("Res{"))
                    {
                        isStartReq = false;
                        var reg = Regex.Replace(item, @"[\s]+", "~");
                        var value = reg.Split('~');
                        lastKey = value[1].Replace("{", "");
                        SomeCustom_SC tClass = new SomeCustom_SC(tStr[indexReq - 1], lastKey, mProtocalName, (str) =>
                        {
                            ShowNotification(new GUIContent(str));
                        });
                        if (SC_Res_List.Contains(tClass) == false)
                        {
                            SC_Res_List.Add(tClass);
                        }
                    }
                    if (isStartReq)
                    {
                        if (item.Contains("repeated") || item.Contains("optional"))
                        {
                            var reg = Regex.Replace(item, @"[\s]+", "~");
                            var value = reg.Split('~');
                            if (tCSReqDic.ContainsKey(lastKey))
                            {
                                tCSReqDic[lastKey].Add(value[3] + ":" + value[1] + ":" + value[2]);//字段名字:单复数:类型                     
                            }
                        }
                    }
                    if (item.Equals("}") && isStartReq)
                    {
                        isStartReq = false;
                    }
                }
            }
            else
            {
                ShowNotification(new GUIContent("proto文件,没找到~"));
                return false;
            }
            foreach (var item in tCSReqDic)
            {
                CS_Req_List.Add(new SomeCustom_CS(item.Key, mProtocalName, item.Value, (str) => ShowNotification(new GUIContent(str))));
            }
            return true;
        }

        List<string> mProtoFileNameList = new List<string>();
        void OnSelectProto()
        {
            mProtocalName = mSelectProto;
            ShowNotification(new GUIContent("选择了" + mSelectProto + ",请点击加载"));
        }

        [OnInspectorInit]
        [HideLabel]
        void InitCreateData()
        {
            var manyNames = PlayerPrefs.GetString("protocalNames_New", "LeagueBoss");
            mProtoFileNameList = manyNames.Split(';').ToList();
            mSelectProto = mProtoFileNameList[0];
            mProtocalName = mSelectProto;
        }

        void SetListProNameList()
        {
            if (mProtoFileNameList.Contains(mProtocalName) == false)
                mProtoFileNameList.Insert(0, mProtocalName);

            for (int i = 0; i < mProtoFileNameList.Count; i++)
            {
                if (i > 10)
                    mProtoFileNameList.RemoveAt(i);
            }
            var str = string.Join(";", mProtoFileNameList);
            PlayerPrefs.SetString("protocalNames_New", str);
            GUIProtocalButtons();
        }

        void GUIProtocalButtons()
        {
            if (mProtoFileNameList != null && mProtoFileNameList.Count > 0)
            {
                for (int i = 0; i < mProtoFileNameList.Count; i++)
                {
                    if (GUILayout.Button(mProtoFileNameList[i], GUILayout.Height(20), GUILayout.MaxWidth(100)))
                    {
                        mProtocalName = mProtoFileNameList[i];
                    }
                }
            }
        }
    }

    [Serializable]
    public class SomeCustom_CS
    {
        [HideInInspector]
        public Action<string> mActionNotify;
        public SomeCustom_CS(string pInterfaceName, string pProtoFileName, List<string> pAllContent, Action<string> pAction)
        {
            this.mInterfaceName = pInterfaceName;
            this.mProtoFileName = pProtoFileName;
            this.mAllContents = pAllContent;
            this.mActionNotify = pAction;
            CreateData();
        }

        /// <summary>备注</summary>
        public string mRemarks { get; set; }

        [VerticalGroup("字段"), LabelWidth(220), LabelText("@ mRemarks")]
        public string mInput_InterfaceName;

        /// <summary>接口的名字 </summary>
        public string mInterfaceName { get; set; }

        /// <summary> **.proto 的 name</summary>
        public string mProtoFileName { get; set; }

        /// <summary> 第0位(注释)     第1位+ 字段名字:单复数:类型 </summary>
        public List<string> mAllContents { get; set; }

        Dictionary<int, bool> isHideDic = new Dictionary<int, bool>()
        {
            { 1,true},{ 2,true},{ 3,true},{ 4,true},{ 5,true},{ 6,true},{ 7,true},{ 8,true},{ 9,true},{ 10,true},{ 11,true},{ 12,true}
        };

        Dictionary<int, string> titleDic = new Dictionary<int, string>()
        {
            { 1,""},{ 2,""},{ 3,""},{ 4,""},{ 5,""},{ 6,""},{ 7,""},{ 8,""},{ 9,""},{ 10,""},{ 11,""},{ 12,""},
        };


        [VerticalGroup("字段"), LabelWidth(220), LabelText("@ (titleDic != null) ?  titleDic[1]:\"\""), HideIf("@ (isHideDic!=null)?isHideDic[1]:true")]
        public string FieldShow_1;
        [VerticalGroup("字段"), LabelWidth(220), LabelText("@ (titleDic != null) ? titleDic[2]:\"\""), HideIf("@ (isHideDic!=null)?isHideDic[2]:true")]
        public string FieldShow_2;
        [VerticalGroup("字段"), LabelWidth(220), LabelText("@ (titleDic != null) ? titleDic[3]:\"\""), HideIf("@ (isHideDic!=null)?isHideDic[3]:true")]
        public string FieldShow_3;

        [VerticalGroup("字段"), LabelWidth(220), LabelText("@ (titleDic != null) ? titleDic[4]:\"\""), HideIf("@ (isHideDic!=null)?isHideDic[4]:true")]
        public string FieldShow_4;
        [VerticalGroup("字段"), LabelWidth(220), LabelText("@ (titleDic != null) ?titleDic[5]:\"\""), HideIf("@ (isHideDic!=null)?isHideDic[5]:true")]
        public string FieldShow_5;
        [VerticalGroup("字段"), LabelWidth(220), LabelText("@ (titleDic != null) ?titleDic[6]:\"\""), HideIf("@ (isHideDic!=null)?isHideDic[6]:true")]
        public string FieldShow_6;

        [VerticalGroup("字段"), LabelWidth(220), LabelText("@ (titleDic != null) ?titleDic[7]:\"\""), HideIf("@ (isHideDic!=null)?isHideDic[7]:true")]
        public string FieldShow_7;
        [VerticalGroup("字段"), LabelWidth(220), LabelText("@ (titleDic != null) ?titleDic[8]:\"\""), HideIf("@ (isHideDic!=null)?isHideDic[8]:true")]
        public string FieldShow_8;
        [VerticalGroup("字段"), LabelWidth(220), LabelText("@ (titleDic != null) ?titleDic[9]:\"\""), HideIf("@ (isHideDic!=null)?isHideDic[9]:true")]
        public string FieldShow_9;

        [VerticalGroup("字段"), LabelWidth(220), LabelText("@ (titleDic != null) ?titleDic[10]:\"\""), HideIf("@ (isHideDic!=null)?isHideDic[10]:true")]
        public string FieldShow_10;
        [VerticalGroup("字段"), LabelWidth(220), LabelText("@ (titleDic != null) ?titleDic[11]:\"\""), HideIf("@ (isHideDic!=null)?isHideDic[11]:true")]
        public string FieldShow_11;
        [VerticalGroup("字段"), LabelWidth(220), LabelText("@ (titleDic != null) ?titleDic[12]:\"\""), HideIf("@ (isHideDic!=null)?isHideDic[12]:true")]
        public string FieldShow_12;


        [TableColumnWidth(60)]
        [Button("发送请求"), VerticalGroup("CS-->方法"), LabelWidth(220)]
        public void SendCS()
        {
            var tStr = new StringBuilder();
            tStr.Append(mInterfaceName);
            tStr.Append(";");
            for (int i = 1; i < mAllContents.Count; i++)
            {
                var list = mAllContents[i].Split(':');//   字段名字:单复数:类型    /// </summary>
                tStr.Append(list[0]);
                tStr.Append("-");
                tStr.Append(list[1]);
                tStr.Append("-");
                tStr.Append(list[2]);
                tStr.Append("-");
                tStr.Append(GetFieldValue(i));
                tStr.Append(";");
            }
            var str = tStr.ToString();
            Debug.Log(str);
            if (Application.isPlaying)
            {
                LuaInterface.LuaState L = LuaClient.GetMainState();
                L.Call("ValueClickSendCSParams", str, true);
            }
            else
            {
                if (mActionNotify != null)
                {
                    mActionNotify("你的Unity没运行,要登录呀");
                }
            }
        }
        string GetFieldValue(int i)
        {
            switch (i)
            {
                case 1:
                    return FieldShow_1;
                case 2:
                    return FieldShow_2;
                case 3:
                    return FieldShow_3;
                case 4:
                    return FieldShow_4;
                case 5:
                    return FieldShow_5;
                case 6:
                    return FieldShow_6;
                case 7:
                    return FieldShow_7;
                case 8:
                    return FieldShow_8;
                case 9:
                    return FieldShow_9;
                case 10:
                    return FieldShow_10;
                case 11:
                    return FieldShow_11;
                case 12:
                    return FieldShow_12;
            }
            return "";
        }

        [Button("copy-->生成代码CS"), VerticalGroup("CS-->方法"), LabelWidth(220)]
        public void CopyCS_Req()
        {
            CopyCS_Txt(false);
        }

        [HideInInspector]
        public string CopyCS_Txt(bool isReturnTxt = false)
        {

            string dataNames = "data.{0} = {0}";
            var tNames = new StringBuilder();
            var tDataIds = new StringBuilder();

            for (int i = 1; i < mAllContents.Count; i++)
            {
                var field = mAllContents[i].Split(':')[0];
                tDataIds.AppendLine(string.Format(dataNames, field));
                tNames.Append(field + ",");
            }
            var tStr2 = tNames.ToString().TrimEnd(',');
            string cs = string.Format(ModuleProtoHelpTool.mProtoCSMethod, mProtoFileName, mInterfaceName, tStr2, tDataIds.ToString(), mAllContents[0]);
            if (isReturnTxt)
            {
                return cs;
            }
            else
            {
                //Debug.LogError("9999  " + cs);
                //if (mActionNotify_CS != null)
                //{
                mActionNotify("代码已copy到系统粘贴板了");
                UnityEngine.GUIUtility.systemCopyBuffer = "";
                UnityEngine.GUIUtility.systemCopyBuffer = cs;
                //Debug.LogError("css5555  " + cs);
                //}
                return "";
            }
        }

        [HideInTables]
        private void CreateData()
        {
            mRemarks = mAllContents[0];
            mInput_InterfaceName = mInterfaceName;
            for (int i = 1; i < mAllContents.Count; i++)
            {
                var tSplits = mAllContents[i].Split(':');//第1位+ 字段名字:单复数:类型
                isHideDic[i] = false;
                titleDic[i] = string.Format("{0} ({1},{2})", tSplits[0], tSplits[1], tSplits[2]);
            }
        }
    }

    [Serializable]
    public class SomeCustom_SC
    {
        [HideInEditorMode]
        Action<string> mActionNotify;
        [HideInEditorMode]


        public SomeCustom_SC(string pRemarks, string pInterfaceName, string pProtoFileName, Action<string> pAction)
        {
            this.mRemarks = pRemarks;
            this.mInterfaceName = pInterfaceName;
            this.mProtoFileName = pProtoFileName;
            this.mActionNotify = pAction;
            CreateData();
        }

        /// <summary>备注    /// </summary>
        public string mRemarks { get; set; }

        /// <summary>接口的名字    /// </summary>
        public string mInterfaceName { get; set; }


        /// <summary>**.proto 的 name    /// </summary>
        public string mProtoFileName { get; set; }


        [VerticalGroup("接口"), LabelWidth(220)]
        [LabelText("@ mRemarks")]
        public string mInput_InterfaceName;


        [TableColumnWidth(60)]
        [Button("copy-->生成代码SC"), VerticalGroup("SC-->方法"), PropertyTooltip("点击后.代码会copy到系统粘贴板了")]
        public void CopySC_Res()
        {
            string value = string.Format(ModuleProtoHelpTool.mProtoSCMethod_one, mInterfaceName, mProtoFileName, mRemarks);

            UnityEngine.GUIUtility.systemCopyBuffer = "";
            UnityEngine.GUIUtility.systemCopyBuffer = value;

            if (mActionNotify != null)
            {
                mActionNotify("代码已copy到系统粘贴板了");
            }
        }

        [HideInTables]
        private void CreateData()
        {
            mInput_InterfaceName = mInterfaceName;
        }
    }

}

Lua脚本

function ValueClickSendSCParams(values)
    --values = 'RoleFightOrderPanelRes;{["totalDurability"] = 0,["time"] = 30,["refreshTime"] = 1666834931}'
    local strValues = string.split(values, ";;;")--这里直接用了  可以 不管性能了
    local msgId = g_MsgID[strValues[1]]
    local code = "local data = " .. strValues[2] .. " return data"
    local luaStr2Tab = load(code)
    if luaStr2Tab then
        local data = luaStr2Tab()
        local EventManager = require('Event.EventManager')
        local EventDefine = require("Event.EventDefine")
        EventManager.Dispatch(EventDefine.GLOBAL_EVENT_ON_NET_DATA, msgId, data, "")--这个是log
        EventManager.Dispatch(EventDefine.GLOBAL_EVENT_ON_NET_DATA_F8, msgId, data, "")--这个 protocal**.lua 监听
    else
        logerror("数据不合理,确定是个table?")
        logerror(values)
    end
end

function ValueClickSendCSParams(values)
    local dataTest = {}
    local strValues = string.split(values, ";")--这里直接用了  可以 不管性能了
    local count = #strValues - 1

    for i = 2, count do
        local item = string.split(strValues[i], "-")
        local optionalRepeated = item[2]
        if item[3] == "int32" or item[3] == "double" then
            if optionalRepeated == "repeated" then
                local tmpTab = {}
                for val in string.gmatch(item[4], "([^:]+)") do
                    table.insert(tmpTab, tonumber(val))
                end
                dataTest[item[1]] = tmpTab
            else
                dataTest[item[1]] = tonumber(item[4])
            end
        elseif item[3] == "string" then
            if optionalRepeated == "repeated" then
                local tmpTab = {}
                for val in string.gmatch(item[4], "([^:]+)") do
                    table.insert(tmpTab, val)
                end
                dataTest[item[1]] = (tmpTab)
            else
                dataTest[item[1]] = item[4]
            end
        elseif item[3] == "bool" then
            dataTest[item[1]] = (item[4] == "true" and true or false)
        else
            local isTab = string.find(item[4], "{")
            if isTab then
                local code = "local data = " .. item[4] .. " return data"
                local luaStr2Tab = load(code)
                if luaStr2Tab then
                    local data = luaStr2Tab()
                    dataTest[item[1]] = data
                end
            end
        end
    end

    local msgId = g_MsgID[strValues[1]]
    local NetManager = require("Net.NetManager")
    NetManager.GetInstance():SendData(msgId, dataTest)
end

Proto文件

package com.manling.common.protobuf.proto;
option java_package = "com.manling.common.protobuf.proto";
option java_outer_classname = "ProtoLeagueBoss";
option optimize_for = SPEED;

import "LeagueBossCollectExtraInfo.proto";
import "PrecisePosition.proto";


/**/
message LeagueBossHpRes{
    /*msgId = 10936;*/
    /*首领cfgId*/
    optional int32 bossId = 1;
    /*首领uid*/
    optional string bossUId = 2;
    /*当前血量*/
    optional int32 hp = 3;
    /*最大血量*/
    optional int32 hpMax = 4;
}


/*创建联盟BOSS*/
message LeagueBossCreateReq{
    /*msgId = 11167;*/
    /*创建坐标点*/
    optional PrecisePosition position = 1;
}


/*联盟BOSS开启喂食*/
message LeagueBossOpenFeedReq{
    /*msgId = 11169;*/
}


/*联盟BOSS攻击排行*/
message LeagueBossAttackRankRes{
    /*msgId = 11177;*/
    /*联盟BOSS攻击伤害排行*/
    repeated LeagueBossAttackRankInfo leagueBossAttackRankInfos = 1;
}


/**/
message LeagueBossAttackRankInfo{
    /*msgId = 11178;*/
    /*角色ID*/
    optional string roleId = 1;
    /*角色名称*/
    optional string roleName = 2;
    /*角色输出伤害*/
    optional double attackHp = 3;
}


/*联盟boss挑战结束信息*/
message LeagueBossFinishRes{
    /*msgId = 11180;*/
    /*参与奖励*/
    optional string roleReward = 1;
    /*联盟奖励*/
    optional string leagueReward = 2;
    /*当前是否双倍奖励阶段TRUE:是FALSE:否*/
    optional bool doubleReward = 3;
}


/**/
message LeagueBossFeedRes{
    /*msgId = 11181;*/
    /*唯一ID*/
    optional string uid = 2;
    /*当前饱食度*/
    optional int32 currentFeed = 3;
}


/*当前联盟BOSS的位置*/
message LeagueBossPosRes{
    /*msgId = 11223;*/
    /*当前联盟BOSS的位置*/
    optional PrecisePosition pos = 1;
    /*联盟BOSS当前的状态对应枚举LeagueBossStateEnum*/
    optional int32 state = 2;
    /*联盟BOSSUID*/
    optional string leagueBossUid = 3;
}


/*联盟BOSS部队状态*/
message LeagueBossTroopStateRes{
    /*msgId = 11225;*/
    /*部队ID*/
    optional string troopId = 1;
    /*联盟BOSS采集扩展信息*/
    optional LeagueBossCollectExtraInfo leagueBossCollectExtraInfo = 3;
}


/*联盟boss玩家可领奖次数*/
message LeagueBossRoleTimeRes{
    /*msgId = 11403;*/
    /*剩余次数*/
    optional int32 time = 1;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值