Exemplo n.º 1
0
 public void GenerateAssembly(string sourceFile, string path, string name)
 {
     GenerateAndExit             = new GenerateInfo();
     GenerateAndExit.name        = name;
     GenerateAndExit.source      = sourceFile;
     GenerateAndExit.destination = path;
 }
Exemplo n.º 2
0
        //----- field -----

        //----- property -----

        //----- method -----

        public static void Generate(ContentType type, LanguageInfo info)
        {
            var textData = TextData.Instance;

            var config = TextDataConfig.Instance;

            var scriptFolderPath = string.Empty;

            var contentsFolderPath = string.Empty;

            var assetFolderPath = string.Empty;

            switch (type)
            {
            case ContentType.Embedded:
            {
                var embedded = config.Embedded;

                scriptFolderPath   = embedded.ScriptFolderPath;
                contentsFolderPath = embedded.GetContentsFolderPath();
                assetFolderPath    = embedded.AseetFolderPath;
            }
            break;

            case ContentType.Distribution:
            {
                var distribution = config.Distribution;

                if (!distribution.Enable)
                {
                    return;
                }

                contentsFolderPath = distribution.GetContentsFolderPath();
                assetFolderPath    = distribution.AseetFolderPath;
            }
            break;
            }

            var assetFolderName = textData.GetAssetFolderName();

            var assetFileName = TextData.GetAssetFileName(info.Identifier);

            var assetPath = PathUtility.Combine(new string[] { assetFolderPath, assetFolderName, assetFileName });

            var generateInfo = new GenerateInfo
            {
                assetPath          = assetPath,
                contentsFolderPath = contentsFolderPath,
                scriptFolderPath   = scriptFolderPath,
                textIndex          = info.TextIndex,
            };

            GenerateTextData(type, generateInfo);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 代码生成
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            var hostName = cmbHostName.Text;

            if (String.IsNullOrWhiteSpace(hostName))
            {
                MsgBox.Show("请选择宿主类型");
                return;
            }

            var tableList = new List <SOTable>();

            foreach (var item in listBox2.Items)
            {
                tableList.Add((SOTable)item);
            }

            String language, groupName;
            var    templateList = GetSelectedTemplate(out language, out groupName);

            if (templateList.Count <= 0)
            {
                MsgBox.Show("请先选择要使用的模块");
                return;
            }

            var savePath = txtSavePath.Text;

            if (String.IsNullOrWhiteSpace(savePath))
            {
                MsgBox.Show("请先选择存储目录");
                return;
            }

            var arg = new GenerateInfo()
            {
                HostName          = hostName,
                Language          = language,
                GroupName         = groupName,
                TemplateInfos     = templateList,
                TableList         = tableList,
                SavePath          = savePath,
                NameRuleConfig    = this.nameRuleConfigBLLObj.GetItem(this.cmbRuleList.Text),
                TypeMapConfigList = typeMapConfigBLLObj.GetList(language, false),
            };

            this.UseWaitCursor        = true;
            this.Enabled              = false;
            this.progressBar1.Minimum = 0;
            this.progressBar1.Value   = 0;
            this.backgroundWorker1.RunWorkerAsync(arg);
        }
Exemplo n.º 4
0
        public IHttpActionResult Generate(GenerateInfo param)
        {
            int row;
            int col;

            row = int.Parse(param.Rows);
            col = int.Parse(param.Cols);
            Maze m = model.GetNewModel(param.Name, row, col);

            if (m == null)
            {
                return(BadRequest("Could not generate the requested maze."));
            }
            return(Ok(m.ToJSON()));
        }
Exemplo n.º 5
0
        internal void GenerateAssemblyAndExit(GenerateInfo info)
        {
            System.IO.StreamReader streamReader = new System.IO.StreamReader(info.source);
            string source = streamReader.ReadToEnd();

            streamReader.Close();

            js.CompileToFile(source, info.destination, info.name);

            // Fix reference to mscorlib
            string fullName = string.Format("{0}/{1}.dll", info.destination, info.name);
            var    assembly = new NETAssembly.NETAssembly();

            assembly.Load(fullName);
            assembly.SetVersionForReference(
                "mscorlib",
                new byte[] { 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00 }, // 2.0.5.0
                new byte[] { 0x7c, 0xec, 0x85, 0xd7, 0xbe, 0xa7, 0x79, 0x8e }
                );
            this.Exit();
        }
Exemplo n.º 6
0
        static void Run(bool debug)
        {
            var projectRoot = new DirectoryInfo(Path.GetFullPath(Path.Combine(Application.dataPath, "../")));

            var gltf = new FileInfo(Path.Combine(projectRoot.FullName, "glTF/specification/2.0/schema/glTF.schema.json"));

            var args = new GenerateInfo[]
            {
                // VRMC_hdr_emissiveMultiplier
                new GenerateInfo(
                    "vrm-specification/specification/VRMC_materials_hdr_emissiveMultiplier-1.0_draft/schema/VRMC_materials_hdr_emissiveMultiplier.json",
                    "Assets/UniGLTF/Runtime/UniGLTF/Format/ExtensionsAndExtras/EmissiveMultiplier"
                    ),

                // VRMC_vrm
                new GenerateInfo(
                    "vrm-specification/specification/VRMC_vrm-1.0_draft/schema/VRMC_vrm.schema.json",
                    "Assets/VRM10/Runtime/Format/Vrm"
                    ),

                // VRMC_materials_mtoon
                new GenerateInfo(
                    "vrm-specification/specification/VRMC_materials_mtoon-1.0_draft/schema/VRMC_materials_mtoon.schema.json",
                    "Assets/VRMShaders/VRM10/Format/Runtime/MaterialsMToon",
                    "Assets/VRM10/Runtime/Format/MaterialsMToon"
                    ),

                // VRMC_springBone
                new GenerateInfo(
                    "vrm-specification/specification/VRMC_springBone-1.0_draft/schema/VRMC_springBone.schema.json",
                    "Assets/VRM10/Runtime/Format/SpringBone"
                    ),

                // VRMC_node_constraint
                new GenerateInfo(
                    "vrm-specification/specification/VRMC_node_constraint-1.0_draft/schema/VRMC_node_constraint.schema.json",
                    "Assets/VRM10/Runtime/Format/Constraints"
                    ),
            };

            foreach (var arg in args)
            {
                var extensionSchemaPath = new FileInfo(Path.Combine(projectRoot.FullName, arg.JsonSchema));
                var parser          = new UniGLTF.JsonSchema.JsonSchemaParser(gltf.Directory, extensionSchemaPath.Directory);
                var extensionSchema = parser.Load(extensionSchemaPath, "");

                var formatDst = new DirectoryInfo(Path.Combine(projectRoot.FullName, arg.FormatDir));
                Debug.Log($"Format.g Dir: {formatDst}");

                var serializerDst = new DirectoryInfo(Path.Combine(projectRoot.FullName, arg.SerializerDir));
                Debug.Log($"Serializer/Deserializer.g Dir: {serializerDst}");

                if (debug)
                {
                    Debug.Log(extensionSchema.Dump());
                }
                else
                {
                    GenerateUniGLTFSerialization.Generator.GenerateTo(extensionSchema, formatDst, serializerDst);
                }
            }
        }
Exemplo n.º 7
0
        static public void Generate(List <IRecordObject> recordObjects, string csFilePath)
        {
            var list = recordObjects.FindAll(x => x is ClassWithMembersAndTypes || x is SystemClassWithMembersAndTypes).ConvertAll(x =>
            {
                GenerateInfo info = null;
                if (x is ClassWithMembersAndTypes)
                {
                    var c = x as ClassWithMembersAndTypes;
                    info  = new GenerateInfo()
                    {
                        ClassInfo = c.ClassInfo, MemberTypeInfo = c.MemberTypeInfo
                    };
                }
                else if (x is SystemClassWithMembersAndTypes)
                {
                    var c = x as SystemClassWithMembersAndTypes;
                    info  = new GenerateInfo()
                    {
                        ClassInfo = c.ClassInfo, MemberTypeInfo = c.MemberTypeInfo
                    };
                }

                if (info != null && info.ClassInfo != null)
                {
                    //系统类跳过
                    if (info.ClassInfo.Name.Value.StartsWith("System"))
                    {
                        return(null);
                    }
                }

                return(info);
            });

            var builder = new StringBuilder(2048);

            builder.AppendLine("using System;");
            builder.AppendLine("using System.Collections.Generic;");
            builder.AppendLine();

            foreach (var item in list)
            {
                if (item == null)
                {
                    continue;
                }

                var tupleInfo = CSExtensions.GetNamespaceAndClassNames(item.ClassInfo.Name.Value);

                var memberCount     = item.ClassInfo.MemberCount;
                var memberNames     = item.ClassInfo.MemberNames.ToList().ConvertAll(x => x.Value);
                var binaryTypeEnums = item.MemberTypeInfo.BinaryTypeEnums;
                var additionalInfos = item.MemberTypeInfo.AdditionalInfos;

                var hasNamespace = !string.IsNullOrEmpty(tupleInfo.Item1);
                var tabIndex     = 0;

                if (hasNamespace)
                {
                    builder.AppendFormat("namespace {0}", tupleInfo.Item1);
                    builder.AppendLine();
                    builder.AppendLine("{");
                    tabIndex++;
                }

                foreach (var className in tupleInfo.Item2)
                {
                    builder.AppendFormat("{0}[System.Serializable]", new string('\t', tabIndex));
                    builder.AppendLine();
                    builder.AppendFormat("{0}class {1}", new string('\t', tabIndex), className);
                    builder.AppendLine();
                    builder.AppendFormat("{0}{{", new string('\t', tabIndex));
                    builder.AppendLine();
                    tabIndex++;
                }

                {
                    for (int i = 0; i < memberCount; i++)
                    {
                        var memberName     = memberNames[i];
                        var binaryTypeEnum = binaryTypeEnums[i];
                        var additionalInfo = additionalInfos[i];
                        var memberType     = string.Empty;

                        switch (binaryTypeEnum)
                        {
                        case BinaryTypeEnumeration.Primitive:
                        case BinaryTypeEnumeration.PrimitiveArray:
                            memberType = "System." + additionalInfo.ToString();
                            break;

                        case BinaryTypeEnumeration.String:
                            memberType = "string";
                            break;

                        case BinaryTypeEnumeration.Object:
                            memberType = "object";
                            break;

                        case BinaryTypeEnumeration.SystemClass:
                            memberType = additionalInfo.ToString();
                            break;

                        case BinaryTypeEnumeration.Class:
                            var info = additionalInfo as ClassTypeInfo;
                            memberType = info.TypeName.Value;
                            break;

                        default:
                            throw new NotImplementedException("BinaryTypeEnumeration:" + binaryTypeEnum);
                        }

                        //generic
                        var index = tupleInfo.Item3.IndexOf(memberType);
                        if (index != -1)
                        {
                            memberType = "T" + index;
                        }

                        var isProperty = memberName.Contains(k_BackingField);
                        if (isProperty)
                        {
                            var match = Regex.Match(memberName, string.Format("<(.*?)>{0}", k_BackingField));
                            memberName = match.Groups[1].Value;
                        }

                        if (CSExtensions.IsKeyword(memberName))
                        {
                            memberName = "@" + memberName;
                        }
                        memberType = memberType.Replace("+", ".");

                        builder.AppendFormat("{0}public {1} {2}{3}", new string('\t', tabIndex), memberType, memberName, isProperty ? " { set; get; }" : ";");
                        builder.AppendLine();
                    }
                }

                foreach (var className in tupleInfo.Item2)
                {
                    tabIndex--;
                    builder.AppendFormat("{0}}}", new string('\t', tabIndex));
                    builder.AppendLine();
                }
                if (hasNamespace)
                {
                    tabIndex--;
                    builder.AppendLine("}");
                    builder.AppendLine();
                }
            }

            File.WriteAllText(csFilePath, builder.ToString());
        }
Exemplo n.º 8
0
        private static void GenerateTextData(ContentType contentType, GenerateInfo generateInfo)
        {
            var progressTitle = "Generate TextData";

            var config = TextDataConfig.Instance;

            // 読み込み.

            EditorUtility.DisplayProgressBar(progressTitle, "Load contents.", 0f);

            var sheets = LoadSheetData(config.FileFormat, generateInfo.contentsFolderPath);

            if (sheets == null)
            {
                return;
            }

            var cryptoKey = new AesCryptoKey(config.CryptoKey, config.CryptoIv);

            var generateScript = !string.IsNullOrEmpty(generateInfo.scriptFolderPath);

            try
            {
                using (new AssetEditingScope())
                {
                    // Script.

                    if (generateScript)
                    {
                        EditorApplication.LockReloadAssemblies();

                        DirectoryUtility.Clean(generateInfo.scriptFolderPath);

                        AssetDatabase.ImportAsset(generateInfo.scriptFolderPath, ImportAssetOptions.ForceUpdate);

                        EditorUtility.DisplayProgressBar(progressTitle, "Generate script.", 0.25f);

                        CategoryScriptGenerator.Generate(sheets, generateInfo.scriptFolderPath);

                        TextDataScriptGenerator.Generate(sheets, generateInfo.scriptFolderPath);

                        ContentsScriptGenerator.Generate(sheets, generateInfo.scriptFolderPath, generateInfo.textIndex);
                    }

                    // Asset.

                    EditorUtility.DisplayProgressBar(progressTitle, "Generate asset.", 0.5f);

                    var textDataAsset = LoadAsset(generateInfo.assetPath);

                    TextDataAssetGenerator.Build(textDataAsset, contentType, sheets, generateInfo.textIndex, cryptoKey);

                    EditorUtility.DisplayProgressBar(progressTitle, "Complete.", 1f);
                }

                AssetDatabase.SaveAssets();
            }
            finally
            {
                if (generateScript)
                {
                    EditorApplication.UnlockReloadAssemblies();
                }

                AssetDatabase.Refresh();

                EditorUtility.ClearProgressBar();
            }

            EditorUtility.ClearProgressBar();
        }
Exemplo n.º 9
0
        internal void GenerateAssemblyAndExit(GenerateInfo info)
        {
            System.IO.StreamReader streamReader = new System.IO.StreamReader(info.source);
            string source = streamReader.ReadToEnd();
            streamReader.Close();

            js.CompileToFile(source, info.destination, info.name);

            // Fix reference to mscorlib
            string fullName = string.Format("{0}/{1}.dll", info.destination, info.name);
            var assembly = new NETAssembly.NETAssembly();
            assembly.Load(fullName);
            assembly.SetVersionForReference(
                "mscorlib",
                new byte[] { 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00 }, // 2.0.5.0
                new byte[] { 0x7c, 0xec, 0x85, 0xd7, 0xbe, 0xa7, 0x79, 0x8e }
            );
            this.Exit();
        }
Exemplo n.º 10
0
 public void GenerateAssembly(string sourceFile, string path, string name)
 {
     GenerateAndExit = new GenerateInfo();
     GenerateAndExit.name = name;
     GenerateAndExit.source = sourceFile;
     GenerateAndExit.destination = path;
 }