diff --git a/Assets/Scripts/GUI/SketchbookPanel.cs b/Assets/Scripts/GUI/SketchbookPanel.cs index 1546a4ff7f..29373c5ccf 100644 --- a/Assets/Scripts/GUI/SketchbookPanel.cs +++ b/Assets/Scripts/GUI/SketchbookPanel.cs @@ -219,24 +219,19 @@ protected override void OnStart() SetVisibleSketchSet(0); RefreshPage(); - Action refresh = () => - { - if (m_ContactingServerMessage.activeSelf || - m_NoShowcaseMessage.activeSelf || - m_LoadingGallery.activeSelf) - { - // Update the overlays more frequently when these overlays are shown to reflect whether - // we are actively trying to get sketches from Poly. - RefreshPage(); - } - }; + App.GoogleIdentity.OnLogout += OnSketchRefreshingChanged; + } - // TODO: We probably should just do a refresh when we enter a sketchset - // SketchCatalog.m_Instance.GetSet(1).OnSketchRefreshingChanged += refresh; - // SketchCatalog.m_Instance.GetSet(2).OnSketchRefreshingChanged += refresh; - // SketchCatalog.m_Instance.GetSet(3).OnSketchRefreshingChanged += refresh; - // Should we just loop through the root ones here? - App.GoogleIdentity.OnLogout += refresh; + void OnSketchRefreshingChanged() + { + if (m_ContactingServerMessage.activeSelf || + m_NoShowcaseMessage.activeSelf || + m_LoadingGallery.activeSelf) + { + // Update the overlays more frequently when these overlays are shown to reflect whether + // we are actively trying to get sketches from Poly. + RefreshPage(); + } } void OnDestroy() @@ -244,6 +239,7 @@ void OnDestroy() if (CurrentSketchSet != null) { CurrentSketchSet.OnChanged -= OnSketchSetDirty; + CurrentSketchSet.OnSketchRefreshingChanged -= OnSketchRefreshingChanged; } } @@ -284,12 +280,14 @@ void SetVisibleSketchSet(RootSet stack) if (CurrentSketchSet != null) { CurrentSketchSet.OnChanged -= OnSketchSetDirty; + CurrentSketchSet.OnSketchRefreshingChanged -= OnSketchRefreshingChanged; } // Cache new set. m_SelectedStack = stackIndex; CurrentSketchSet = m_SetStacks[m_SelectedStack].Peek(); CurrentSketchSet.OnChanged += OnSketchSetDirty; + CurrentSketchSet.OnSketchRefreshingChanged += OnSketchRefreshingChanged; CurrentSketchSet.RequestRefresh(); // Tell all the icons which set to reference when loading sketches. diff --git a/Assets/Scripts/ResourceSystem/ResourceCollectionSketchSet.cs b/Assets/Scripts/ResourceSystem/ResourceCollectionSketchSet.cs index 11888285a6..ddb7a62261 100644 --- a/Assets/Scripts/ResourceSystem/ResourceCollectionSketchSet.cs +++ b/Assets/Scripts/ResourceSystem/ResourceCollectionSketchSet.cs @@ -133,12 +133,23 @@ private void FetchSketchesToAtLeast(int index) private async Task FetchSketchesToAtLeastAsync(int index) { int totalIndex = index + m_LookAhead; + bool updated = false; while (await m_ResourceEnumerator.MoveNextAsync() && totalIndex > NumSketches) { + if (!updated) + { + OnSketchRefreshingChanged?.Invoke(); + } var resource = m_ResourceEnumerator.Current; var fileInfo = new ResourceFileInfo(resource); var sketch = new ResourceSketch(fileInfo); m_Sketches.Add(sketch); + updated = true; + } + if (updated) + { + OnSketchRefreshingChanged?.Invoke(); + OnChanged?.Invoke(); } }