Exemplo n.º 1
0
        public static T loadFromFile <T>(string path)
        {
            FileStream        fs        = new FileStream(path, FileMode.Open);
            BinaryFormatter   formatter = new BinaryFormatter();
            SurrogateSelector ss        = new SurrogateSelector();

            Assets.Editor.Vector3SerializationSurrogate v3Surrogate = new Assets.Editor.Vector3SerializationSurrogate();
            ss.AddSurrogate(typeof(Vector3), new StreamingContext(StreamingContextStates.All), v3Surrogate);
            formatter.SurrogateSelector = ss;
            T t;

            try
            {
                t = (T)formatter.Deserialize(fs);
            }
            catch (SerializationException e)
            {
                Debug.Log("Failed to deserialize. Reason: " + e.Message);
                throw;
            }
            finally
            {
                fs.Close();
            }
            return(t);
        }
Exemplo n.º 2
0
 public static void SaveToFile <T>(T item, string path, FileMode fileMode)
 {
     try
     {
         BinaryFormatter   formatter = new BinaryFormatter();
         SurrogateSelector ss        = new SurrogateSelector();
         Assets.Editor.Vector3SerializationSurrogate v3Surrogate = new Assets.Editor.Vector3SerializationSurrogate();
         ss.AddSurrogate(typeof(Vector3), new StreamingContext(StreamingContextStates.All), v3Surrogate);
         formatter.SurrogateSelector = ss;
         using (FileStream fs = new FileStream(path, fileMode))
         {
             formatter.Serialize(fs, item);
             fs.Close();
         }
     }
     catch (SerializationException e)
     {
         Debug.Log("Failed to serialize. Reason: " + e.Message);
         throw;
     }
 }
Exemplo n.º 3
0
 public static void init()
 {
     Assets.Editor.Vector3SerializationSurrogate v3Surrogate = new Assets.Editor.Vector3SerializationSurrogate();
     ss.AddSurrogate(typeof(Vector3), new StreamingContext(StreamingContextStates.All), v3Surrogate);
     formatter.SurrogateSelector = ss;
 }