8
8
9
9
#if UNITY_EDITOR
10
10
using UnityEditor . SceneManagement ;
11
+ using UnityEditor ;
11
12
#endif
12
13
13
14
namespace CesiumForUnity
@@ -102,8 +103,8 @@ public partial class CesiumCreditSystem : MonoBehaviour
102
103
private int _numLoadingImages = 0 ;
103
104
104
105
const string base64Prefix = "data:image/png;base64," ;
105
- const string defaultName = "CesiumCreditSystemDefault" ;
106
106
const string creditSystemPrefabName = "CesiumCreditSystem" ;
107
+ const string defaultName = "CesiumCreditSystemDefault" ;
107
108
108
109
#region Fields and Events
109
110
/// <summary>
@@ -160,6 +161,7 @@ private void OnEnable()
160
161
161
162
Cesium3DTileset . OnSetShowCreditsOnScreen += this . ForceUpdateCredits ;
162
163
#if UNITY_EDITOR
164
+ EditorApplication . playModeStateChanged += HandleEnteringPlayMode ;
163
165
EditorSceneManager . sceneClosing += HandleClosingSceneView ;
164
166
#endif
165
167
}
@@ -183,8 +185,12 @@ private void OnDestroy()
183
185
184
186
this . _images . Clear ( ) ;
185
187
186
- if ( _defaultCreditSystem == this )
188
+ if ( this == _defaultCreditSystem )
187
189
{
190
+ #if UNITY_EDITOR
191
+ EditorApplication . playModeStateChanged -= HandleEnteringPlayMode ;
192
+ EditorSceneManager . sceneClosing -= HandleClosingSceneView ;
193
+ #endif
188
194
_defaultCreditSystem = null ;
189
195
}
190
196
}
@@ -322,7 +328,6 @@ internal IEnumerator LoadImage(string url)
322
328
texture . wrapMode = TextureWrapMode . Clamp ;
323
329
}
324
330
325
-
326
331
#if UNITY_EDITOR
327
332
/// <summary>
328
333
/// 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)
338
343
UnityLifetime . Destroy ( _defaultCreditSystem . gameObject ) ;
339
344
}
340
345
}
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
+ }
341
359
#endif
342
360
}
343
361
}
0 commit comments