예제 #1
0
    private static BinaryFormatter CreateBinaryFormatter()
    {
        BinaryFormatter   form = new BinaryFormatter();
        SurrogateSelector ss   = new SurrogateSelector();

        {
            Vector3IntSerializationSurrogate v3iss = new Vector3IntSerializationSurrogate();
            ss.AddSurrogate(typeof(Vector3Int),
                            new StreamingContext(StreamingContextStates.All),
                            v3iss);
        }
        {
            Vector3SerializationSurrogate v3ss = new Vector3SerializationSurrogate();
            ss.AddSurrogate(typeof(Vector3),
                            new StreamingContext(StreamingContextStates.All),
                            v3ss);
        }
        {
            QuaternionSerializationSurrogate qss = new QuaternionSerializationSurrogate();
            ss.AddSurrogate(typeof(Quaternion),
                            new StreamingContext(StreamingContextStates.All),
                            qss);
        }
        {
            Vector2SerializationSurrogate v2ss = new Vector2SerializationSurrogate();
            ss.AddSurrogate(typeof(Vector2),
                            new StreamingContext(StreamingContextStates.All),
                            v2ss);
        }

        form.SurrogateSelector = ss;
        return(form);
    }
예제 #2
0
    public static BinaryFormatter GetBinaryFormatter()
    {
        BinaryFormatter bf = new BinaryFormatter();

        SurrogateSelector surrogateSelector = new SurrogateSelector();

        Vector3IntSerializationSurrogate vector3SS = new Vector3IntSerializationSurrogate();

        surrogateSelector.AddSurrogate(typeof(Vector3Int), new StreamingContext(StreamingContextStates.All), vector3SS);
        ColorSerializationSurrogate colour3SS = new ColorSerializationSurrogate();

        surrogateSelector.AddSurrogate(typeof(Color), new StreamingContext(StreamingContextStates.All), colour3SS);
        BuffSerializationSurrogate buffSerializationSurrogate = new BuffSerializationSurrogate();

        surrogateSelector.AddSurrogate(typeof(Buff), new StreamingContext(StreamingContextStates.All), buffSerializationSurrogate);
        CardSerializationSurrogate cardSerializationSurrogate = new CardSerializationSurrogate();

        surrogateSelector.AddSurrogate(typeof(Card), new StreamingContext(StreamingContextStates.All), cardSerializationSurrogate);
        EquipmentSerializationSurrogate equipmentSerializationSurrogate = new EquipmentSerializationSurrogate();

        surrogateSelector.AddSurrogate(typeof(Equipment), new StreamingContext(StreamingContextStates.All), equipmentSerializationSurrogate);

        bf.SurrogateSelector = surrogateSelector;

        return(bf);
    }
예제 #3
0
    public static BinaryFormatter GetBinaryFormatter()
    {
        BinaryFormatter bf = new BinaryFormatter();

        SurrogateSelector surrogateSelector = new SurrogateSelector();

        Vector3IntSerializationSurrogate vector3SS = new Vector3IntSerializationSurrogate();

        surrogateSelector.AddSurrogate(typeof(Vector3Int), new StreamingContext(StreamingContextStates.All), vector3SS);
        ColorSerializationSurrogate colour3SS = new ColorSerializationSurrogate();

        surrogateSelector.AddSurrogate(typeof(Color), new StreamingContext(StreamingContextStates.All), colour3SS);

        bf.SurrogateSelector = surrogateSelector;

        return(bf);
    }
    public static void AddAllUnitySurrogate(this SurrogateSelector surrogateSelector)
    {
        var colorSS      = new ColorSerializationSurrogate();
        var quaternionSS = new QuaternionSerializationSurrogate();
        var vector2IntSS = new Vector2IntSerializationSurrogate();
        var vector2SS    = new Vector2SerializationSurrogate();
        var vector3IntSS = new Vector3IntSerializationSurrogate();
        var vector3SS    = new Vector3SerializationSurrogate();
        var vector4SS    = new Vector4SerializationSurrogate();

        surrogateSelector.AddSurrogate(typeof(Color), new StreamingContext(StreamingContextStates.All), colorSS);
        surrogateSelector.AddSurrogate(typeof(Quaternion), new StreamingContext(StreamingContextStates.All), quaternionSS);
        surrogateSelector.AddSurrogate(typeof(Vector2Int), new StreamingContext(StreamingContextStates.All), vector2IntSS);
        surrogateSelector.AddSurrogate(typeof(Vector2), new StreamingContext(StreamingContextStates.All), vector2SS);
        surrogateSelector.AddSurrogate(typeof(Vector3Int), new StreamingContext(StreamingContextStates.All), vector3IntSS);
        surrogateSelector.AddSurrogate(typeof(Vector3), new StreamingContext(StreamingContextStates.All), vector3SS);
        surrogateSelector.AddSurrogate(typeof(Vector4), new StreamingContext(StreamingContextStates.All), vector4SS);
    }
예제 #5
0
        /// <summary>
        ///     Get a Binary Formatter that is customized to serialize World data.
        /// </summary>
        /// <returns>The Binary Formatter object.</returns>
        private static BinaryFormatter GetBinaryFormatter()
        {
            // Create new Binary Formatter
            BinaryFormatter formatter = new BinaryFormatter();

            // Create surrogate selector to add new surrogates
            SurrogateSelector surrogateSelector = new SurrogateSelector();

            // Add all the surrogates to convert non-serializable to serializable
            Vector3IntSerializationSurrogate vector3IntSurrogate = new Vector3IntSerializationSurrogate();

            surrogateSelector.AddSurrogate(typeof(Vector3Int), new StreamingContext(StreamingContextStates.All),
                                           vector3IntSurrogate);

            // Apply SurrogateSelector
            formatter.SurrogateSelector = surrogateSelector;

            return(formatter);
        }