//deserialize and return for loading (do not call directly, call load() instead) protected Object2PropertiesMappingListWrapper DeSerializeObject(byte[] data) { Object2PropertiesMappingListWrapper objectToSerialize = null; if (compressSaves) { try { data = CLZF2.Decompress(data); } catch (OutOfMemoryException meme) { if (showWarnings) { Debug.LogWarning("EZReplayManager WARNING: Decompressing was unsuccessful. Trying without decompression."); } } catch (OverflowException ofe) { if (showWarnings) { Debug.LogWarning("EZReplayManager WARNING: Decompressing was unsuccessful. Trying without decompression."); } } } MemoryStream stream = new MemoryStream(data); // BinaryFormatter bFormatter = new BinaryFormatter (); // objectToSerialize = (Object2PropertiesMappingListWrapper)bFormatter.Deserialize (stream); objectToSerialize = ProtoBuf.Serializer.Deserialize <Object2PropertiesMappingListWrapper> (stream); objectToSerialize.CalcParentMapingRef(); //print("System.GC.GetTotalMemory(): "+System.GC.GetTotalMemory(false)); return(objectToSerialize); }
//serialize and save (do not call directly, call save() instead) protected void SerializeObject(string filename, Object2PropertiesMappingListWrapper objectToSerialize) { Stream stream = File.Open(filename, FileMode.Create); BinaryFormatter bFormatter = new BinaryFormatter(); bFormatter.Serialize(stream, objectToSerialize); stream.Close(); }
void finishLoading(Object2PropertiesMappingListWrapper reSerialized) { gOs2propMappings.Clear(); maxPositions = 0; recorderPosition = 0; recordingInterval = reSerialized.recordingInterval; //if you load a replay with a different recording interval, //you have to reset it to the earlier value afterwards YOURSELF! if (reSerialized.EZR_VERSION != EZR_VERSION) { if (showWarnings) { Debug.LogWarning("EZReplayManager WARNING: The EZR version with which the file has been created differs from your version of the EZReplayManager. This can cause unintended behaviour."); } } foreach (var entry in reSerialized.object2PropertiesMappings) { if (entry.isParent()) { entry.prepareObjectForReplay(); GameObject goClone = entry.getGameObjectClone(); gOs2propMappings.Add(goClone, entry); foreach (KeyValuePair <int, SavedState> stateEntry in entry.savedStates) { if (stateEntry.Key > maxPositions) { maxPositions = stateEntry.Key; } } } } foreach (var entry in reSerialized.object2PropertiesMappings) { if (!entry.isParent()) { entry.prepareObjectForReplay(); GameObject goClone = entry.getGameObjectClone(); gOs2propMappings.Add(goClone, entry); } foreach (KeyValuePair <int, SavedState> stateEntry in entry.savedStates) { if (stateEntry.Key > maxPositions) { maxPositions = stateEntry.Key; } } } currentMode = ViewMode.REPLAY; //switchModeTo(ViewMode.REPLAY); //happens in play: // play (0); }
//deserialize and return for loading (do not call directly, call load() instead) protected Object2PropertiesMappingListWrapper DeSerializeObject(string filename) { Object2PropertiesMappingListWrapper objectToSerialize = null; Stream stream = File.Open(filename, FileMode.Open); BinaryFormatter bFormatter = new BinaryFormatter(); objectToSerialize = (Object2PropertiesMappingListWrapper)bFormatter.Deserialize(stream); //print("System.GC.GetTotalMemory(): "+System.GC.GetTotalMemory(false)); stream.Close(); return(objectToSerialize); }
//wrapper for saving to file public void saveToFile(string filename) { if (!precacheGameobjects) { StartCoroutine(startShowPrecachingMandatoryMessage(8.5f)); return; } stop(); Object2PropertiesMappingListWrapper o2pMappingListW = new Object2PropertiesMappingListWrapper(); foreach (var entry in gOs2propMappings) { o2pMappingListW.addMapping(entry.Value); } o2pMappingListW.recordingInterval = recordingInterval; SerializeObject(filename, o2pMappingListW); }
public byte[] saveToStream() { if (!precacheGameobjects) { StartCoroutine(startShowPrecachingMandatoryMessage(8.5f)); return(null); } stop(); Object2PropertiesMappingListWrapper o2pMappingListW = new Object2PropertiesMappingListWrapper(); foreach (var entry in gOs2propMappings) { o2pMappingListW.addMapping(entry.Value); } o2pMappingListW.recordingInterval = recordingInterval; return(SerializeObject(o2pMappingListW)); }
//serialize and save (do not call directly, call save() instead) protected byte[] SerializeObject(Object2PropertiesMappingListWrapper objectToSerialize) { MemoryStream memStream = new MemoryStream(); // BinaryFormatter bFormatter = new BinaryFormatter(); // bFormatter.Serialize(memStream, objectToSerialize); objectToSerialize.CalcParentMapingIdx(); ProtoBuf.Serializer.Serialize <Object2PropertiesMappingListWrapper> (memStream, objectToSerialize); if (compressSaves) { return(CLZF2.Compress(memStream.ToArray())); } else { return(memStream.ToArray()); } }
void finishLoading(Object2PropertiesMappingListWrapper reSerialized) { gOs2propMappings.Clear(); maxPositions = 0; recorderPosition = 0; recordingInterval = reSerialized.recordingInterval; //if you load a replay with a different recording interval, //you have to reset it to the earlier value afterwards YOURSELF! if (reSerialized.EZR_VERSION != EZR_VERSION) { if (showWarnings) Debug.LogWarning("EZReplayManager WARNING: The EZR version with which the file has been created differs from your version of the EZReplayManager. This can cause unintended behaviour."); } foreach (var entry in reSerialized.object2PropertiesMappings) { if (entry.isParent()) { entry.prepareObjectForReplay(); GameObject goClone = entry.getGameObjectClone(); gOs2propMappings.Add(goClone, entry); foreach (KeyValuePair<int, SavedState> stateEntry in entry.savedStates) { if (stateEntry.Key > maxPositions) maxPositions = stateEntry.Key; } } } foreach (var entry in reSerialized.object2PropertiesMappings) { if (!entry.isParent()) { entry.prepareObjectForReplay(); GameObject goClone = entry.getGameObjectClone(); gOs2propMappings.Add(goClone, entry); } foreach (KeyValuePair<int, SavedState> stateEntry in entry.savedStates) { if (stateEntry.Key > maxPositions) maxPositions = stateEntry.Key; } } currentMode = ViewMode.REPLAY; //switchModeTo(ViewMode.REPLAY); //happens in play: play(0); }
public byte[] saveToStream() { if (!precacheGameobjects) { StartCoroutine(startShowPrecachingMandatoryMessage(8.5f)); return null; } stop(); Object2PropertiesMappingListWrapper o2pMappingListW = new Object2PropertiesMappingListWrapper(); foreach (var entry in gOs2propMappings) { o2pMappingListW.addMapping(entry.Value); } o2pMappingListW.recordingInterval = recordingInterval; return SerializeObject(o2pMappingListW); }
//serialize and save (do not call directly, call save() instead) protected byte[] SerializeObject(Object2PropertiesMappingListWrapper objectToSerialize) { MemoryStream memStream = new MemoryStream(); BinaryFormatter bFormatter = new BinaryFormatter(); bFormatter.Serialize(memStream, objectToSerialize); if (compressSaves) { return CLZF2.Compress(memStream.ToArray()); } else { return memStream.ToArray(); } }
//wrapper for loading from file public void loadFromFile(string filename) { if (!precacheGameobjects) { StartCoroutine(startShowPrecachingMandatoryMessage(8.5f)); return; } stop(); if (autoDeactivateLiveObjectsOnReplay) { foreach (var entry in markedGameObjects) { if (entry != null) //not sure why, but it seems that sometimes this condition is neccessary, will research { entry.SetActive(false); } //else // print ("entry: "+entry); } } useLoadingSlot(); Object2PropertiesMappingListWrapper reSerialized = (Object2PropertiesMappingListWrapper)DeSerializeObject(filename); gOs2propMappings.Clear(); maxPositions = 0; recorderPosition = 0; recordingInterval = reSerialized.recordingInterval; //if you load a replay with a different recording interval, //you have to reset it to the earlier value afterwards YOURSELF! if (reSerialized.EZR_VERSION != EZR_VERSION) { if (showWarnings) { print("EZReplayManager WARNING: The EZR version with which the file has been created differs from your version of the EZReplayManager. This can cause unintended behaviour."); } } foreach (var entry in reSerialized.object2PropertiesMappings) { if (entry.isParent()) { entry.prepareObjectForReplay(); GameObject goClone = entry.getGameObjectClone(); gOs2propMappings.Add(goClone, entry); foreach (KeyValuePair <int, SavedState> stateEntry in entry.savedStates) { if (stateEntry.Key > maxPositions) { maxPositions = stateEntry.Key; } } } } foreach (var entry in reSerialized.object2PropertiesMappings) { if (!entry.isParent()) { entry.prepareObjectForReplay(); GameObject goClone = entry.getGameObjectClone(); gOs2propMappings.Add(goClone, entry); } foreach (KeyValuePair <int, SavedState> stateEntry in entry.savedStates) { if (stateEntry.Key > maxPositions) { maxPositions = stateEntry.Key; } } } currentMode = ViewMode.REPLAY; //switchModeTo(ViewMode.REPLAY); //happens in play: play(0); }
//wrapper for saving to file public void saveToFile(string filename) { if (!precacheGameobjects) { StartCoroutine(startShowPrecachingMandatoryMessage(8.5f)); return; } stop (); Object2PropertiesMappingListWrapper o2pMappingListW = new Object2PropertiesMappingListWrapper(); foreach (var entry in gOs2propMappings) { //Debug.Log (entry.Key.name); /*foreach (var yang in entry.Value.savedStates) { //Debug.Log (yang.Key); if (entry.Key.name == "Main Camera") { //Debug.Log (yang.Value.localPosition.getVector3()); //Debug.Log (yang.Value.localRotation.getQuaternion()); Debug.Log (yang.Value.dialogueNum); Debug.Log (yang.Value.dialogueType); Debug.Log (yang.Value.convoTitle); } }*/ o2pMappingListW.addMapping(entry.Value); } o2pMappingListW.recordingInterval = recordingInterval; SerializeObject(filename,o2pMappingListW); }