Sent a bug report just in case to notify of the problem.
Hello, I have a uss file for styling a MiniMap VisualElement:
/*Places the minimap at the top-left corner of the editor window*/
MiniMap
{
margin-left: 0px;
margin-top: 20px;
width: 200px;
height: 200px;
}
In my CustomEditorWindow.cs, in the CreateGUI() method, I simply added :
rootVisualElement.Add(new MiniMap());
Reloading the uss files for any other type selector immediately updates its styling in the window, but not for the Minimap; I have to manually close and reopen the window for the changes to take effect. This does not happen for any of the other built-in VisualElement child types.
Also, attempting to move the MiniMap while its size is different than its default size will snap it back to its default size, as if the style is applied only once on startup, but not actually “serialized”.
Hi!
Where do you apply or add the stylesheet?
Hi, thank you for your time.
I’m applying the stylesheet in the OnEnable() method:
/// <summary>
/// Called when the window is created, but before CreateGUI()
/// </summary>
private void OnEnable()
{
string styleSheetPath = "path/to/uss";
this._styleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>(styleSheetPath);
this.rootVisualElement.styleSheets.Add(this._styleSheet);
}
The MiniMap is created in the CreateGUI() method. It is a child of a GraphView, itself a child of a Tab inside a TabView, attached to the root. Copy-pasting the while thing would be a little bit complicated.
I know the stylesheet itself is responsive as I’m able to swap between two different stylesheets to change e.g. the grid lines’ color, and it works properly. The stylesheet should be applied automatically to any element attached to the rootVisualElement, so I don’t exactly know what’s wrong here.
Here is the whole USS file if that may be useful to you:
/* Unity-specific classes */
GridBackground
{
--grid-background-color: #222222;
--line-color: #222222;
--thick-line-color: #222222;
--spacing: 20;
}
/* Make TabView fill whole window */
TabView, .unity-tab-view__content-container, Tab, .unity-tab__content-container
{
flex-grow: 1;
}
MiniMap
{
margin-left: 0px;
margin-top: 20px;
width: 200px;
height: 200px;
}
/*Custom classes*/
.gridLines
{
--line-color: rgba(51, 51, 51, 0.25);
--thick-line-color: rgba(51, 51, 51, 0.75);
}
.minimapBtn
{
width: 16px;
height: 16px;
position: absolute;
right: 0px;
top: -1px;
background-color: clear;
border-color: #747431;
-unity-background-image-tint-color: #747431;
}
.minimapBtn--anchored
{
background-image: url("../Textures/UI/unlock.png");
}
.minimapBtn--free
{
background-image: url("../Textures/UI/lock.png");
}