- Main Page
- Packages
- Classes
- Files

- File List
- File Members

# D:/guillaume/guillara/3D/DXGfx/Backup/DXGfxLib/Serialization/OutDoorSceneSurrogate.cs

Go to the documentation of this file.

    00001 using System;
    00002 using System.Collections;
    00003 using System.Collections.Generic;
    00004 using System.Text;
    00005 using System.Runtime.Serialization;
    00006
    00007 namespace DXGfxLib.Serialization
    00008 {
    00009     public sealed class OutDoorSceneSurrogate : ISerializationSurrogate
    00010     {
    00017         public void GetObjectData(Object obj, SerializationInfo info, StreamingContext context)
    00018         {
    00019             if (obj == null)
    00020             {
    00021                 throw new NullReferenceException("No scene to serialize, this is wrong!");
    00022             }
    00023
    00024             OutDoorScene scene = obj as OutDoorScene;
    00025
    00026             if (scene == null)
    00027             {
    00028                 throw new ArgumentException("The Object passed through obj argument is not an OutDoorScene, this is wrong!");
    00029             }
    00030
    00031             info.AddValue("Name", scene.name, typeof(string));
    00032             info.AddValue("Depth", scene.depth, typeof(int));
    00033             info.AddValue("ExtendX", scene.Extents.X, typeof(float));
    00034             info.AddValue("ExtendY", scene.Extents.Y, typeof(float));
    00035             info.AddValue("ExtendZ", scene.Extents.Z, typeof(float));
    00036             info.AddValue("Terrain", scene.SceneTerrain, typeof(Terrain));
    00037             info.AddValue("Sky", scene.SceneSky, typeof(SkyDome));
    00038             info.AddValue("Water", scene.SceneWater, typeof(Water2));
    00039             info.AddValue("SceneContent", scene.sceneContent, typeof(Hashtable));
    00040
    00041             if (scene.CurrentAvatar == null)
    00042             {
    00043                 info.AddValue("Avatar", "", typeof(string));
    00044             }
    00045             else if (scene.CurrentAvatar.associatedSceneObject == null)
    00046             {
    00047                 info.AddValue("Avatar", "", typeof(string));
    00048             }
    00049             else
    00050             {
    00051                 info.AddValue("Avatar", scene.CurrentAvatar.associatedSceneObject.name, typeof(string));
    00052             }
    00053         }
    00054
    00063         public Object SetObjectData(Object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
    00064         {
    00065             if (obj == null)
    00066             {
    00067                 throw new NullReferenceException("No scene to serialize, this is wrong!");
    00068             }
    00069
    00070             OutDoorScene scene = obj as OutDoorScene;
    00071
    00072             if (scene == null)
    00073             {
    00074                 throw new ArgumentException("The Object passed through obj argument is not an OutDoorScene, this is wrong!");
    00075             }
    00076
    00077             scene.name = (string)info.GetValue("Name", typeof(string));
    00078             scene.depth = (int)info.GetValue("Depth", typeof(int));
    00079             float X = (float)info.GetValue("ExtendX", typeof(float));
    00080             float Y = (float)info.GetValue("ExtendY", typeof(float));
    00081             float Z = (float)info.GetValue("ExtendZ", typeof(float));
    00082             AABBox aabox = new AABBox(X, Y, Z);
    00083             scene.Initialize(aabox, scene.depth);
    00084             scene.SceneTerrain = (Terrain)info.GetValue("Terrain", typeof(Terrain));
    00085             scene.SceneSky = (SkyDome)info.GetValue("Sky", typeof(SkyDome));
    00086             scene.SceneWater = (Water2)info.GetValue("Water", typeof(Water2));
    00087             scene.sceneContent = (Hashtable)info.GetValue("SceneContent", typeof(Hashtable));
    00088             scene.avatarName = (string)info.GetValue("Avatar", typeof(string));
    00089
    00090             return null;
    00091         }
    00092     }
    00093 }