Skip to content

Commit

Permalink
Use default ion server when loading old tilesets/overlays.
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Dec 11, 2023
1 parent 0f62063 commit b31c806
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
34 changes: 32 additions & 2 deletions Runtime/Cesium3DTileset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public enum CesiumDataSource
[ReinteropNativeImplementation("CesiumForUnityNative::Cesium3DTilesetImpl", "Cesium3DTilesetImpl.h")]
[AddComponentMenu("Cesium/Cesium 3D Tileset")]
[IconAttribute("Packages/com.cesium.unity/Editor/Resources/Cesium-24x24.png")]
public partial class Cesium3DTileset : MonoBehaviour, IDisposable
public partial class Cesium3DTileset : MonoBehaviour, IDisposable, ISerializationCallbackReceiver
{
public void Dispose()
{
Expand Down Expand Up @@ -186,7 +186,20 @@ public CesiumIonServer ionServer
{
get
{
if (this._ionServer == null) this._ionServer = CesiumIonServer.currentForNewObjects;
if (this._ionServer == null)
{
#if UNITY_EDITOR
// See OnAfterDeserialize.
if (this._useDefaultServer)
this._ionServer = CesiumIonServer.defaultServer;
else
this._ionServer = CesiumIonServer.currentForNewObjects;

this._useDefaultServer = false;
#else
this._ionServer = CesiumIonServer.currentForNewObjects;
#endif
}
return this._ionServer;
}
set
Expand Down Expand Up @@ -698,5 +711,22 @@ public bool createPhysicsMeshes
/// Zoom the Editor camera to this tileset. This method does nothing outside of the Editor.
/// </summary>
public partial void FocusTileset();

void ISerializationCallbackReceiver.OnBeforeSerialize()
{
}

void ISerializationCallbackReceiver.OnAfterDeserialize()
{
#if UNITY_EDITOR
// For backward compatibility, tilesets loaded without a server should adopt the default one.
if (this._ionServer == null)
this._useDefaultServer = true;
#endif
}

#if UNITY_EDITOR
private bool _useDefaultServer = false;
#endif
}
}
34 changes: 32 additions & 2 deletions Runtime/CesiumIonRasterOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace CesiumForUnity
[ReinteropNativeImplementation("CesiumForUnityNative::CesiumIonRasterOverlayImpl", "CesiumIonRasterOverlayImpl.h")]
[AddComponentMenu("Cesium/Cesium Ion Raster Overlay")]
[IconAttribute("Packages/com.cesium.unity/Editor/Resources/Cesium-24x24.png")]
public partial class CesiumIonRasterOverlay : CesiumRasterOverlay
public partial class CesiumIonRasterOverlay : CesiumRasterOverlay, ISerializationCallbackReceiver
{
[SerializeField]
private long _ionAssetID = 0;
Expand Down Expand Up @@ -53,7 +53,20 @@ public CesiumIonServer ionServer
{
get
{
if (this._ionServer == null) this._ionServer = CesiumIonServer.currentForNewObjects;
if (this._ionServer == null)
{
#if UNITY_EDITOR
// See OnAfterDeserialize.
if (this._useDefaultServer)
this._ionServer = CesiumIonServer.defaultServer;
else
this._ionServer = CesiumIonServer.currentForNewObjects;

this._useDefaultServer = false;
#else
this._ionServer = CesiumIonServer.currentForNewObjects;
#endif
}
return this._ionServer;
}
set
Expand All @@ -68,5 +81,22 @@ public CesiumIonServer ionServer
protected override partial void AddToTileset(Cesium3DTileset tileset);
/// <inheritdoc/>
protected override partial void RemoveFromTileset(Cesium3DTileset tileset);

void ISerializationCallbackReceiver.OnBeforeSerialize()
{
}

void ISerializationCallbackReceiver.OnAfterDeserialize()
{
#if UNITY_EDITOR
// For backward compatibility, tilesets loaded without a server should adopt the default one.
if (this._ionServer == null)
this._useDefaultServer = true;
#endif
}

#if UNITY_EDITOR
private bool _useDefaultServer = false;
#endif
}
}

0 comments on commit b31c806

Please sign in to comment.