Skip to content

Commit

Permalink
Add version information to serialized asset classes (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
matteblair authored Dec 7, 2017
1 parent b7c5547 commit 49b2923
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
18 changes: 15 additions & 3 deletions Assets/Mapzen/Unity/MapStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,26 @@ namespace Mapzen.Unity
[CreateAssetMenu(menuName = "Mapzen/MapStyle")]
public class MapStyle : ScriptableObject
{
public List<FeatureLayer> Layers;
// Version information
// This allows us to check whether an asset was serialized with a different version than this code.
// If a serialized field of this class is changed or renamed, currentAssetVersion should be incremented.

private const int currentAssetVersion = 1;
[SerializeField] private int serializedAssetVersion = currentAssetVersion;

public List<FeatureLayer> Layers = new List<FeatureLayer>();

[SerializeField]
private bool liveUpdateEnabled;

public MapStyle()
void OnEnable()
{
this.Layers = new List<FeatureLayer>();
if (serializedAssetVersion != currentAssetVersion)
{
Debug.LogWarningFormat("The MapStyle \"{0}\" was created with a different version of this tool. " +
"Some properties may be missing or have unexpected values.", this.name);
serializedAssetVersion = currentAssetVersion;
}
}
}
}
17 changes: 17 additions & 0 deletions Assets/RegionMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ namespace Mapzen
{
public class RegionMap : MonoBehaviour
{
// Version information
// This allows us to check whether an asset was serialized with a different version than this code.
// If a serialized field of this class is changed or renamed, currentAssetVersion should be incremented.

private const int currentAssetVersion = 1;
[SerializeField] private int serializedAssetVersion = currentAssetVersion;

// Public fields
// These are serialized, so renaming them will break asset compatibility.

Expand Down Expand Up @@ -224,5 +231,15 @@ public void LogErrors()
Debug.LogError("Make sure to set a MapStyle");
}
}

public void OnValidate()
{
if (serializedAssetVersion != currentAssetVersion)
{
Debug.LogWarningFormat("The RegionMap \"{0}\" was created with a different version of this tool. " +
"Some properties may be missing or have unexpected values.", this.name);
serializedAssetVersion = currentAssetVersion;
}
}
}
}
1 change: 1 addition & 0 deletions Assets/Scenes/DefaultScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 673da631ad95c423cbdabfdc9202e581, type: 3}
m_Name:
m_EditorClassIdentifier:
serializedAssetVersion: 1
ApiKey:
Area:
min:
Expand Down
2 changes: 2 additions & 0 deletions Assets/Scenes/SimpleMapStyle.asset
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: a4edcc12ded754f86bc8b9ea3b3c3ee6, type: 3}
m_Name: SimpleMapStyle
m_EditorClassIdentifier:
serializedAssetVersion: 1
Layers:
- Name: Water
FeatureCollection: 256
Expand Down Expand Up @@ -116,3 +117,4 @@ MonoBehaviour:
Width: 0
MiterLimit: 0
Enabled: 0
liveUpdateEnabled: 0

0 comments on commit 49b2923

Please sign in to comment.