// Creates a new style catalog from a set of USS assets. internal static StyleCatalog LoadCatalog(string[] ussPaths) { var catalog = new StyleCatalog(); catalog.Load(ussPaths); return(catalog); }
static void Main(string[] args) { StyleCatalog style = new StyleCatalog(); BreweriesCatalog breweriesCatalog = new BreweriesCatalog(); BeerCatalog beerCatalog = new BeerCatalog(); var stylescsv = @"D:\User\Vicente\Proyectos\Cursos de Programacion\Curso de C#\Repocitorio\ExerciseTRSF\BrewerySite\Files\styles.csv"; var beerscleanedcsv = @"D:\User\Vicente\Proyectos\Cursos de Programacion\Curso de C#\Repocitorio\ExerciseTRSF\BrewerySite\Files\beers-cleaned.csv"; var breweriescsv = @"D:\User\Vicente\Proyectos\Cursos de Programacion\Curso de C#\Repocitorio\ExerciseTRSF\BrewerySite\Files\breweries.csv"; /* var s = style.getListStyles(stylescsv); * foreach (var item in s) * { * Console.WriteLine(item.Id); * } * WriteLine("R-----------"); *//* * var d = breweriesCatalog.getListBreweries(breweriescsv); * foreach (var item in d) * { * Console.WriteLine(item.City); * } * WriteLine("R-----------"); * */ var f = beerCatalog.SetListBeer(beerscleanedcsv); foreach (var item in f) { Console.WriteLine(item.abv); } WriteLine("R-----------"); }
internal static void PopulateFromUSS(StyleCatalog catalog, GUIStyle style, string blockName, string ussInPlaceStyleOverride) { // Override with style in catalog PopulateStyle(catalog, style, blockName); if (!string.IsNullOrEmpty(ussInPlaceStyleOverride)) { try { if (!ussInPlaceStyleOverride.Contains("{")) { // A bit of sugar syntax in case the user doesn't provide the uss class declaration. ussInPlaceStyleOverride = $".{ConverterUtils.EscapeSelectorName(style.name)} {{\n{ussInPlaceStyleOverride}\n}}"; } var styleSheet = ConverterUtils.CompileStyleSheetContent(ussInPlaceStyleOverride); var overrideCatalog = new StyleCatalog(); overrideCatalog.Load(new[] { styleSheet }); const bool useExtensionDefaultValues = false; PopulateStyle(overrideCatalog, style, blockName, useExtensionDefaultValues); } catch (Exception e) { Debug.LogError("Cannot compile style override:" + e); } } }
internal static void BuildCatalog() { styleCatalog = new StyleCatalog(); var paths = GetDefaultStyleCatalogPaths(); foreach (var editorUssPath in AssetDatabase.FindAssets("t:StyleSheet").Select(AssetDatabase.GUIDToAssetPath).Where(IsEditorStyleSheet)) { paths.Add(editorUssPath); } styleCatalog.Load(paths); if (CanEnableExtendedStyles()) { // Update gui skin style layouts var skin = GUIUtility.GetDefaultSkin(); if (skin != null) { // TODO: Emit OnStyleCatalogLoaded if (Path.GetFileName(Path.GetDirectoryName(Application.dataPath)) == "editor_resources") { ConverterUtils.ResetSkinToPristine(skin, EditorGUIUtility.isProSkin ? SkinTarget.Dark : SkinTarget.Light); } UpdateGUIStyleProperties(skin); } } }
static void SaveCatalogToDisk(StyleCatalog catalog, string hash, string savePath) { using (var stream = new FileStream(savePath, FileMode.Create, FileAccess.Write, FileShare.None)) using (BinaryWriter writer = new BinaryWriter(stream)) { writer.Write(hash); catalog.Save(writer); } }
static EditorResources() { styleCatalog = new StyleCatalog(); if (CanEnableExtendedStyles()) { GUIStyle.onDraw = StylePainter.DrawStyle; } }
static void Main(string[] args) { StyleCatalog style = new StyleCatalog(); var s = style.getListStyles(); foreach (var item in s) { Console.WriteLine(item); } }
internal static void BuildCatalog() { using (new EditorPerformanceTracker(nameof(BuildCatalog))) { s_StyleCatalog = new StyleCatalog(); bool rebuildCatalog = true; List <string> paths = new List <string>(); string catalogHash = ""; const string k_GlobalStyleCatalogCacheFilePath = "Library/Style.catalog"; if (!EditorApplication.isBuildingAnyResources) { paths = GetDefaultStyleCatalogPaths(); foreach (var editorUssPath in AssetDatabase.FindAssets("t:StyleSheet") .Select(AssetDatabase.GUIDToAssetPath).Where(IsEditorStyleSheet)) { paths.Add(editorUssPath); } var forceRebuild = s_RefreshGlobalStyleCatalog; s_RefreshGlobalStyleCatalog = false; catalogHash = ComputeCatalogHash(paths); if (!forceRebuild && File.Exists(k_GlobalStyleCatalogCacheFilePath)) { using (var cacheCatalogStream = new FileStream(k_GlobalStyleCatalogCacheFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (var ccReader = new BinaryReader(cacheCatalogStream)) { string cacheHash = ccReader.ReadString(); if (cacheHash == catalogHash) { rebuildCatalog = !styleCatalog.Load(ccReader); } } } } } if (rebuildCatalog) { Console.WriteLine($"Loading style catalogs ({paths.Count})\r\n\t{String.Join("\r\n\t", paths.ToArray())}"); styleCatalog.Load(paths); if (paths.Count != 0) { SaveCatalogToDisk(styleCatalog, catalogHash, k_GlobalStyleCatalogCacheFilePath); } } } }
// Creates a new style catalog from a set of USS assets. internal static StyleCatalog LoadCatalog(string[] ussPaths, bool useResolver = true) { var catalog = new StyleCatalog(); foreach (var path in ussPaths) { catalog.AddPath(path); } catalog.Refresh(); return(catalog); }
internal static void BuildCatalog() { s_StyleCatalog = new StyleCatalog(); var paths = GetDefaultStyleCatalogPaths(); foreach (var editorUssPath in AssetDatabase.FindAssets("t:StyleSheet").Select(AssetDatabase.GUIDToAssetPath).Where(IsEditorStyleSheet)) { paths.Add(editorUssPath); } styleCatalog.Load(paths); }
static EditorResources() { s_StyleCatalog = new StyleCatalog(); // Initially only load catalog with bundle resources (since they area already compiled and valid) s_StyleCatalog.AddPaths(UIElementsEditorUtility.s_DefaultCommonStyleSheetPath, EditorGUIUtility.isProSkin ? UIElementsEditorUtility.s_DefaultCommonDarkStyleSheetPath : UIElementsEditorUtility.s_DefaultCommonLightStyleSheetPath); s_StyleCatalog.Refresh(); EditorApplication.update -= DelayInitialization; EditorApplication.update += DelayInitialization; }
internal static void BuildCatalog() { s_StyleCatalog = new StyleCatalog(); s_RefreshGlobalStyleCatalog = false; var paths = GetDefaultStyleCatalogPaths(); foreach (var editorUssPath in AssetDatabase.FindAssets("t:StyleSheet").Select(AssetDatabase.GUIDToAssetPath).Where(IsEditorStyleSheet)) { paths.Add(editorUssPath); } Console.WriteLine($"Building style catalogs ({paths.Count})\r\n\t{String.Join("\r\n\t", paths.ToArray())}"); styleCatalog.Load(paths); }
private static void BuildCatalog() { s_StyleCatalog = new StyleCatalog(); var paths = new List <string>(); paths.Add(UIElementsEditorUtility.s_DefaultCommonStyleSheetPath); paths.Add(EditorGUIUtility.isProSkin ? UIElementsEditorUtility.s_DefaultCommonDarkStyleSheetPath : UIElementsEditorUtility.s_DefaultCommonLightStyleSheetPath); foreach (var editorUssPath in AssetDatabase.GetAllAssetPaths().Where(IsEditorStyleSheet)) { paths.Add(editorUssPath); } s_StyleCatalog.AddPaths(paths); s_StyleCatalog.Refresh(); }
internal static void BuildCatalog() { using (new EditorPerformanceTracker(nameof(BuildCatalog))) { s_StyleCatalog = new StyleCatalog(); s_RefreshGlobalStyleCatalog = false; var paths = GetDefaultStyleCatalogPaths(); foreach (var editorUssPath in AssetDatabase.GetAllAssetPaths().Where(IsEditorStyleSheet)) { paths.Add(editorUssPath); } Console.WriteLine($"Building style catalogs ({paths.Count})\r\n\t{String.Join("\r\n\t", paths.ToArray())}"); styleCatalog.Load(paths); } }
internal static void BuildCatalog() { styleCatalog = new StyleCatalog(); var paths = GetDefaultStyleCatalogPaths(); foreach (var editorUssPath in AssetDatabase.GetAllAssetPaths().Where(IsEditorStyleSheet)) { paths.Add(editorUssPath); } styleCatalog.Load(paths); if (CanEnableExtendedStyles()) { // Update gui skin style layouts var skin = GUIUtility.GetDefaultSkin(); if (skin != null) { ConverterUtils.ResetSkinToPristine(skin, EditorGUIUtility.isProSkin ? SkinTarget.Dark : SkinTarget.Light); UpdateGUIStyleProperties(skin); } } }
internal static void PopulateSkin(StyleSheetResolver resolver, GUISkin skin) { var catalog = new StyleCatalog(); catalog.Load(resolver); // Global values: var globalBlock = catalog.GetStyle("*"); if (globalBlock.IsValid()) { skin.font = globalBlock.GetResource(ConverterUtils.k_Font, skin.font); } // builtin (type selector) GUIStyle skin.ForEachGUIStyleProperty((name, style) => { PopulateStyle(catalog, name.Capitalize(), style); }); // CustomStyles var customStyleBlockNames = resolver.Rules.Select(r => r.Key) .Where(ConverterUtils.IsCustomStyleSelector) .Select(GUIStyleExtensions.RuleNameToBlockName) .ToArray(); var blockNameToStyleDict = new Dictionary <string, GUIStyle>(); if (skin.customStyles != null) { // Add Existing style: ready to be overridden: foreach (var customStyle in skin.customStyles) { // GUISkin by default adds a null Style if (customStyle != null) { var blockName = GUIStyleExtensions.StyleNameToBlockName(customStyle.name); blockNameToStyleDict.TryAdd(blockName, customStyle); } } } foreach (var customStyleBlockName in customStyleBlockNames) { GUIStyle customStyle; // Check if we are overriding an existing style or if we are creating a new custom style: if (!blockNameToStyleDict.TryGetValue(customStyleBlockName, out customStyle)) { // New style being added: customStyle = new GUIStyle(); blockNameToStyleDict.Add(customStyleBlockName, customStyle); } PopulateStyle(catalog, customStyleBlockName, customStyle); } skin.customStyles = blockNameToStyleDict.Values.ToArray(); Array.Sort(skin.customStyles, (s1, s2) => s1.name.CompareTo(s2.name)); // GUISettings var settingsBlock = catalog.GetStyle("imgui-skin-settings"); if (settingsBlock.IsValid()) { skin.settings.selectionColor = settingsBlock.GetColor(ConverterUtils.k_SelectionColor, skin.settings.selectionColor); skin.settings.cursorColor = settingsBlock.GetColor(ConverterUtils.k_CursorColor, skin.settings.cursorColor); skin.settings.cursorFlashSpeed = settingsBlock.GetFloat(ConverterUtils.k_CursorFlashSpeed, skin.settings.cursorFlashSpeed); skin.settings.doubleClickSelectsWord = settingsBlock.GetBool(ConverterUtils.k_DoubleClickSelectsWord, skin.settings.doubleClickSelectsWord); skin.settings.tripleClickSelectsLine = settingsBlock.GetBool(ConverterUtils.k_TripleClickSelectsLine, skin.settings.tripleClickSelectsLine); } }
internal static void PopulateStyle(StyleCatalog catalog, string styleBlockName, GUIStyle style) { GUIStyleExtensions.PopulateStyle(catalog, style, styleBlockName, false); }
static EditorResources() { styleCatalog = new StyleCatalog(); }
static EditorResources() { styleCatalog = new StyleCatalog(); styleCatalog.Load(GetDefaultStyleCatalogPaths()); }
internal static void BuildCatalog() { using (new EditorPerformanceTracker(nameof(BuildCatalog))) { s_StyleCatalog = new StyleCatalog(); bool rebuildCatalog = true; List <string> paths = new List <string>(); string catalogHash = ""; if (!EditorApplication.isBuildingAnyResources) { paths = GetDefaultStyleCatalogPaths(); foreach (var editorUssPath in AssetDatabase.GetAllAssetPaths().Where(IsEditorStyleSheet)) { var artifactKey = new ArtifactKey(new GUID(AssetDatabase.AssetPathToGUID(editorUssPath))); var artifactID = AssetDatabaseExperimental.LookupArtifact(artifactKey); //Only add it to the list of paths it if has been imported, since later on //the asset will be loaded, and if not imported it will fail. if (artifactID.isValid) { paths.Add(editorUssPath); } } var forceRebuild = s_RefreshGlobalStyleCatalog; s_RefreshGlobalStyleCatalog = false; catalogHash = ComputeCatalogHash(paths); if (!forceRebuild && File.Exists(k_GlobalStyleCatalogCacheFilePath)) { using (var cacheCatalogStream = new FileStream(k_GlobalStyleCatalogCacheFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (var ccReader = new BinaryReader(cacheCatalogStream)) { string cacheHash = ccReader.ReadString(); if (cacheHash == catalogHash) { rebuildCatalog = !styleCatalog.Load(ccReader); } } } } } if (rebuildCatalog) { Console.WriteLine($"Loading style catalogs ({paths.Count})\r\n\t{String.Join("\r\n\t", paths.ToArray())}"); styleCatalog.Load(paths); if (paths.Count != 0) { SaveCatalogToDisk(styleCatalog, catalogHash, k_GlobalStyleCatalogCacheFilePath); } } } }
internal static void PopulateStyle(StyleCatalog catalog, GUIStyle style, string blockName, bool useExtensionDefaultValues = true) { if (string.IsNullOrEmpty(blockName)) { blockName = ConverterUtils.EscapeSelectorName(style.name); } var styleBlock = catalog.GetStyle(blockName); var rootBlock = catalog.GetStyle(StyleCatalogKeyword.root, StyleState.root); style.name = styleBlock.GetText(ConverterUtils.k_Name, style.name); if (string.IsNullOrEmpty(style.name)) { style.name = BlockNameToStyleName(blockName); } style.fixedWidth = styleBlock.GetFloat(StyleCatalogKeyword.width, style.fixedWidth); style.fixedHeight = styleBlock.GetFloat(StyleCatalogKeyword.height, style.fixedHeight); GetStyleRectOffset(styleBlock, "margin", style.margin); GetStyleRectOffset(styleBlock, "padding", style.padding); style.stretchHeight = styleBlock.GetBool("-unity-stretch-height".GetHashCode(), style.stretchHeight); style.stretchWidth = styleBlock.GetBool("-unity-stretch-width".GetHashCode(), style.stretchWidth); GetStyleRectOffset(styleBlock, "-unity-slice", style.border); GetStyleRectOffset(styleBlock, "-unity-overflow", style.overflow); var contentOffsetKey = "-unity-content-offset".GetHashCode(); if (styleBlock.HasValue(contentOffsetKey, StyleValue.Type.Rect)) { var contentOffsetSize = styleBlock.GetRect(contentOffsetKey); style.contentOffset = new Vector2(contentOffsetSize.width, contentOffsetSize.height); } // Support both properties for font: style.font = styleBlock.GetResource <Font>("-unity-font".GetHashCode(), style.font); style.font = styleBlock.GetResource <Font>("font".GetHashCode(), style.font); if (style.fontSize == 0 || styleBlock.HasValue(StyleCatalogKeyword.fontSize, StyleValue.Type.Number)) { style.fontSize = styleBlock.GetInt(StyleCatalogKeyword.fontSize, style.fontSize); } var fontStyleStr = styleBlock.GetText(ConverterUtils.k_FontStyle.GetHashCode()); var fontWeightStr = styleBlock.GetText(ConverterUtils.k_FontWeight.GetHashCode()); FontStyle fontStyle; if (ConverterUtils.TryGetFontStyle(fontStyleStr, fontWeightStr, out fontStyle)) { style.fontStyle = fontStyle; } style.imagePosition = ConverterUtils.ToImagePosition(styleBlock.GetText("-unity-image-position".GetHashCode(), ConverterUtils.ToUssString(style.imagePosition))); style.clipping = ConverterUtils.ToTextClipping(styleBlock.GetText("-unity-clipping".GetHashCode(), ConverterUtils.ToUssString(style.clipping))); style.alignment = ConverterUtils.ToTextAnchor(styleBlock.GetText("-unity-text-align".GetHashCode(), ConverterUtils.ToUssString(style.alignment))); style.richText = styleBlock.GetBool("-unity-rich-text".GetHashCode(), style.richText); style.wordWrap = styleBlock.GetBool("-unity-word-wrap".GetHashCode(), style.wordWrap); var defaultStyleState = useExtensionDefaultValues ? new GUIStyleState() { textColor = styleBlock.GetColor(StyleCatalogKeyword.color, rootBlock.GetColor("--unity-text-color")) } : null; PopulateStyleState(styleBlock, style.normal, defaultStyleState); PopulateStyleState(catalog.GetStyle(blockName, StyleState.hover), style.hover, defaultStyleState); PopulateStyleState(catalog.GetStyle(blockName, StyleState.focus), style.focused, defaultStyleState); // Supports GUISkin Generation selector that assumes GUIStyle.active maps to :hover:active PopulateStyleState(catalog.GetStyle(blockName, StyleState.hover | StyleState.active), style.active, defaultStyleState); PopulateStyleState(catalog.GetStyle(blockName, StyleState.active), style.active, null); //// All "on" states uses their parent pseudo class (without :checked) as their default value PopulateStyleState(catalog.GetStyle(blockName, StyleState.@checked), style.onNormal, useExtensionDefaultValues ? style.normal : null); PopulateStyleState(catalog.GetStyle(blockName, StyleState.@checked | StyleState.hover), style.onHover, useExtensionDefaultValues ? style.hover : null); // Supports GUISkin Generation selector that assumes GUIStyle.onActive maps to :hover:active:checked PopulateStyleState(catalog.GetStyle(blockName, StyleState.@checked | StyleState.active), style.onActive, useExtensionDefaultValues ? style.active : null); PopulateStyleState(catalog.GetStyle(blockName, StyleState.@checked | StyleState.hover | StyleState.active), style.onActive, null); // Supports GUISkin Generation selector that assumes GUIStyle.onFocused maps to:hover:focus:checked PopulateStyleState(catalog.GetStyle(blockName, StyleState.@checked | StyleState.focus), style.onFocused, useExtensionDefaultValues ? style.focused : null); PopulateStyleState(catalog.GetStyle(blockName, StyleState.@checked | StyleState.hover | StyleState.focus), style.onFocused, null); }