コード例 #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);
    }