예제 #1
0
        public override void OnImportAsset(AssetImportContext ctx)
        {
            isWhitelisted = IsWhiteListed(ctx);
            string contents = string.Empty;

            try
            {
                contents = File.ReadAllText(ctx.assetPath);
            }
            catch (IOException exc)
            {
                ctx.LogImportError($"IOException : {exc.Message}");
            }
            finally
            {
                StyleSheet asset = ScriptableObject.CreateInstance <StyleSheet>();
                asset.hideFlags = HideFlags.NotEditable;

                if (!string.IsNullOrEmpty(contents))
                {
                    var importer = new StyleSheetImporterImpl(ctx);
                    importer.disableValidation = disableValidation | isWhitelisted;
                    importer.Import(asset, contents);
                }

                // make sure to produce a style sheet object in all cases
                ctx.AddObjectToAsset("stylesheet", asset);
                ctx.SetMainObject(asset);
            }
        }
예제 #2
0
        public override void OnImportAsset(AssetImportContext ctx)
        {
            var        importer = new StyleSheetImporterImpl();
            string     contents = File.ReadAllText(ctx.assetPath);
            StyleSheet asset    = ScriptableObject.CreateInstance <StyleSheet>();

            asset.hideFlags = HideFlags.NotEditable;

            if (importer.Import(asset, contents))
            {
                ctx.AddObjectToAsset("stylesheet", asset);

                // Force the pre processor to rebuild its list of referenced asset paths
                // as paths may have changed with this import.
                StyleSheetAssetPostprocessor.ClearReferencedAssets();

                // Clear the style cache to force all USS rules to recompute
                // and subsequently reload/reimport all images.
                StyleContext.ClearStyleCache();
            }
            else
            {
                foreach (string importError in importer.errors.FormatErrors())
                {
                    Debug.LogError(importError);
                }
            }
        }
예제 #3
0
        internal static StyleSheet CompileStyleSheetContent(string styleSheetContent)
        {
            var importer   = new StyleSheetImporterImpl();
            var styleSheet = ScriptableObject.CreateInstance <StyleSheet>();

            importer.Import(styleSheet, styleSheetContent);
            return(styleSheet);
        }
        public override void OnImportAsset(AssetImportContext ctx)
        {
            string contents = File.ReadAllText(ctx.assetPath);

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

            asset.hideFlags = HideFlags.NotEditable;

            var importer = new StyleSheetImporterImpl(ctx);

            importer.Import(asset, contents);
        }
예제 #5
0
 private void VisitSheet(StyleSheet styleSheet)
 {
     foreach (StyleRule current in styleSheet.StyleRules)
     {
         this.m_Builder.BeginRule(current.Line);
         this.VisitBaseSelector(current.Selector);
         foreach (Property current2 in current.Declarations)
         {
             this.m_Builder.BeginProperty(current2.Name);
             StyleSheetImporterImpl.VisitValue(this.m_Errors, this.m_Builder, current2.Term);
             this.m_Builder.EndProperty();
         }
         this.m_Builder.EndRule();
     }
 }
예제 #6
0
        internal static StyleSheet CompileStyleSheetContent(string styleSheetContent, bool disableValidation = true, bool reportErrors = false)
        {
            var importer   = new StyleSheetImporterImpl();
            var styleSheet = ScriptableObject.CreateInstance <StyleSheet>();

            importer.disableValidation = disableValidation;
            importer.Import(styleSheet, styleSheetContent);
            if (reportErrors)
            {
                foreach (var err in importer.importErrors)
                {
                    Debug.LogFormat(LogType.Warning, LogOption.NoStacktrace, styleSheet, err.ToString());
                }
            }
            return(styleSheet);
        }
예제 #7
0
        public override void OnImportAsset(AssetImportContext ctx)
        {
            StyleSheetImporterImpl styleSheetImporterImpl = new StyleSheetImporterImpl();
            string     contents   = File.ReadAllText(ctx.assetPath);
            StyleSheet styleSheet = ScriptableObject.CreateInstance <StyleSheet>();

            styleSheet.hideFlags = HideFlags.NotEditable;
            if (styleSheetImporterImpl.Import(styleSheet, contents))
            {
                ctx.AddObjectToAsset("stylesheet", styleSheet);
                StyleSheetAssetPostprocessor.ClearReferencedAssets();
                StyleContext.ClearStyleCache();
            }
            else
            {
                foreach (string current in styleSheetImporterImpl.errors.FormatErrors())
                {
                    Debug.LogError(current);
                }
            }
        }
예제 #8
0
        internal static void VisitValue(StyleSheetImportErrors errors, StyleSheetBuilder ssb, Term term)
        {
            PrimitiveTerm   primitiveTerm   = term as PrimitiveTerm;
            HtmlColor       htmlColor       = term as HtmlColor;
            GenericFunction genericFunction = term as GenericFunction;
            TermList        termList        = term as TermList;

            if (term == Term.Inherit)
            {
                ssb.AddValue(StyleValueKeyword.Inherit);
            }
            else if (primitiveTerm != null)
            {
                string   text          = term.ToString();
                UnitType primitiveType = primitiveTerm.PrimitiveType;
                switch (primitiveType)
                {
                case UnitType.String:
                {
                    string value = text.Trim(new char[]
                        {
                            '\'',
                            '"'
                        });
                    ssb.AddValue(value, StyleValueType.String);
                    goto IL_F9;
                }

                case UnitType.Uri:
IL_63:
                    if (primitiveType != UnitType.Number && primitiveType != UnitType.Pixel)
                    {
                        errors.AddSemanticError(StyleSheetImportErrorCode.UnsupportedUnit, primitiveTerm.ToString());
                        return;
                    }
                    ssb.AddValue(primitiveTerm.GetFloatValue(UnitType.Pixel).Value);
                    goto IL_F9;

                case UnitType.Ident:
                {
                    StyleValueKeyword keyword;
                    if (StyleSheetImporterImpl.TryParseKeyword(text, out keyword))
                    {
                        ssb.AddValue(keyword);
                    }
                    else
                    {
                        ssb.AddValue(text, StyleValueType.Enum);
                    }
                    goto IL_F9;
                }
                }
                goto IL_63;
                IL_F9 :;
            }
            else if (htmlColor != null)
            {
                Color value2 = new Color((float)htmlColor.R / 255f, (float)htmlColor.G / 255f, (float)htmlColor.B / 255f, (float)htmlColor.A / 255f);
                ssb.AddValue(value2);
            }
            else if (genericFunction != null)
            {
                primitiveTerm = (genericFunction.Arguments.FirstOrDefault <Term>() as PrimitiveTerm);
                if (genericFunction.Name == "resource" && primitiveTerm != null)
                {
                    string value3 = primitiveTerm.Value as string;
                    ssb.AddValue(value3, StyleValueType.ResourcePath);
                }
                else
                {
                    errors.AddSemanticError(StyleSheetImportErrorCode.UnsupportedFunction, genericFunction.Name);
                }
            }
            else if (termList != null)
            {
                foreach (Term current in termList)
                {
                    StyleSheetImporterImpl.VisitValue(errors, ssb, current);
                }
            }
            else
            {
                errors.AddInternalError(term.GetType().Name);
            }
        }