Created
September 30, 2013 18:38
-
-
Save lucasmeijer/6768143 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[DataVersion(2)] | |
public MyClass : MonoBehaviour | |
{ | |
public float m_myFloatThatUsedToBeAnInt; | |
} | |
#if UNITY_EDITOR | |
static class DataUpdater | |
{ | |
[DataUpdaterFor(typeof(MyClass))] | |
static void DeserializeOldData(SerializedObject oldData, SerializedObject newData) | |
{ | |
//oldData is the old serialized data | |
//newData will be populated by Unity with a "best guess" (similar to what unity does today) | |
//it's up to you to set newData serialized data to be how you want it | |
//this method would be called when the typetree between stored data and new class is different. | |
//(i.e. you added or changed a field), or when the DataVersion is different between the stored data | |
//and the current code | |
//Questions: do you think it's good enough to have this API only work on MonoBehaviour/ScriptableObject, | |
//and not on arbitrary nested classes. (you could update those too, but the code for that has to be in the consuming | |
//monobehaviour, and not in the custom class itself) | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How common of a problem is this? The few times I've needed to migrate data between types in Unity, I did it by directly monkeying with the YAML serialized data (of a .prefab or .scene). You could provide a YAML munging library and let people go nuts with it.