Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Editor/Core/UIElements/LoadingSpinner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,22 @@ public LoadingSpinner()
innerElement = new VisualElement();
innerElement.AddToClassList("loading-spinner");
innerElement.AddToClassList("hidden");
#if UNITY_2021_2_OR_NEWER
// In Unity 2021.2 and later, transform origin of elements changed from
// top-left to center by default.
// https://discussions.unity.com/t/introducing-transform-styles/861646
// To maintain the same behavior as before, we set the transform origin to top-left.
style.transformOrigin = new TransformOrigin(Length.Percent(0), Length.Percent(0), 0);
#endif
SetLoadingSpinnerBackground();

Add(innerElement);
}

private void UpdateProgress()
{
transform.rotation = Quaternion.Euler(0, 0, m_Rotation);

m_Rotation += 3;
if (m_Rotation > 360)
m_Rotation -= 360;
Expand Down Expand Up @@ -59,5 +69,18 @@ public void Stop()
started = false;
innerElement.AddToClassList("hidden");
}

private void SetLoadingSpinnerBackground()
{
// Unity 2019.1+ includes this as a loaded resource, but in earlier versions
// we need to load it from the Unity Package Manager package's resources.
#if UNITY_2019_1_OR_NEWER
innerElement.style.backgroundImage = new StyleBackground(
(Texture2D)EditorGUIUtility.Load("icons/packagemanager/dark/loading.png")
);
#else
innerElement.style.backgroundImage = AssetDatabase.LoadAssetAtPath<Texture2D>("Packages/com.unity.package-manager-ui/Editor/Resources/Images/Dark/loading.png");
#endif
}
}
}
1 change: 0 additions & 1 deletion UXML/PackageManager/PackageSource.uss
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ LoadingSpinner{

}
.loading-spinner {
background-image: resource("icons/packagemanager/dark/loading.png");
top: -8px;
left: -8px;
width: 16px;
Expand Down
Loading