예제 #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
        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);
        }
예제 #6
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);
                }
            }
        }