1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- using UnityEngine;
- namespace Pathfinding {
-
- public interface IVersionedMonoBehaviourInternal {
- void UpgradeFromUnityThread();
- }
-
- public abstract class VersionedMonoBehaviour : MonoBehaviour, ISerializationCallbackReceiver, IVersionedMonoBehaviourInternal {
-
- [SerializeField]
- [HideInInspector]
- int version = 0;
- protected virtual void Awake () {
-
-
-
- if (Application.isPlaying) version = OnUpgradeSerializedData(int.MaxValue, true);
- }
-
- protected virtual void Reset () {
-
- version = OnUpgradeSerializedData(int.MaxValue, true);
- }
-
- void ISerializationCallbackReceiver.OnBeforeSerialize () {
- }
-
- void ISerializationCallbackReceiver.OnAfterDeserialize () {
- var r = OnUpgradeSerializedData(version, false);
-
- if (r >= 0) version = r;
- }
-
- protected virtual int OnUpgradeSerializedData (int version, bool unityThread) {
- return 1;
- }
- void IVersionedMonoBehaviourInternal.UpgradeFromUnityThread () {
- var r = OnUpgradeSerializedData(version, true);
- if (r < 0) throw new System.Exception();
- version = r;
- }
- }
- }
|