Created
October 4, 2013 20:19
-
-
Save lucasmeijer/6832115 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
using System; | |
using NUnit.Framework; | |
using Unity.RuntimeTests.Framework; | |
using UnityEngine; | |
using RuntimePlatform = UnityEngine.Common.Enums.RuntimePlatform; | |
namespace Unity.RuntimeTests.SerializationTests.Callback | |
{ | |
[TestFixture] | |
[ExcludePlatform(RuntimePlatform.FlashPlayer, ExcludePlatformAttribute.ExclusionReason.NotSupported, "this feature was introduced after announcing flash EOL")] | |
public class SerializationCallbackInCustomStruct : RuntimeTest | |
{ | |
public class SerializationCallbackInCustomStructScript : MonoBehaviour | |
{ | |
[Serializable] | |
public struct Custom : INotifyOnSerialization | |
{ | |
public int myint; | |
public int myint2; | |
public int myint3; | |
public int myint4; | |
public void OnSerialization() | |
{ | |
myint++; | |
myint2++; | |
myint3++; | |
myint4++; | |
} | |
} | |
public Custom custom; | |
public bool firstPass = true; | |
void Awake() | |
{ | |
if (!firstPass) | |
return; | |
firstPass = false; | |
custom.myint = 5; | |
custom.myint2 = 6; | |
custom.myint3 = 7; | |
custom.myint4 = 8; | |
var copy = (SerializationCallbackInCustomStructScript)Instantiate(this); | |
//everything got increased twice, because we have a StreamedBinaryWrite and a RemapPPtr run. | |
Check.AreEqual(7, copy.custom.myint); | |
Check.AreEqual(8, copy.custom.myint2); | |
Check.AreEqual(9, copy.custom.myint3); | |
Check.AreEqual(10, copy.custom.myint4); | |
Testing.TestCompleted(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment