Array Serialization

Hi , i m making a component who can be edited in EditMode and this component save datas in a 3 dimensionnal array.

I want this component save this array like it will save others properties in editor.
I read a lots of example but can’t find something who do what i need.

So i create a serializable class to contains this 3 dimensionnal array:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary ;
using System.IO;
using System.Runtime.Serialization;

[System.Serializable]
public class TerrainData : ISerializable
{ 
	private byte[,,] _data;
	 
	public TerrainData(SerializationInfo info, StreamingContext context) 
	{
		string dataSerialized = info.GetString("data");
		Deserialize (dataSerialized);
	}

	public TerrainData(int sizeX,int sizeY,int sizeZ) 
	{
		_data = new byte[sizeX, sizeY, sizeZ];
		}
	
	void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
	{  
		info.AddValue("data", this.Serialize());
	}

	public string Serialize()
	{
		if (_data==null)
			_data=new byte[0, 0, 0];

		var bf = new BinaryFormatter (); 
		var o = new MemoryStream (); //Create something to hold the data

		//Create a formatter
		bf.Serialize (o, _data); //Save the array

		string dataSerialized = System.Convert.ToBase64String (o.GetBuffer ()); //Convert the data to a string

		return dataSerialized;
	}

	public void Deserialize(string dataSerialized)
	{
		var bf = new BinaryFormatter (); 
		//Reading it back in
		var ms = new MemoryStream (System.Convert.FromBase64String (dataSerialized)); //Create an input stream from the string
		//Read back the data
		_data = bf.Deserialize (ms) as byte[,,];
	}


        public void SetData(int x,int y,int z,byte value)
	{
		_data [x, y, z] = value;
	}

	public byte GetData(int x,int y,int z)
	{
		 if (_data != null) {
						return _data [x, y, z];

				} else
						return 0;
	}
}

And i use it in my component class:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary ;
using System.IO;


[ExecuteInEditMode()]
[System.Serializable]
public class World : MonoBehaviour
{ 
	[SerializeField]
	public TerrainData terrainData


...

But data are not saved (serialization methods are never called in TerrainData class)

What is the best way to do this ?

thanks in advance

I find a way but i don’t know if it’s the best :

I call the serialize methods in AssetModificationProcessor:

public class BaseDataProcessor : UnityEditor.AssetModificationProcessor
{
	/**
    * When we're about to save an asset, make sure that asset does not contain bad data
    */
	public static void OnWillSaveAssets( string[] assets )
	{
		foreach( string asset in assets )
		{
  		if ( asset.EndsWith(".unity") )
			{
				// If we're saving a level file, assume it's the current one... so process the current scene.
				World[] allObjs = GameObject.FindSceneObjectsOfType( typeof(World) ) as World[];
				CheckList( allObjs );
			}
		}
	}
	
	/**
     * Check an object list for bad data
     */
	private static void CheckList( IEnumerable<World>    dataObjs )
	{
		foreach( World obj in dataObjs )
		{
			obj.SerializeTerrain();
		}
	}
}