示例#1
0
    private void OnGUI_GenNetWindow()
    {
        isClient = EditorGUILayout.Toggle("是否生成Client:", isClient);

        if (isClient)
        {
            type = "client";
        }
        else if (!isClient)
        {
            type = "server";
        }
        //一键全部生成
        GUI.skin.button.fixedWidth = 200;
        if (GUILayout.Button("一键生成所有Class"))
        {
            DeleteFileByURL(Application.dataPath + "/Code/Game/Protocol/RouteClass");
            DeleteFileByURL(Application.dataPath + "/Code/Game/Protocol/NetHelper");
            var dic = RouteJsonTool.StringToDic(true, routeFile);
            if (dic != null)
            {
                this.ShowNotification(new GUIContent("Succesed!"));
                CopyFile();
                AssetDatabase.Refresh();
            }
            else
            {
                this.ShowNotification(new GUIContent("Failed!"));
            }
        }
        pos = GUILayout.BeginScrollView(pos, GUILayout.Width(800));
        GUILayout.BeginVertical();
        if (!hasDone)
        {
            list = RouteJsonTool.StringToDic(false, routeFile);
            //将list按顺序排列
            //把未生成类的key给标红
            //TODO
            list.Sort();
            hasDone = true;
        }
        foreach (var key in list)
        {
            //根据NetHelper中的文件来确定是否已经生成对应的class
            path = Application.dataPath + "/Code/Game/Protocol";
            if (key.Contains('.'))
            {
                var arr       = key.Split('.');
                var file_Test = path + "/NetHelper/" + "NetHelper_" + arr[1] + ".cs";
                if (File.Exists(file_Test))
                {
                    if (File.ReadAllText(file_Test).Contains(arr[2]))
                    {
                        DrawOneProtocal(key, Color.green);
                    }
                    else
                    {
                        DrawOneProtocal(key, Color.red);
                    }
                }
                else
                {
                    DrawOneProtocal(key, Color.red);
                }
            }
            else
            {
                var file_Test = path + "/NetHelper/" + "NetHelper_" + key + ".cs";
                if (File.Exists(file_Test))
                {
                    DrawOneProtocal(key, Color.green);
                }
                else
                {
                    DrawOneProtocal(key, Color.red);
                }
            }
        }
        GUILayout.EndVertical();
        GUILayout.EndScrollView();
    }
示例#2
0
    private void DrawOneProtocal(string key, Color color)
    {
        GUILayout.BeginHorizontal();
        GUI.skin.label.fixedWidth = 350f;
        GUI.color = color;
        if (color == Color.red)
        {
            GUILayout.Label(key + "   (miss)");
        }
        else
        {
            GUILayout.Label(key);
        }

        Layout_DrawSeparatorV(Color.gray);
        GUILayout.Space(170);

        GUI.skin.button.fixedWidth = 100;
        var btn = GUILayout.Button("覆盖");

        if (btn)
        {
            //TODO
            if (color == Color.red)
            {
                this.ShowNotification(new GUIContent("Without File"));
            }
            else
            {
                if (RouteJsonTool.DicToOther_Editor(key, type))
                {
                    this.ShowNotification(new GUIContent("Succesed!"));
                    CopyFile();
                }
                else
                {
                    this.ShowNotification(new GUIContent("Failed!"));
                }
            }
            AssetDatabase.Refresh();
        }
        GUILayout.Space(50);
        if (GUILayout.Button("生成"))
        {
            if (color == Color.red)
            {
                if (RouteJsonTool.DicToOther_Editor(key, type))
                {
                    this.ShowNotification(new GUIContent("Succesed!"));
                    CopyFile();
                }
                else
                {
                    this.ShowNotification(new GUIContent("Failed!"));
                }
            }
            else
            {
                this.ShowNotification(new GUIContent("Already Producted"));
            }

            AssetDatabase.Refresh();
        }
        GUILayout.EndHorizontal();
        Layout_DrawSeparator(Color.gray);
    }