示例#1
0
        private string GetClassName(FairyComponent comp)
        {
            var className = comp.ResoureInfo.Name.Replace(".xml", "");

            className = className.Replace("&", "_");
            className = string.Format("{0}{1}", Publish.codeGeneration.classNamePrefix, className);
            return(className);
        }
示例#2
0
        private string GetClassFullName(FairyComponent comp)
        {
            var refPkgName = GetPackageFullName(Packages[comp.PackageID]);

            refPkgName = string.Format("{0}.", refPkgName);
            var compType = string.Format("{0}{1}", refPkgName, GetClassName(comp));

            return(compType);
        }
示例#3
0
        /// <summary>
        /// 生成Controller文件
        /// </summary>
        /// <param name="package"></param>
        /// <param name="comp"></param>
        /// <param name="filePath"></param>
        /// <param name="variable"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        private string GenerateController(FairyPackage package, FairyComponent comp, string filePath, StringBuilder variable, StringBuilder content)
        {
            var controllerTemplate      = ((TextAsset)EditorGUIUtility.Load("FairyAnalyzer/Controller.template.txt")).text;
            var controllerTemplateParts = controllerTemplate.Split(new[] { "-----" }, StringSplitOptions.None);

            var controllerTemplateHeader = controllerTemplateParts[0];

            controllerTemplateHeader = controllerTemplateHeader.Replace("{packageName}", GetPackageFullName(package));
            controllerTemplateHeader = controllerTemplateHeader.Replace("{className}", GetClassName(comp));

            var controllerTemplateFooter = controllerTemplateParts[2];
            var controllerTemplateBody   = new StringBuilder();

            for (var i = 0; i < comp.ComponentDescription.Controllers.Count; i++)
            {
                var controllerDef = controllerTemplateParts[1];
                var con           = comp.ComponentDescription.Controllers[i];

                var memberName = string.Format("{0}{1}", Publish.codeGeneration.memberNamePrefix, con.Name);

                var controllerIndexMember = new StringBuilder();
                for (var j = 0; j < con.Pages.Count; j++)
                {
                    var stateName = con.Pages[j];
                    stateName = string.Format("{0}_{1}", stateName, j);

                    controllerIndexMember.AppendLine(string.Format("{3,16}{0}{1} = {2},", memberName, stateName, j, ""));
                }


                controllerDef = controllerDef.Replace("{controllerName}", con.Name);
                controllerDef = controllerDef.Replace("{controllerIndexMember}", controllerIndexMember.ToString());
                controllerTemplateBody.AppendLine(controllerDef);

                variable.AppendLine(string.Format("{2,8}public {0}Controller {1};", con.Name, memberName, ""));
                content.AppendLine(string.Format("{3,12}{0} = new {1}Controller(this.GetControllerAt({2}));",
                                                 memberName, con.Name, i, ""));
            }

            var controllerBody = controllerTemplateBody.ToString();

            if (string.IsNullOrEmpty(controllerBody) == false)
            {
                controllerBody = string.Format("{0}{1}{2}", controllerTemplateHeader, controllerBody, controllerTemplateFooter);
                var outPath = filePath.Replace(".cs", "Controller.cs");
                File.WriteAllText(outPath, controllerBody);
                return(outPath);
            }

            return(string.Empty);
        }