@@ -32,7 +32,8 @@ CesiumCreditSystemImpl::CesiumCreditSystemImpl(
3232 : _pCreditSystem(std::make_shared<CesiumUtility::CreditSystem>()),
3333 _htmlToUnityCredit (),
3434 _lastCreditsCount(0 ),
35- _creditsUpdated(false ) {}
35+ _lastLoadingImagesCount(0 ),
36+ _shouldBroadcastUpdate(false ) {}
3637
3738CesiumCreditSystemImpl::~CesiumCreditSystemImpl () {}
3839
@@ -43,24 +44,32 @@ void CesiumCreditSystemImpl::UpdateCredits(
4344 return ;
4445 }
4546
46- // If the credits were updated in a previous frame, the update will not get
47- // broadcasted until all of the images are fully loaded. Broadcast the
48- // previous update first before handling the next one.
49- if (this ->_creditsUpdated && !creditSystem.HasLoadingImages ()) {
47+ // Images are handled asynchronously by Unity's coroutine system, so their
48+ // progress must be accounted for separately.
49+ size_t loadingImagesCount = creditSystem.GetNumberOfLoadingImages ();
50+ if (loadingImagesCount != this ->_lastLoadingImagesCount ) {
51+ this ->_shouldBroadcastUpdate = true ;
52+ this ->_lastLoadingImagesCount = loadingImagesCount;
53+ }
54+
55+ // If the credits were updated in a previous frame, do not broadcast the
56+ // update until all of the images are fully loaded. Then, broadcast the
57+ // previous update before handling the next one.
58+ if (this ->_shouldBroadcastUpdate && loadingImagesCount == 0 ) {
5059 creditSystem.BroadcastCreditsUpdate ();
51- this ->_creditsUpdated = false ;
60+ this ->_shouldBroadcastUpdate = false ;
5261 }
5362
5463 const CesiumUtility::CreditsSnapshot& credits = _pCreditSystem->getSnapshot ();
5564 const std::vector<CesiumUtility::Credit>& creditsToShowThisFrame =
5665 credits.currentCredits ;
5766
5867 size_t creditsCount = creditsToShowThisFrame.size ();
59- this -> _creditsUpdated = forceUpdate ||
60- creditsToShowThisFrame.size () != _lastCreditsCount ||
61- credits.removedCredits .size () > 0 ;
68+ bool creditsUpdated =
69+ forceUpdate || creditsToShowThisFrame.size () != this -> _lastCreditsCount ||
70+ credits.removedCredits .size () > 0 ;
6271
63- if (this -> _creditsUpdated ) {
72+ if (creditsUpdated ) {
6473 List1<CesiumForUnity::CesiumCredit> popupCredits =
6574 creditSystem.popupCredits ();
6675 List1<CesiumForUnity::CesiumCredit> onScreenCredits =
@@ -94,8 +103,8 @@ void CesiumCreditSystemImpl::UpdateCredits(
94103 }
95104 }
96105
97- this ->_creditsUpdated = true ;
98106 this ->_lastCreditsCount = creditsCount;
107+ this ->_shouldBroadcastUpdate = true ;
99108 }
100109}
101110
0 commit comments