Created
November 25, 2019 20:07
-
-
Save ASPePeX/53fc0b835111265855a8cb10ca60af45 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Fusee.Base.Core; | |
using Fusee.Serialization; | |
using System.IO; | |
namespace Fusee.Engine.Core | |
{ | |
/// <summary> | |
/// High level serialization helper thing | |
/// </summary> | |
public static class Serializer | |
{ | |
public static string Version = SerializerLow.Version; | |
public static SceneContainer DeserializeSceneGraph(Stream stream) | |
{ | |
SceneContainer sceneContainer = SerializerLow.DeserializeRawSceneContainer(stream); | |
if (sceneContainer.Header.Version.ToString() != Version) | |
{ | |
FileStream fs = stream as FileStream; | |
if (fs != null) | |
{ | |
Diagnostics.Warn("File version of " + fs.Name + " (" + sceneContainer.Header.Version.ToString() + ") does not match used Fusee version (" + Version + "). This can result in unexpected behaviour."); | |
} | |
else | |
{ | |
Diagnostics.Warn("Serialization version of stream input (" + sceneContainer.Header.Version.ToString() + ") does not match used Fusee version (" + Version + "). This can result in unexpected behaviour."); | |
} | |
} | |
return new ConvertSceneGraph().Convert(sceneContainer); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO; | |
using System.Reflection; | |
namespace Fusee.Serialization | |
{ | |
/// <summary> | |
/// Low level serialization helper thing | |
/// </summary> | |
public static class SerializerLow | |
{ | |
public static string Version = Assembly.GetAssembly(typeof(SerializerLow)).GetName().Version.ToString(); | |
public static SceneContainer DeserializeRawSceneContainer(Stream stream) | |
{ | |
var sceneContainer = ProtoBuf.Serializer.Deserialize<SceneContainer>(stream); | |
return sceneContainer; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fap.RegisterTypeHandler( | |
new AssetHandler | |
{ | |
ReturnedType = typeof(SceneContainer), | |
Decoder = delegate (string id, object storage) | |
{ | |
if (!Path.GetExtension(id).ToLower().Contains("fus")) return null; | |
return Serializer.DeserializeSceneGraph((Stream)storage); | |
}, | |
Checker = id => Path.GetExtension(id).ToLower().Contains("fus") | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment