00001 using System;
00002 using System.Collections.Generic;
00003 using System.Text;
00004 using System.Runtime.Serialization;
00005
00006 namespace DXGfxLib.Serialization
00007 {
00008 public class TerrainSurrogate : ISerializationSurrogate
00009 {
00016 public void GetObjectData(Object obj, SerializationInfo info, StreamingContext context)
00017 {
00018 if (obj == null)
00019 {
00020 throw new NullReferenceException("No scene object to serialize, this is wrong!");
00021 }
00022
00023 Terrain terrain = obj as Terrain;
00024
00025 if (terrain == null)
00026 {
00027 throw new ArgumentException("The Object passed through obj argument is not a scene object, this is wrong!");
00028 }
00029
00030 info.AddValue("HeightMap", terrain.heightmapFile, typeof(string));
00031 info.AddValue("BaseTexture", terrain.baseTextureFile, typeof(string));
00032 info.AddValue("SecondTexture", terrain.secondTextureFile, typeof(string));
00033 info.AddValue("SecondTextureHeight", terrain.secondTexHeigth, typeof(float));
00034 }
00035
00044 public Object SetObjectData(Object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
00045 {
00046 if (obj == null)
00047 {
00048 throw new NullReferenceException("No scene object to serialize, this is wrong!");
00049 }
00050
00051 Terrain terrain = obj as Terrain;
00052
00053 if (terrain == null)
00054 {
00055 throw new ArgumentException("The Object passed through obj argument is not a terrain object, this is wrong!");
00056 }
00057
00058 terrain.Initialize();
00059 terrain.heightmapFile = (string)info.GetValue("HeightMap", typeof(string));
00060 terrain.baseTextureFile = (string)info.GetValue("BaseTexture", typeof(string));
00061 terrain.secondTextureFile = (string)info.GetValue("SecondTexture", typeof(string));
00062 terrain.secondTexHeigth = (float)info.GetValue("SecondTextureHeight", typeof(float));
00063
00064 return null;
00065 }
00066 }
00067 }