Created
October 7, 2014 13:38
-
-
Save frarees/29ca649090310f3c1ffa to your computer and use it in GitHub Desktop.
Class Layout Update on Unity3D
This file contains 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
using UnityEngine; | |
using System.Collections; | |
#if UNITY_EDITOR | |
using UnityEditor; | |
#endif | |
public class Test : MonoBehaviour, ISerializationCallbackReceiver { | |
[SerializeField, HideInInspector] int m_SerializedVersion; | |
[SerializeField] string m_NewString; | |
#if UNITY_EDITOR | |
string m_Buffer; | |
#endif | |
void ISerializationCallbackReceiver.OnBeforeSerialize () { | |
} | |
void ISerializationCallbackReceiver.OnAfterDeserialize () { | |
#if UNITY_EDITOR | |
if (m_SerializedVersion < 1) { | |
m_NewString = m_Buffer; | |
} | |
m_SerializedVersion = 1; | |
#endif | |
} | |
} |
This file contains 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
using UnityEngine; | |
using System.Collections; | |
#if UNITY_EDITOR | |
using UnityEditor; | |
#endif | |
public class Test : MonoBehaviour, ISerializationCallbackReceiver { | |
[SerializeField, HideInInspector] int m_SerializedVersion; | |
[SerializeField] string m_OldString; | |
#if UNITY_EDITOR | |
string m_Buffer; | |
#endif | |
void ISerializationCallbackReceiver.OnBeforeSerialize () { | |
#if UNITY_EDITOR | |
m_Buffer = m_OldString; | |
#endif | |
} | |
void ISerializationCallbackReceiver.OnAfterDeserialize () { | |
#if UNITY_EDITOR | |
if (m_SerializedVersion > 0) { | |
m_OldString = m_Buffer; | |
} | |
m_SerializedVersion = 0; | |
#endif | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that
m_Buffer
is actually serialized and not saved to disk (i.e. data will survive an assembly reload). This won't work if you mark that field withNonSerializable
.