Beispiel #1
0
    bool Load(String s)
    {
        if (!File.Exists(s))
        {
            return(false);
        }
        BinaryFormatter   BF = new BinaryFormatter();
        SurrogateSelector ss = new SurrogateSelector();

        ss.AddSurrogate(typeof(Vector3),
                        new StreamingContext(StreamingContextStates.All),
                        new Vector3SerializationSurrogate());
        ss.AddSurrogate(typeof(Quaternion),
                        new StreamingContext(StreamingContextStates.All),
                        new QuaternionSerializationSurrogate());
        ss.AddSurrogate(typeof(Color),
                        new StreamingContext(StreamingContextStates.All),
                        new ColorSerializationSurrogate());
        BF.SurrogateSelector = ss;
        using (FileStream stream = new FileStream(Application.persistentDataPath + "/" + FileName + ".save", FileMode.Open, FileAccess.Read))
        {
            IS = BF.Deserialize(stream) as InputSaver;
            IS.setParent(this.gameObject.transform.parent.transform.parent.gameObject);
            stream.Close();
        }
        return(true);
    }
Beispiel #2
0
    public void Start()
    {
        IS.setParent(this.gameObject.transform.parent.transform.parent.gameObject);

        String Path = Application.persistentDataPath + "/" + FileName + ".save";

        if (this.Load(Path))
        {
            IS.FirstFrame.Apply();
            IsReplaying = true;
        }
    }
Beispiel #3
0
    public void EndLevel()
    {
        if (IsRecording)
        {
            IS.EndFrame.Init();

            String Path = Application.persistentDataPath + "/" + FileName + ".save";
            if (!IsSerializing && !IsReplaying && IS.InputsFrame.Count != 0)
            {
                BinaryFormatter   BF = new BinaryFormatter();
                SurrogateSelector ss = new SurrogateSelector();
                ss.AddSurrogate(typeof(Vector3),
                                new StreamingContext(StreamingContextStates.All),
                                new Vector3SerializationSurrogate());
                ss.AddSurrogate(typeof(Quaternion),
                                new StreamingContext(StreamingContextStates.All),
                                new QuaternionSerializationSurrogate());
                ss.AddSurrogate(typeof(Color),
                                new StreamingContext(StreamingContextStates.All),
                                new ColorSerializationSurrogate());

                BF.SurrogateSelector = ss;

                FileStream file = File.Create(Path);
                IsSerializing = true;
                BF.Serialize(file, IS);
                IsSerializing = false;
                file.Close();

                IS = new InputSaver();
                IS.setParent(this.gameObject.transform.parent.transform.parent.gameObject);
            }
        }

#if false
        if (IsReplaying)
        {
            CompareEndFrames();
        }
#endif
    }