Пример #1
0
        public static void CreateWindowCS(string goName, string prefabName)
        {
            MyClass mc = new MyClass("Window_" + goName + ": AWindow ");

            mc.AddAttribute(string.Format("UI(0,\"{0}\")", "Windows/" + prefabName));
            mc.AddNameSpace(new string[3] {
                "BDFramework.UI", "UnityEngine", "BDFramework.UI"
            });
            MyMethod construct = new MyMethod();

            construct.OverwriteContent(@"//[Note]
        public  [method name](string path) : base(path)
        {
            
        }");
            construct.SetMethSign(null, "Window_" + goName, null);
            mc.AddMethod(construct);
            MyMethod init = new MyMethod();

            init.OverwriteContent(overrideContent);
            init.SetMethSign(null, "Init", null);
            init.SetMethodContent("base.Init();");
            mc.AddMethod(init);

            MyMethod close = new MyMethod();

            close.OverwriteContent(overrideContent);
            close.SetMethSign(null, "Close", null);
            close.SetMethodContent("base.Close();");
            mc.AddMethod(close);
            MyMethod open = new MyMethod();

            open.OverwriteContent(overrideContent);
            open.SetMethSign(null, "Open", null);
            open.SetMethodContent("base.Open();");
            mc.AddMethod(open);

            MyMethod destroy = new MyMethod();

            destroy.OverwriteContent(overrideContent);
            destroy.SetMethSign(null, "Destroy", null);
            destroy.SetMethodContent("base.Destroy();");
            mc.AddMethod(destroy);

            string path = Application.dataPath + windowPath;

            if (!Directory.Exists(path))
            {
                Debug.LogError(string.Format("文件夹不存在!路径:{0}", path));
                return;
            }
            path = path + "Window_" + goName + ".cs";
            File.WriteAllText(path, mc.ToString());
            Debug.Log(string.Format("生成成功!路径:{0}", path));
        }
Пример #2
0
        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));
        }
Пример #3
0
        public static void CreateContrlCS(List <RegistViewItem> itemList, string goName)
        {
            MyClass mc = new MyClass("Contrl_" + goName + ":AViewContrlBase");

            mc.AddNameSpace(new string[2] {
                "BDFramework.UI", "UnityEngine"
            });
            mc.SetSelfNameSpace("Code.Game.Windows.MCX"); MyMethod construct = new MyMethod();
            construct.OverwriteContent(@"//[Note]
        public [method name](DataDrive_Service data) : base(data)
        {
            
        } ");
            construct.SetMethSign(null, "Contrl_" + goName, null);
            mc.AddMethod(construct);
            foreach (RegistViewItem item in itemList)
            {
                if (string.IsNullOrEmpty(item.BindDataName))
                {
                    continue;
                }
                Type     t = GetUIType(item.gameObject);
                MyMethod bindData = new MyMethod();
                string   methodName = ""; string methodParams = "";
                if (t.Equals(typeof(UnityEngine.UI.Button)))
                {
                    methodName   = "OnClick_" + item.name;
                    methodParams = "";
                }
                else if (t.Equals(typeof(UnityEngine.UI.Slider)))
                {
                    methodName   = "OnValueChange_" + item.name;
                    methodParams = "float value";
                }
                else if (t.Equals(typeof(UnityEngine.UI.Scrollbar)))
                {
                    methodName   = "OnValueChange_" + item.name;
                    methodParams = "float value";
                }
                else
                {
                    methodName   = "On_" + item.name;
                    methodParams = "";
                }
                bindData.OverwriteContent(@"//[Note]
                private [return type] [method name] ([params])
                {
                   [method content]
                }
                ");
                bindData.SetMethSign(null, methodName, methodParams);
                bindData.SetMethodContent(string.Format("Debug.Log(\"use {0}\");", item.name));
                mc.AddMethod(bindData);
            }


            string path = Application.dataPath + createPath;

            if (!Directory.Exists(path))
            {
                Debug.LogError(string.Format("文件夹不存在!路径:{0}", path));
                return;
            }
            path = path + "Contrl_" + goName + ".cs";
            File.WriteAllText(path, mc.ToString());
            Debug.Log(string.Format("生成成功!路径:{0}", path));
        }
Пример #4
0
    //创建类方法
    //MyClassList

    private static void ProductMethodClass_Now(string subClassName, string gate, List <string> strList, string IclassName)
    {
        string className = "NetHelper_";

        if (IclassName == "Request_")
        {
            var arr = gate.Split('.');
            className = className + arr[1];
        }
        else if (IclassName == "Response_")
        {
            if (gate.Contains('.'))
            {
                return;
            }
            else
            {
                className = className + gate;
            }
        }
        MyClass mc = new MyClass(className);
        //var file = path + "/RouteClass" + mc.Name + ".cs";
        var dir_Test = "D:/TestClass/";

        if (Directory.Exists(dir_Test) == false)
        {
            Directory.CreateDirectory(dir_Test);
        }
        var file = "D:/TestClass/" + mc.Name + ".cs";

        if (!File.Exists(file))
        {
            mc.AddNameSpace("System");
            mc.AddNameSpace("MyJson");
            mc.AddNameSpace("System.Linq");
        }
        //用来添加方法体
        MyMethod m        = null;
        MyMethod m_Remove = null;

        if (IclassName == "Request_")
        {
            m = CreateMethod_Client(IclassName, gate, strList);
        }
        else
        {
            m        = CreateMethod_Server(subClassName, gate, strList, false);
            m_Remove = CreateMethod_Server(subClassName, gate, strList, true);
        }
        mc.AddMethod(m);
        if (m_Remove != null)
        {
            mc.AddMethod(m_Remove);
        }

        var    code   = mc.ToString();
        string result = "";

        if (File.Exists(file))
        {
            //File.Delete(file);
            //将当前类插入到最后一个“}”之前
            var str = File.ReadAllText(file).ToString();
            code = m.ToString();
            if (str.Contains(code))
            {
                result = str;
            }
            else
            {
                result = str.Insert(str.LastIndexOf('}'), code);
            }
        }
        else
        {
            mc.AddMethod(m);
            result = code;
        }
        var dir = Path.GetDirectoryName(path + "/NetHelper/");

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

        //File.WriteAllText(path + "/NetHelper/" + mc.Name + ".cs", result);
        File.WriteAllText("D:/TestClass/" + mc.Name + ".cs", result);
    }
Пример #5
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);
    }
Пример #6
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);
    }