public void OnEnable() { this.antiAliasing = 4; titleContent = GetLocalizedTitleContent(); var windowResource = EditorGUIUtility.Load("UXML/AssetStore/AssetStoreWindow.uxml") as VisualTreeAsset; if (windowResource != null) { var root = windowResource.CloneTree(); var lightStyleSheet = EditorGUIUtility.Load(EditorUIService.instance.GetUIToolkitDefaultCommonLightStyleSheetPath()) as StyleSheet; var assetStoreStyleSheet = EditorGUIUtility.Load("StyleSheets/AssetStore/AssetStoreWindow.uss") as StyleSheet; var styleSheet = CreateInstance <StyleSheet>(); styleSheet.isUnityStyleSheet = true; var resolver = new StyleSheets.StyleSheetResolver(); resolver.AddStyleSheets(lightStyleSheet, assetStoreStyleSheet); resolver.ResolveTo(styleSheet); root.styleSheets.Add(styleSheet); rootVisualElement.Add(root); root.StretchToParentSize(); visitWebsiteButton.clickable.clicked += OnVisitWebsiteButtonClicked; launchPackageManagerButton.clickable.clicked += OnLaunchPackageManagerButtonClicked; alwaysOpenInBrowserToggle.SetValueWithoutNotify(EditorPrefs.GetBool("AlwaysOpenAssetStoreInBrowser", false)); alwaysOpenInBrowserToggle.RegisterValueChangedCallback(changeEvent => { EditorPrefs.SetBool("AlwaysOpenAssetStoreInBrowser", changeEvent.newValue); }); } }
public void ResolveParent(StyleSheetResolver resolver) { Rule parentRule; if (!resolver.Rules.TryGetValue(ParentSelectorName, out parentRule) && resolver.Options.ThrowIfCannotResolve) { throw new Exception("Cannot resolve parent: " + ParentSelectorName); } ParentRule = parentRule; }
public List <Rule> ResolveExtendedRules(StyleSheetResolver resolver) { var rules = new List <Rule>(); rules.Add(this); foreach (var pseudoStateRuleName in PseudoStateRules) { rules.Add(resolver.Rules[pseudoStateRuleName]); } return(rules); }
internal static StyleSheetResolver ResolveFromSheetsFolder(IEnumerable <string> folders, SkinTarget target, StyleSheetResolver.ResolvingOptions options = null, string sheetPostFix = "") { var sheetPaths = ConverterUtils.GetSheetPathsFromRootFolders(folders, target, sheetPostFix); if (sheetPaths.Length == 0) { throw new Exception("Cannot find sheets to generate skin"); } var resolver = new StyleSheetResolver(options ?? new StyleSheetResolver.ResolvingOptions() { ThrowIfCannotResolve = true }); foreach (var sheet in sheetPaths) { resolver.AddStyleSheets(sheet); } return(resolver); }
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); } }