Esempio n. 1
0
        private void EnsureTemplates()
        {
            if (templates != null)
            {
                return;
            }

            IReadOnlyCollection <TemplateLoaderResult> result = templateLoader.LoadTemplates();

            try
            {
                templates = result.Where(r => r.Template is TemplateDescription)
                            .ToDictionary(r => (TemplateDescription)r.Template, r => r.TemplateLocation);
                fieldTemplates = result.Select(r => r.Template)
                                 .OfType <FieldTemplates>()
                                 .ToArray();
                typeTemplates = result.Select(r => r.Template)
                                .OfType <TypeTemplates>()
                                .ToArray();
                formatTemplates = result.Select(r => r.Template)
                                  .OfType <FormatTemplates>()
                                  .ToArray();
            }
            catch (ArgumentException e)
            {
                executionContext.WriteError(e.ToString(), false);
                throw new FormattableException("Two templates with the same name exist. See log for more information.");
            }
        }
Esempio n. 2
0
        public static CompiledTemplateData LoadPrecompiledTemplates(TemplateSettings templateSettings)
        {
            Assembly assembly = AppDomain.CurrentDomain.GetAssemblyByName(templateSettings.assemblyName);
            Type     type     = assembly.GetType("UIForia.Generated.UIForiaGeneratedTemplates_" + templateSettings.StrippedApplicationName);

            if (type == null)
            {
                throw new ArgumentException("Trying to use precompiled templates for " + templateSettings.StrippedApplicationName + " but couldn't find the type. Maybe you need to regenerate the code?");
            }

            CompiledTemplateData compiledTemplateData = new CompiledTemplateData(templateSettings);

            compiledTemplateData.styleImporter.importResolutionPath = Path.Combine(UnityEngine.Application.streamingAssetsPath, "UIForia", compiledTemplateData.templateSettings.StrippedApplicationName);

            ITemplateLoader loader = (ITemplateLoader)Activator.CreateInstance(type);

            string[] files = loader.StyleFilePaths;

            compiledTemplateData.styleImporter.Reset(); // reset because in testing we will already have parsed files, nuke these

            LightList <UIStyleGroupContainer> styleList     = new LightList <UIStyleGroupContainer>(128);
            Dictionary <string, StyleSheet>   styleSheetMap = new Dictionary <string, StyleSheet>(128);

            MaterialDatabase materialDatabase = loader.GetMaterialDatabase();

            for (int i = 0; i < files.Length; i++)
            {
                StyleSheet sheet = compiledTemplateData.styleImporter.ImportStyleSheetFromFile(files[i], materialDatabase);
                styleList.EnsureAdditionalCapacity(sheet.styleGroupContainers.Length);

                for (int j = 0; j < sheet.styleGroupContainers.Length; j++)
                {
                    styleList.array[styleList.size++] = sheet.styleGroupContainers[j];
                }

                styleSheetMap.Add(sheet.path, sheet);
            }

            compiledTemplateData.templates        = loader.LoadTemplates();
            compiledTemplateData.slots            = loader.LoadSlots();
            compiledTemplateData.bindings         = loader.LoadBindings();
            compiledTemplateData.templateMetaData = loader.LoadTemplateMetaData(styleSheetMap, styleList.array);

            for (int i = 0; i < compiledTemplateData.templateMetaData.Length; i++)
            {
                compiledTemplateData.templateMetaData[i].compiledTemplateData = compiledTemplateData;
            }

            compiledTemplateData.constructElement = loader.ConstructElement;
            compiledTemplateData.dynamicTemplates = loader.DynamicTemplates;

            return(compiledTemplateData);
        }