Esempio n. 1
0
        public string GetPackageFullName(FairyPackage package)
        {
            var fullName = GetPackageName(package);

            if (string.IsNullOrEmpty(Publish.codeGeneration.packageName) == false)
            {
                fullName = string.Format("{0}.{1}", Publish.codeGeneration.packageName, fullName);
            }

            return(fullName);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public FairyAsset(string guiProjectRootPath)
        {
            if (Path.IsPathRooted(guiProjectRootPath)) //绝对路径
            {
            }
            else //相对路径
            {
            }

            var  files        = Directory.GetFiles(guiProjectRootPath);
            bool isGuiProject = false;

            foreach (var file in files)
            {
                if (Path.GetExtension(file) == ".fairy")
                {
                    isGuiProject = true;
                    break;
                }
            }

            if (false == isGuiProject)
            {
                throw new Exception("不是FairyGUI项目目录");
            }

            var packagePathes = Directory.GetDirectories(string.Format("{0}/assets", guiProjectRootPath));
            var publishJson   = File.ReadAllText(string.Format("{0}/settings/Publish.json", guiProjectRootPath));

            Publish = LitJson.JsonMapper.ToObject <Setting.Publish>(publishJson);

            Packages   = new Dictionary <string, FairyPackage>();
            Components = new Dictionary <string, Dictionary <string, FairyComponent> >();
            foreach (var packagePath in packagePathes)
            {
                var package = new FairyPackage(packagePath);
                Packages[package.PackageID] = package;

                Components[package.PackageID] = new Dictionary <string, FairyComponent>();

                foreach (var resKey in package.Components.Keys)
                {
                    var comp = package.Components[resKey];
                    Components[comp.PackageID][comp.ComponentID] = comp;
                }
            }
        }
Esempio n. 4
0
 public string GetPackageName(FairyPackage package)
 {
     return(package.FolderName);
 }