Skip to content

Commit

Permalink
Resource Sketchsets work now with large collections that don't all lo…
Browse files Browse the repository at this point in the history
…ad at once now
  • Loading branch information
TimAidley committed Mar 21, 2023
1 parent c494007 commit 3a4c9a3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
32 changes: 15 additions & 17 deletions Assets/Scripts/GUI/SketchbookPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,31 +219,27 @@ 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()
{
if (CurrentSketchSet != null)
{
CurrentSketchSet.OnChanged -= OnSketchSetDirty;
CurrentSketchSet.OnSketchRefreshingChanged -= OnSketchRefreshingChanged;
}
}

Expand Down Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions Assets/Scripts/ResourceSystem/ResourceCollectionSketchSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down

0 comments on commit 3a4c9a3

Please sign in to comment.