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 | |
} | |
} |
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 with NonSerializable
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Test.cs
in your projectOld.cs
in your newly createdTest.cs
Old String
New.cs
inTest.cs
New String
using the data that was before onOld String
Old.cs
, and will get the data that you got inNew String
there