Skip to content

Commit e610fb5

Browse files
authored
Merge pull request #567 from CesiumGS/fix-play-mode-credits
Fix credits not appearing in Play Mode
2 parents cffa3b9 + a719f01 commit e610fb5

7 files changed

+94
-32
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- Added `CesiumUrlTemplateRasterOverlay` component, allowing a raster overlay to be added using tiles requested based on a specified URL template.
88

9+
##### Fixes :wrench:
10+
11+
- Fixed a bug where credits would not display in the Game tab after entering Play Mode.
12+
913
## v1.15.5 - 2025-04-01
1014

1115
##### Fixes :wrench:

Editor/CesiumCreditSystemManager.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using UnityEditor;
2+
using UnityEditor.SceneManagement;
3+
using UnityEngine;
4+
using UnityEngine.SceneManagement;
5+
6+
namespace CesiumForUnity
7+
{
8+
[InitializeOnLoad]
9+
public static class CesiumCreditSystemManager
10+
{
11+
static CesiumCreditSystemManager()
12+
{
13+
EditorApplication.playModeStateChanged += HandleEnteringPlayMode;
14+
EditorSceneManager.sceneClosing += HandleClosingScene;
15+
}
16+
17+
/// <summary>
18+
/// This handles the destruction of the default credit system between scene switches in the
19+
/// Unity Editor.
20+
/// Without this, the credit system will live between instances and fail to capture the current
21+
/// scene's credits.
22+
/// </summary>
23+
/// <param name="scene">The scene.</param>
24+
/// <param name="removingScene">Whether the scene is being removed.</param>
25+
private static void HandleClosingScene(Scene scene, bool removingScene)
26+
{
27+
Destroy(CesiumCreditSystem.GetDefaultCreditSystem());
28+
}
29+
30+
/// <summary>
31+
/// This handles the destruction of the default credit system while entering Play Mode.
32+
/// Without this, the persisting credit system's UI will not register with the Play Mode view, leading
33+
/// to missing credits.
34+
/// </summary>
35+
/// <param name="state">The state change between the Edit and Play modes.</param>
36+
private static void HandleEnteringPlayMode(PlayModeStateChange state)
37+
{
38+
if (state == PlayModeStateChange.EnteredPlayMode)
39+
{
40+
Destroy(CesiumCreditSystem.GetDefaultCreditSystem());
41+
}
42+
}
43+
44+
/// <summary>
45+
/// Destroys the input credit system depending on the current Editor context. This is the same as
46+
/// the internal UnityLifetime class (which is currently inaccessible from Editor classes).
47+
/// </summary>
48+
/// <param name="creditSystem">The credit system.</param>
49+
private static void Destroy(CesiumCreditSystem creditSystem)
50+
{
51+
if (creditSystem == null) { return; }
52+
53+
// In the Editor, we must use DestroyImmediate because Destroy won't
54+
// actually destroy the object.
55+
if (!EditorApplication.isPlaying)
56+
{
57+
Object.DestroyImmediate(creditSystem.gameObject);
58+
return;
59+
}
60+
61+
Object.Destroy(creditSystem.gameObject);
62+
}
63+
}
64+
}

Editor/CesiumCreditSystemManager.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/CesiumCreditSystem.cs

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#if UNITY_EDITOR
1010
using UnityEditor.SceneManagement;
11+
using UnityEditor;
1112
#endif
1213

1314
namespace CesiumForUnity
@@ -102,8 +103,8 @@ public partial class CesiumCreditSystem : MonoBehaviour
102103
private int _numLoadingImages = 0;
103104

104105
const string base64Prefix = "data:image/png;base64,";
105-
const string defaultName = "CesiumCreditSystemDefault";
106106
const string creditSystemPrefabName = "CesiumCreditSystem";
107+
const string defaultName = "CesiumCreditSystemDefault";
107108

108109
#region Fields and Events
109110
/// <summary>
@@ -159,9 +160,6 @@ private void OnEnable()
159160
this._images = new List<Texture2D>();
160161

161162
Cesium3DTileset.OnSetShowCreditsOnScreen += this.ForceUpdateCredits;
162-
#if UNITY_EDITOR
163-
EditorSceneManager.sceneClosing += HandleClosingSceneView;
164-
#endif
165163
}
166164

167165
private void Update()
@@ -183,7 +181,7 @@ private void OnDestroy()
183181

184182
this._images.Clear();
185183

186-
if (_defaultCreditSystem == this)
184+
if (this == _defaultCreditSystem)
187185
{
188186
_defaultCreditSystem = null;
189187
}
@@ -246,7 +244,7 @@ private static CesiumCreditSystem CreateDefaultCreditSystem()
246244
/// Gets the default credit system, or creates a new default credit system instance if none exist.
247245
/// </summary>
248246
/// <returns>The default CesiumCreditSystem instance.</returns>
249-
internal static CesiumCreditSystem GetDefaultCreditSystem()
247+
public static CesiumCreditSystem GetDefaultCreditSystem()
250248
{
251249
if (_defaultCreditSystem == null)
252250
{
@@ -321,23 +319,5 @@ internal IEnumerator LoadImage(string url)
321319

322320
texture.wrapMode = TextureWrapMode.Clamp;
323321
}
324-
325-
326-
#if UNITY_EDITOR
327-
/// <summary>
328-
/// This handles the destruction of the credit system between scene switches in the Unity Editor.
329-
/// Without this, the credit system will live between instances and won't properly render the
330-
/// current scene's credits.
331-
/// </summary>
332-
/// <param name="scene">The scene.</param>
333-
/// <param name="removingScene">Whether or not the closing scene is also being removed.</param>
334-
private static void HandleClosingSceneView(Scene scene, bool removingScene)
335-
{
336-
if (_defaultCreditSystem != null && _defaultCreditSystem.gameObject.scene == scene)
337-
{
338-
UnityLifetime.Destroy(_defaultCreditSystem.gameObject);
339-
}
340-
}
341-
#endif
342322
}
343323
}

native~/Runtime/src/Cesium3DTilesetImpl.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,12 @@ void Cesium3DTilesetImpl::Update(
133133
std::vector<ViewState> viewStates =
134134
CameraManager::getAllCameras(tileset, *this);
135135

136-
const ViewUpdateResult& updateResult = this->_pTileset->updateView(
136+
const ViewUpdateResult& updateResult = this->_pTileset->updateViewGroup(
137+
this->_pTileset->getDefaultViewGroup(),
137138
viewStates,
138139
DotNet::UnityEngine::Time::deltaTime());
140+
this->_pTileset->loadTiles();
141+
139142
this->updateLastViewUpdateResultState(tileset, updateResult);
140143

141144
for (auto pTile : updateResult.tilesFadingOut) {

native~/Runtime/src/CesiumCreditSystemImpl.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,14 @@ void CesiumCreditSystemImpl::UpdateCredits(
5151
this->_creditsUpdated = false;
5252
}
5353

54+
const CesiumUtility::CreditsSnapshot& credits = _pCreditSystem->getSnapshot();
5455
const std::vector<CesiumUtility::Credit>& creditsToShowThisFrame =
55-
this->_pCreditSystem->getCreditsToShowThisFrame();
56+
credits.currentCredits;
57+
5658
size_t creditsCount = creditsToShowThisFrame.size();
57-
this->_creditsUpdated =
58-
forceUpdate || creditsCount != this->_lastCreditsCount ||
59-
this->_pCreditSystem->getCreditsToNoLongerShowThisFrame().size() > 0;
59+
this->_creditsUpdated = forceUpdate ||
60+
creditsToShowThisFrame.size() != _lastCreditsCount ||
61+
credits.removedCredits.size() > 0;
6062

6163
if (this->_creditsUpdated) {
6264
List1<CesiumForUnity::CesiumCredit> popupCredits =
@@ -95,8 +97,6 @@ void CesiumCreditSystemImpl::UpdateCredits(
9597
this->_creditsUpdated = true;
9698
this->_lastCreditsCount = creditsCount;
9799
}
98-
99-
this->_pCreditSystem->startNextFrame();
100100
}
101101

102102
namespace {

native~/extern/cesium-native

Submodule cesium-native updated 60 files

0 commit comments

Comments
 (0)