Beispiel #1
0
        static void CreateDNAHelperCode()
        {
            var destDir      = Path.Combine(Directory.GetCurrentDirectory(), "Assets/UMA/Generated/DNAHelpers");
            var sourceDir    = Path.Combine(Directory.GetCurrentDirectory(), "Assets/UMA/Core/Scripts/Editor/Templates");
            var baseTemplate = FileUtils.ReadAllText(Path.Combine(sourceDir, "UmaDna_Template.cs.txt"));
            var pageTemplate = FileUtils.ReadAllText(Path.Combine(sourceDir, "UmaDnaChild_Template.cs.txt"));

            var templates     = CodeGenTemplate.ParseTemplates(sourceDir, baseTemplate);
            var pageTemplates = CodeGenTemplate.ParseTemplates(sourceDir, pageTemplate);

            customFormatter           = new DictionaryCustomFormatter();
            CodeGenTemplate.formatter = customFormatter;

            var baseDnaType = typeof(UMADnaBase);
            var customData  = new Dictionary <string, object>();

            customData.Add("ClassName", "");

            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (var dnaType in assembly.GetTypes())
                {
                    if (DerivesFrom(dnaType, baseDnaType))
                    {
                        if (dnaType.Name == "UMADna" || dnaType.Name == "DynamicUMADnaBase")
                        {
                            continue;
                        }
                        customData["ClassName"] = dnaType.Name;
                        foreach (var template in templates)
                        {
                            template.Append(customData);
                        }
                        if (dnaType.Name == "DynamicUMADna")
                        {
                            continue;
                        }
                        foreach (var template in pageTemplates)
                        {
                            template.sb.Length = 0;
                        }
                        CreateDNAHelperCode(dnaType, destDir, pageTemplate, pageTemplates);
                    }
                }
            }

            foreach (var template in templates)
            {
                customData.Add(template.Name, template.sb);
            }

            CreateBaseDNAExtension(destDir, baseTemplate, customData);
            AssetDatabase.Refresh();
        }
Beispiel #2
0
        static void CreateDNAHelperCode()
        {
            var destDir      = Path.Combine(Directory.GetCurrentDirectory(), "Assets/UMA/UMA_Generated/DnaHelpers");
            var sourceDir    = Path.Combine(Directory.GetCurrentDirectory(), "Assets/UMA/Editor/Templates");
            var baseTemplate = File.ReadAllText(Path.Combine(sourceDir, "UmaDna_Template.cs.txt"));
            var pageTemplate = File.ReadAllText(Path.Combine(sourceDir, "UmaDnaChild_Template.cs.txt"));

            var templates     = CodeGenTemplate.ParseTemplates(sourceDir, baseTemplate);
            var pageTemplates = CodeGenTemplate.ParseTemplates(sourceDir, pageTemplate);

            customFormatter           = new DictionaryCustomFormatter();
            CodeGenTemplate.formatter = customFormatter;

            if (!Directory.Exists(destDir))
            {
                Debug.Log("Creating Directory: " + destDir);
                Directory.CreateDirectory(destDir);
            }

            var baseDnaType = typeof(UMADna);
            var customData  = new Dictionary <string, object>();

            customData.Add("ClassName", "");

            foreach (var dnaType in baseDnaType.Assembly.GetTypes())
            {
                if (DerivesFrom(dnaType, baseDnaType))
                {
                    customData["ClassName"] = dnaType.Name;
                    foreach (var template in pageTemplates)
                    {
                        template.sb.Length = 0;
                    }
                    foreach (var template in templates)
                    {
                        template.Append(customData);
                    }
                    CreateDNAHelperCode(dnaType, destDir, pageTemplate, pageTemplates);
                }
            }

            foreach (var template in templates)
            {
                customData.Add(template.Name, template.sb);
            }

            CreateBaseDNAExtension(destDir, baseTemplate, customData);
            AssetDatabase.Refresh();
        }