static PackedMemorySnapshot LoadFromFile(string filePath)
{
Debug.LogFormat("Loading...");
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
PackedMemorySnapshot result;
string fileExtension = Path.GetExtension(filePath);
if (string.Equals(fileExtension, ".memsnap3", System.StringComparison.OrdinalIgnoreCase))
{
Profiler.BeginSample("PackedMemorySnapshotUtility.LoadFromFile(litjson)");
stopwatch.Start();
using (TextReader reader = File.OpenText(filePath)) {
var errors = new List <string>();
var serializer = getSerializer(errors);
result = (PackedMemorySnapshot)serializer.Deserialize(reader, typeof(PackedMemorySnapshot));
logErrors(errors);
}
stopwatch.Stop();
Profiler.EndSample();
}
else if (string.Equals(fileExtension, ".memsnap2", System.StringComparison.OrdinalIgnoreCase))
{
Profiler.BeginSample("PackedMemorySnapshotUtility.LoadFromFile(json)");
stopwatch.Start();
var json = File.ReadAllText(filePath);
result = JsonUtility.FromJson <PackedMemorySnapshot>(json);
stopwatch.Stop();
Profiler.EndSample();
}
else if (string.Equals(fileExtension, ".memsnap", System.StringComparison.OrdinalIgnoreCase))
{
Profiler.BeginSample("PackedMemorySnapshotUtility.LoadFromFile(binary)");
stopwatch.Start();
var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
using (Stream stream = File.Open(filePath, FileMode.Open))
{
result = binaryFormatter.Deserialize(stream) as PackedMemorySnapshot;
}
stopwatch.Stop();
Profiler.EndSample();
}
else
{
Debug.LogErrorFormat("MemoryProfiler: Unrecognized memory snapshot format '{0}'.", filePath);
result = null;
}
Debug.LogFormat("Loading took {0}ms", stopwatch.ElapsedMilliseconds);
return(result);
}