Exemple #1
0
        public static bool SaveDictionary(string path)
        {
            if (dict.Count > 0)
            {
                BinaryFormatter bf   = new BinaryFormatter();
                FileStream      file = File.Create(path);

                if (ss == null)
                {
                    CreateSurrogates();
                }

                if (Texture2DCompressionType_old != Texture2DCompressionType)
                {
                    ss.RemoveSurrogate(typeof(Texture2D), new StreamingContext(StreamingContextStates.All));

                    Texture2DSerializationSurrogate texture_ss = new Texture2DSerializationSurrogate();
                    ss.AddSurrogate(typeof(Texture2D), new StreamingContext(StreamingContextStates.All), texture_ss);

                    Texture2DCompressionType_old = Texture2DCompressionType;
                }

                bf.SurrogateSelector = ss;

                bf.Serialize(file, dict);
                file.Close();

                return(true);
            }

            return(false);
        }
Exemple #2
0
        public static void Save(object obj, string path)
        {
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Create(path);

            if (ss == null)
            {
                CreateSurrogates();
            }

            if (Texture2DCompressionType_old != Texture2DCompressionType)
            {
                ss.RemoveSurrogate(typeof(Texture2D), new StreamingContext(StreamingContextStates.All));

                Texture2DSerializationSurrogate texture_ss = new Texture2DSerializationSurrogate();
                ss.AddSurrogate(typeof(Texture2D), new StreamingContext(StreamingContextStates.All), texture_ss);

                Texture2DCompressionType_old = Texture2DCompressionType;
            }

            bf.SurrogateSelector = ss;

            bf.Serialize(file, obj);
            file.Close();
        }
Exemple #3
0
        static void CreateSurrogates()
        {
            ss = new SurrogateSelector();

            //VECTOR2
            Vector2SerializationSurrogate v2_ss = new Vector2SerializationSurrogate();

            ss.AddSurrogate(typeof(Vector2), new StreamingContext(StreamingContextStates.All), v2_ss);
            //VECTOR3
            Vector3SerializationSurrogate v3_ss = new Vector3SerializationSurrogate();

            ss.AddSurrogate(typeof(Vector3), new StreamingContext(StreamingContextStates.All), v3_ss);
            //VECTOR4
            Vector4SerializationSurrogate v4_ss = new Vector4SerializationSurrogate();

            ss.AddSurrogate(typeof(Vector4), new StreamingContext(StreamingContextStates.All), v4_ss);

            //QUATERNION
            QuaternionSerializationSurrogate q_ss = new QuaternionSerializationSurrogate();

            ss.AddSurrogate(typeof(Quaternion), new StreamingContext(StreamingContextStates.All), q_ss);

            //COLOR AND COLOR32
            ColorSerializationSurrogate color_ss = new ColorSerializationSurrogate();

            ss.AddSurrogate(typeof(Color), new StreamingContext(StreamingContextStates.All), color_ss);
            ss.AddSurrogate(typeof(Color32), new StreamingContext(StreamingContextStates.All), color_ss);

            //TEXTURE2D
            Texture2DSerializationSurrogate texture_ss = new Texture2DSerializationSurrogate();

            ss.AddSurrogate(typeof(Texture2D), new StreamingContext(StreamingContextStates.All), texture_ss);

            Texture2DCompressionType_old = Texture2DCompressionType;
        }
    static void CreateSurrogates()
    {
        ss = new SurrogateSelector();

        //VECTOR2
        Vector2SerializationSurrogate v2_ss = new Vector2SerializationSurrogate();
        ss.AddSurrogate(typeof(Vector2), new StreamingContext(StreamingContextStates.All), v2_ss);
        //VECTOR3
        Vector3SerializationSurrogate v3_ss = new Vector3SerializationSurrogate();
        ss.AddSurrogate(typeof(Vector3), new StreamingContext(StreamingContextStates.All), v3_ss);
        //VECTOR4
        Vector4SerializationSurrogate v4_ss = new Vector4SerializationSurrogate();
        ss.AddSurrogate(typeof(Vector4), new StreamingContext(StreamingContextStates.All), v4_ss);

        //QUATERNION
        QuaternionSerializationSurrogate q_ss = new QuaternionSerializationSurrogate();
        ss.AddSurrogate(typeof(Quaternion), new StreamingContext(StreamingContextStates.All), q_ss);

        //COLOR AND COLOR32
        ColorSerializationSurrogate color_ss = new ColorSerializationSurrogate();
        ss.AddSurrogate(typeof(Color), new StreamingContext(StreamingContextStates.All), color_ss);
        ss.AddSurrogate(typeof(Color32), new StreamingContext(StreamingContextStates.All), color_ss);

        //TEXTURE2D
        Texture2DSerializationSurrogate texture_ss = new Texture2DSerializationSurrogate();
        ss.AddSurrogate(typeof(Texture2D), new StreamingContext(StreamingContextStates.All), texture_ss);

        Texture2DCompressionType_old = Texture2DCompressionType;
    }
    public static bool SaveDictionary(string path)
    {
        if(dict.Count > 0){
            BinaryFormatter bf = new BinaryFormatter();
            FileStream file = File.Create (path);

            if(ss == null){
                CreateSurrogates();
            }

            if(Texture2DCompressionType_old != Texture2DCompressionType){
                ss.RemoveSurrogate(typeof(Texture2D), new StreamingContext(StreamingContextStates.All));

                Texture2DSerializationSurrogate texture_ss = new Texture2DSerializationSurrogate();
                ss.AddSurrogate(typeof(Texture2D), new StreamingContext(StreamingContextStates.All), texture_ss);

                Texture2DCompressionType_old = Texture2DCompressionType;
            }

            bf.SurrogateSelector = ss;

            bf.Serialize(file, dict);
            file.Close();

            return true;
        }

        return false;
    }
    public static void Save(object obj, string path)
    {
        BinaryFormatter bf = new BinaryFormatter();
        FileStream file = File.Create (path);

        if(ss == null){
            CreateSurrogates();
        }

        if(Texture2DCompressionType_old != Texture2DCompressionType){
            ss.RemoveSurrogate(typeof(Texture2D), new StreamingContext(StreamingContextStates.All));

            Texture2DSerializationSurrogate texture_ss = new Texture2DSerializationSurrogate();
            ss.AddSurrogate(typeof(Texture2D), new StreamingContext(StreamingContextStates.All), texture_ss);

            Texture2DCompressionType_old = Texture2DCompressionType;
        }

        bf.SurrogateSelector = ss;

        bf.Serialize(file, obj);
        file.Close();
    }