public static void Write(string name, string scriptsFolder, string scriptsNamespace)
        {
            var scriptFile = scriptsFolder + "/{0}Data.cs".FillFormat(name);

            var writer = File.CreateText(scriptFile);

            var codeWriter = new FileCodeWriter(writer);

            if (!scriptsNamespace.IsNotNull() || scriptsNamespace.Equals(""))
            {
                scriptsNamespace = "UGUIFramework";
            }

            var rootCode = new RootCode()
                           .Using("UnityEngine")
                           .Using("UnityEngine.UI")
                           .Using("UGUIFramework")
                           .EmptyLine()
                           .Namespace(scriptsNamespace, nsScope =>
            {
                nsScope.Class(name + "Data", null, false, false, classScope =>
                {
                    classScope.Custom("protected " + name + " window;");
                    classScope.EmptyLine();
                    classScope.CustomScope("public " + name + "Data(" + name + " window)", false, (function) =>
                    {
                        function.Custom("this.window = window;");
                    });
                });
            });

            rootCode.Gen(codeWriter);
            codeWriter.Dispose();
        }
        public static void Write(string name, string scriptsFolder, string scriptsNamespace)
        {
            var scriptFile = scriptsFolder + "/{0}.Designer.cs".FillFormat(name);

            var writer = File.CreateText(scriptFile);

            var codeWriter = new FileCodeWriter(writer);

            if (!scriptsNamespace.IsNotNull() || scriptsNamespace.Equals(""))
            {
                scriptsNamespace = "UGUIFramework";
            }

            var rootCode = new RootCode()
                           .Using("UnityEngine")
                           .Using("UnityEngine.UI")
                           .Using("UGUIFramework")
                           .EmptyLine()
                           .Namespace(scriptsNamespace, nsScope =>
            {
                nsScope.Class(name, null, true, false, classScope =>
                {
                    classScope.CustomScope("public override void OpenWindow(UGUIWindowInfo windowInfo)", false,
                                           function =>
                    {
                        function.Custom("base.OpenWindow(windowInfo);");
                        function.Custom("windowTransform = GetComponent<RectTransform>();");
                        function.Custom("//在此处添加初始化窗口代码");
                    });
                    classScope.EmptyLine();
                    classScope.CustomScope("public override void ShowWindow()", false,
                                           function => { });
                    classScope.EmptyLine();
                    classScope.CustomScope("public override void HideWindow()", false,
                                           function => { });
                    classScope.EmptyLine();
                    classScope.CustomScope("public override void CloseWindow()", false,
                                           function =>
                    {
                        function.Custom("//在此处添加销毁窗口代码");
                        function.Custom("");
                        function.Custom("windowData = null;");
                    });
                });
            });

            rootCode.Gen(codeWriter);
            codeWriter.Dispose();
        }
Пример #3
0
        public static void Write(string name, string srcFilePath, string srcNamespace)
        {
            var scriptFile = srcFilePath;

            if (File.Exists(scriptFile))
            {
                return;
            }

            var writer = File.CreateText(scriptFile);

            var scriptNamespace = srcNamespace;

            if (!srcNamespace.IsNotNull() || srcNamespace.Equals(""))
            {
                scriptNamespace = "UGUIFramework";
            }

            var root = new RootCode()
                       .Using("System")
                       .Using("UnityEngine")
                       .Using("UnityEngine.UI")
                       .Using("UGUIFramework")
                       .EmptyLine()
                       .Namespace(scriptNamespace, ns =>
            {
                ns.Custom("// Generate Id:{0}".FillFormat(Guid.NewGuid().ToString()));
                ns.Class(name, "UGUIWindowBase", true, false, (classScope) =>
                {
                    classScope.Custom("public const string Name = \"" + name + "\";");
                    classScope.EmptyLine();

                    classScope.EmptyLine();
                    classScope.Custom("private " + name + "Data windowData = null;");

                    classScope.EmptyLine();
                });
            });

            var codeWriter = new FileCodeWriter(writer);

            root.Gen(codeWriter);
            codeWriter.Dispose();
        }