Exemplo n.º 1
0
        internal static void ImportXml(string xmlPath, out VisualTreeAsset vta)
        {
            vta = ScriptableObject.CreateInstance <VisualTreeAsset>();
            vta.visualElementAssets = new List <VisualElementAsset>();
            vta.templateAssets      = new List <TemplateAsset>();
            XDocument doc;

            try
            {
                doc = XDocument.Load(xmlPath, LoadOptions.SetLineInfo);
            }
            catch (Exception context)
            {
                UIElementsViewImporter.logger.LogError(ImportErrorType.Syntax, ImportErrorCode.InvalidXml, context, UIElementsViewImporter.Error.Level.Fatal, null);
                return;
            }
            StyleSheetBuilder styleSheetBuilder = new StyleSheetBuilder();

            UIElementsViewImporter.LoadXmlRoot(doc, vta, styleSheetBuilder);
            StyleSheet styleSheet = ScriptableObject.CreateInstance <StyleSheet>();

            styleSheet.name = "inlineStyle";
            styleSheetBuilder.BuildTo(styleSheet);
            vta.inlineSheet = styleSheet;
        }
Exemplo n.º 2
0
        private static void LoadXmlRoot(XDocument doc, VisualTreeAsset vta, StyleSheetBuilder ssb)
        {
            XElement root = doc.Root;

            if (!string.Equals(root.Name.LocalName, "UXML", StringComparison.InvariantCulture))
            {
                UIElementsViewImporter.logger.LogError(ImportErrorType.Semantic, ImportErrorCode.InvalidRootElement, root.Name, UIElementsViewImporter.Error.Level.Fatal, root);
            }
            else
            {
                foreach (XElement current in root.Elements())
                {
                    string localName = current.Name.LocalName;
                    if (localName != null)
                    {
                        if (localName == "Using")
                        {
                            UIElementsViewImporter.LoadUsingNode(vta, root, current);
                            continue;
                        }
                    }
                    UIElementsViewImporter.LoadXml(current, null, vta, ssb);
                }
            }
        }
Exemplo n.º 3
0
        public override void OnImportAsset(AssetImportContext args)
        {
            UIElementsViewImporter.logger.BeginImport(args.assetPath);
            VisualTreeAsset visualTreeAsset;

            UIElementsViewImporter.ImportXml(args.assetPath, out visualTreeAsset);
            args.AddObjectToAsset("tree", visualTreeAsset);
            args.SetMainObject(visualTreeAsset);
            if (!visualTreeAsset.inlineSheet)
            {
                visualTreeAsset.inlineSheet = ScriptableObject.CreateInstance <StyleSheet>();
            }
            args.AddObjectToAsset("inlineStyle", visualTreeAsset.inlineSheet);
        }
Exemplo n.º 4
0
        private static void LoadXml(XElement elt, VisualElementAsset parent, VisualTreeAsset vta, StyleSheetBuilder ssb)
        {
            VisualElementAsset visualElementAsset;

            if (!UIElementsViewImporter.ResolveType(elt, vta, out visualElementAsset))
            {
                UIElementsViewImporter.logger.LogError(ImportErrorType.Semantic, ImportErrorCode.UnknownElement, elt.Name.LocalName, UIElementsViewImporter.Error.Level.Fatal, elt);
            }
            else
            {
                int num = (parent != null) ? parent.id : 0;
                int id  = num << 1 ^ visualElementAsset.GetHashCode();
                visualElementAsset.parentId = num;
                visualElementAsset.id       = id;
                bool flag = UIElementsViewImporter.ParseAttributes(elt, visualElementAsset, ssb, vta, parent);
                visualElementAsset.ruleIndex = ((!flag) ? -1 : ssb.EndRule());
                if (visualElementAsset is TemplateAsset)
                {
                    vta.templateAssets.Add((TemplateAsset)visualElementAsset);
                }
                else
                {
                    vta.visualElementAssets.Add(visualElementAsset);
                }
                if (elt.HasElements)
                {
                    foreach (XElement current in elt.Elements())
                    {
                        if (current.Name.LocalName == "Style")
                        {
                            UIElementsViewImporter.LoadStyleReferenceNode(visualElementAsset, current);
                        }
                        else
                        {
                            UIElementsViewImporter.LoadXml(current, visualElementAsset, vta, ssb);
                        }
                    }
                }
            }
        }