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); } }
public override void OnImportAsset(AssetImportContext ctx) { var contents = string.Empty; try { contents = File.ReadAllText(ctx.assetPath); } catch (IOException exc) { ctx.LogImportError($"IOException : {exc.Message}"); } finally { var theme = ScriptableObject.CreateInstance <ThemeStyleSheet>(); theme.hideFlags = HideFlags.NotEditable; if (!string.IsNullOrEmpty(contents)) { var importer = new StyleSheetImporterImpl(ctx); importer.disableValidation = disableValidation | isWhitelisted; importer.Import(theme, contents); } var icon = EditorGUIUtility.FindTexture("GUISkin Icon"); ctx.AddObjectToAsset("themeStyleSheet", theme, icon); ctx.SetMainObject(theme); } }
static string[] GatherDependenciesFromSourceFile(string assetPath) { var contents = File.ReadAllText(assetPath); if (string.IsNullOrEmpty(contents)) { return(new string[] {}); } try { return(StyleSheetImporterImpl.PopulateDependencies(assetPath)); } catch (Exception) { // We want to be silent here, all USS syntax errors will be reported during the actual import. return(new string[] {}); } }