Skip to content

Instantly share code, notes, and snippets.

@lucasmeijer
Created October 4, 2013 20:19
Show Gist options
  • Save lucasmeijer/6832115 to your computer and use it in GitHub Desktop.
Save lucasmeijer/6832115 to your computer and use it in GitHub Desktop.
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