Serialize Mesh and MeshRenderer in scene + fixed Light serialization

This commit is contained in:
Simon Lübeß
2023-01-08 19:31:01 +01:00
parent b5ca86d8de
commit e38373dccf
8 changed files with 204 additions and 42 deletions
+45
View File
@@ -1,8 +1,12 @@
using GlitchyEngine.Core;
using System;
using Bon;
using Bon.Integrated;
using System.Reflection;
namespace GlitchyEngine.Content;
[BonTarget]
class Asset : RefCounter
{
private append String _identifier;
@@ -28,10 +32,51 @@ class Asset : RefCounter
/// Gets the content manager that manages this asset; or null if this asset isn't managed.
public IContentManager ContentManager => _contentManager;
static this
{
gBonEnv.typeHandlers.Add(typeof(Asset),
((.)new => AssetSerialize, new => AssetDeserialize));
}
protected ~this()
{
// TODO: crash when _contentManager is deleted first...
// TODO: unregister from content manager
_contentManager?.UnmanageAsset(this);
}
static void AssetSerialize(BonWriter writer, ValueView value, BonEnvironment environment)
{
Log.EngineLogger.Assert(value.type == typeof(Asset));
let identifier = value.Get<Asset>().Identifier;
writer.String(identifier);
}
static Result<void> AssetDeserialize(BonReader reader, ValueView value, BonEnvironment environment)//, DeserializeFieldState state)
{
Log.EngineLogger.Assert(value.type == typeof(Asset));
String identifier = scope .();
Deserialize.String!(reader, ref identifier, environment);
Asset asset = Application.Get().ContentManager.LoadAsset(identifier);
if (asset != null)
{
Asset oldAsset = value.Get<Asset>();
oldAsset.ReleaseRef();
value.Assign(asset);
return .Ok;
}
else
{
Deserialize.Error!("Invalid resource path", reader, value.type);
}
}
//gBonEnv.typeHandlers.Add(typeof(Resource<>),
// ((.)new => ResourceSerialize, (.)new => ResourceDeserialize));
}