Beispiel #1
0
        void LogWarning(VisualTreeAsset asset, ImportErrorType errorType, ImportErrorCode code, object context, IXmlLineInfo xmlLineInfo)
        {
            // If we ever want to use the AssetDatabase error reporting APIs, use m_Context.LogImportWarning() here
            logger.LogError(errorType, code, context, Error.Level.Warning, xmlLineInfo);

            if (asset != null)
            {
                asset.importedWithWarnings = true;
            }
        }
Beispiel #2
0
        void ImportXml(string xmlPath, out VisualTreeAsset vta)
        {
            vta = ScriptableObject.CreateInstance <VisualTreeAsset>();
            vta.visualElementAssets = new List <VisualElementAsset>();
            vta.templateAssets      = new List <TemplateAsset>();

            var h = new Hash128();

            using (var stream = File.OpenRead(xmlPath))
            {
                int    readCount = 0;
                byte[] b         = new byte[1024 * 16];
                while ((readCount = stream.Read(b, 0, b.Length)) > 0)
                {
                    for (int i = readCount; i < b.Length; i++)
                    {
                        b[i] = 0;
                    }
                    Hash128 blockHash = new Hash128();
                    HashUtilities.ComputeHash128(b, ref blockHash);
                    HashUtilities.AppendHash(ref blockHash, ref h);
                }
            }

            vta.contentHash = h.GetHashCode();

            XDocument doc;

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

            LoadXmlRoot(doc, vta);
            TryCreateInlineStyleSheet(vta);
        }
        void ImportXml(string xmlPath, out VisualTreeAsset vta)
        {
            var h = new Hash128();

            using (var stream = File.OpenRead(xmlPath))
            {
                int    readCount = 0;
                byte[] b         = new byte[1024 * 16];
                while ((readCount = stream.Read(b, 0, b.Length)) > 0)
                {
                    for (int i = readCount; i < b.Length; i++)
                    {
                        b[i] = 0;
                    }
                    h.Append(b);
                }
            }

            CreateVisualTreeAsset(out vta, h);

            XDocument doc;

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

            LoadXmlRoot(doc, vta);
            TryCreateInlineStyleSheet(vta);
        }
Beispiel #4
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 e)
            {
                logger.LogError(ImportErrorType.Syntax, ImportErrorCode.InvalidXml, e, Error.Level.Fatal, null);
                return;
            }

            StyleSheetBuilder ssb = new StyleSheetBuilder();

            LoadXmlRoot(doc, vta, ssb);

            StyleSheet inlineSheet = ScriptableObject.CreateInstance <StyleSheet>();

            inlineSheet.name = "inlineStyle";
            ssb.BuildTo(inlineSheet);
            vta.inlineSheet = inlineSheet;
        }