Skip to content

Commit 6360b6e

Browse files
committed
Force credit system to recreate entering playmode
1 parent 16337a3 commit 6360b6e

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## ? - ?
4+
5+
##### Fixes :wrench:
6+
7+
- Fixed a bug where credits would not display in the Game tab after entering Play Mode.
8+
39
## v1.15.5
410

511
##### Fixes :wrench:

Runtime/CesiumCreditSystem.cs

Lines changed: 21 additions & 3 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>
@@ -160,6 +161,7 @@ private void OnEnable()
160161

161162
Cesium3DTileset.OnSetShowCreditsOnScreen += this.ForceUpdateCredits;
162163
#if UNITY_EDITOR
164+
EditorApplication.playModeStateChanged += HandleEnteringPlayMode;
163165
EditorSceneManager.sceneClosing += HandleClosingSceneView;
164166
#endif
165167
}
@@ -183,8 +185,12 @@ private void OnDestroy()
183185

184186
this._images.Clear();
185187

186-
if (_defaultCreditSystem == this)
188+
if (this == _defaultCreditSystem)
187189
{
190+
#if UNITY_EDITOR
191+
EditorApplication.playModeStateChanged -= HandleEnteringPlayMode;
192+
EditorSceneManager.sceneClosing -= HandleClosingSceneView;
193+
#endif
188194
_defaultCreditSystem = null;
189195
}
190196
}
@@ -322,7 +328,6 @@ internal IEnumerator LoadImage(string url)
322328
texture.wrapMode = TextureWrapMode.Clamp;
323329
}
324330

325-
326331
#if UNITY_EDITOR
327332
/// <summary>
328333
/// This handles the destruction of the credit system between scene switches in the Unity Editor.
@@ -338,6 +343,19 @@ private static void HandleClosingSceneView(Scene scene, bool removingScene)
338343
UnityLifetime.Destroy(_defaultCreditSystem.gameObject);
339344
}
340345
}
346+
347+
/// <summary>
348+
/// This handles the destruction of the credit system while entering Play Mode.
349+
/// Without this, the persisting credit system's UI will not register with the Play Mode view, leading
350+
/// to missing credits.
351+
/// </summary>
352+
/// <param name="state">The state change between the Edit and Play modes.</param>
353+
private static void HandleEnteringPlayMode(PlayModeStateChange state)
354+
{
355+
if (state == PlayModeStateChange.EnteredPlayMode && _defaultCreditSystem != null) {
356+
UnityLifetime.Destroy(_defaultCreditSystem.gameObject);
357+
}
358+
}
341359
#endif
342360
}
343361
}

0 commit comments

Comments
 (0)