public static void CreateViewCS(List <RegistViewItem> itemList, string goName, string root)
        {
            MyClass mc = new MyClass("View_" + goName + ":AViewBase");

            mc.AddNameSpace(new string[2] {
                "BDFramework.UI", "UnityEngine"
            });
            mc.SetSelfNameSpace("Code.Game.Windows");
            foreach (RegistViewItem item in itemList)
            {
                MyField f = new MyField();
                f.SetType(GetUIType(item.gameObject));
                f.SetFieldName(item.gameObject.name);
                if (item.IsBindPath)
                {
                    f.AddAttribute(GetBindPath(item.gameObject, root));
                }
                string tp = GetBindDataName(item);
                if (!string.IsNullOrEmpty(tp))
                {
                    f.AddAttribute(tp);
                }
                mc.AddField(f);
            }

            MyMethod construct = new MyMethod();

            construct.OverwriteContent(@"//[Note]
        public  [method name](Transform t, DataDrive_Service service) : base(t, service)
        {
            
        }");
            construct.SetMethSign(null, "View_" + goName, null);
            mc.AddMethod(construct);

            MyMethod bindData = new MyMethod();

            bindData.OverwriteContent(@"//[Note]
        public override void BindModel()
        {
            base.BindModel();
        }");
            mc.AddMethod(bindData);
            string path = Application.dataPath + createPath;

            if (!Directory.Exists(path))
            {
                Debug.LogError(string.Format("文件夹不存在!路径:{0}", path));
                return;
            }
            path = path + "View_" + goName + ".cs";
            File.WriteAllText(path, mc.ToString());
            Debug.Log(string.Format("生成成功!路径:{0}", path));
        }
Exemple #2
0
    private static void ProductClass_Message(List <Array> listArr, List <string> listStr, string IclassName, string gate)
    {
        var    classNameArr  = listArr[0];
        var    className     = classNameArr.GetValue(classNameArr.Length - 1);
        string gateClassName = "";
        string result        = "";
        string gateFile      = "";

        if (gate.Contains('.'))
        {
            var gateArr = gate.Split('.');
            //className = /*IclassName + gateArr[1] + "_" + */className;
            gateClassName = IclassName + gateArr[1];
            gateFile      = "D:/TestClass/" + gateClassName + ".cs";

            if (!File.Exists(gateFile))
            {
                MyClass gateClass = new MyClass(gateClassName);
                gateClass.AddNameSpace("System");
                result = gateClass.ToString();
            }
            else
            {
                result   = File.ReadAllText(gateFile).ToString();
                gateFile = "D:/TestClass/" + gateClassName + ".cs";
            }
        }
        else
        {
            //className = IclassName + className;
            gateClassName = gate;
            gateFile      = "D:/TestClass/" + IclassName + gateClassName + ".cs";
        }
        MyClass c            = new MyClass(className.ToString());
        var     subClassName = "";

        for (int i = 1; i < listArr.Count; i++)
        {
            var arr = listArr[i];
            subClassName = arr.GetValue(0).ToString();
            MyClass subClass = new MyClass(subClassName);

            for (int n = 1; n < arr.Length; n++)
            {
                var f = new MyField();
                //if(n == 1)
                //{
                //    field = string.Format("public {0};", arr.GetValue(n));
                //}
                //else
                //{
                //    field = string.Format("public {0};", arr.GetValue(n));
                //}
                string field = string.Format("public {0};", arr.GetValue(n));
                f.SetContent(field);
                subClass.AddField(f);
            }
            c.AddClass(subClass);
        }
        //添加field
        if (listStr.Count > 1)
        {
            for (int i = 0; i < listStr.Count; i++)
            {
                //先判断类型
                var    f        = new MyField();
                string field    = "";
                var    arrField = listStr[i].Split(' ');
                if (arrField[0] == subClassName)
                {
                    var str = listStr[i].Insert(listStr[i].LastIndexOf(' '), "[]");
                    field = string.Format("public {0};", str);
                }
                else
                {
                    field = string.Format("public {0};", listStr[i]);
                }
                //if (i == 0)
                //{
                //    field = string.Format("public {0};", listStr[i]);
                //}
                //else
                //{
                //    field = string.Format("public {0};", listStr[i]);
                //}
                f.SetContent(field);
                c.AddField(f);
            }
        }
        var code = c.ToString();

        if (gate.Contains('.'))
        {
            result = result.Insert(result.LastIndexOf('}'), code);
        }
        else
        {
            result = code;
        }
        var files = path + "/RouteClass/Response_" + c.Name + ".cs";

        if (File.Exists(files))
        {
            File.Delete(files);
        }
        File.WriteAllText(gateFile, result);
        //AssetDatabase.Refresh();
        //ProductMethodClass_All(c, gate, listStr, IclassName);
        ProductMethodClass_Now(className.ToString(), gate, listStr, IclassName);
    }
Exemple #3
0
    //创建类_Client
    private static void ProductClass_NoMessage(List <string> strList, string IclassName, string gate)
    {
        var    className     = "";
        var    gateClassName = "";
        var    result        = "";
        string gateFile      = "";

        if (gate.Contains('.'))
        {
            var gateArr = gate.Split('.');
            className     = /*IclassName + gateArr[1] + "_" + */ strList[0];
            gateClassName = IclassName + gateArr[1];
            gateFile      = "D:/TestClass/" + gateClassName + ".cs";
            if (!File.Exists(gateFile))
            {
                MyClass gateClass = new MyClass(gateClassName);
                gateClass.AddNameSpace("System");
                result = gateClass.ToString();
            }
            else
            {
                result = File.ReadAllText(gateFile).ToString();
            }
        }
        else
        {
            className     = IclassName + strList[0];
            gateClassName = gate;
            gateFile      = "D:/TestClass/" + IclassName + gateClassName + ".cs";
        }
        //if(strList.Count)

        //c.AddNameSpace("System");
        //添加field
        if (strList.Count > 1)
        {
            MyClass c = new MyClass(className);
            for (int i = 1; i < strList.Count; i++)
            {
                //先判断类型
                var    f = new MyField();
                string field;
                if (i == 1)
                {
                    field = string.Format("public {0};", strList[i]);
                }
                else
                {
                    field = string.Format("public {0};", strList[i]);
                }
                f.SetContent(field);
                c.AddField(f);
            }
            var code = c.ToString();
            if (gate.Contains('.'))
            {
                result = result.Insert(result.LastIndexOf('}'), code);
            }
            else
            {
                //Debug.Log(className);
                result = code;
            }
        }


        //result = result.Insert(result.LastIndexOf('}'),code);
        var dir = Path.GetDirectoryName(path + "/RouteClass/");

        if (Directory.Exists(dir) == false)
        {
            Directory.CreateDirectory(dir);
        }

        var files = path + "/RouteClass/" + className + ".cs";

        if (File.Exists(files))
        {
            File.Delete(files);
        }

        //ProductMethodClass(c, gate, strList,IclassName);
        ProductMethodClass_Now(className, gate, strList, IclassName);
        File.WriteAllText(gateFile, result);
    }