summaryrefslogtreecommitdiff
path: root/VRCSDK3Worlds/Assets/Udon/Serialization/Formatters/UdonGameObjectComponentReferenceFormatter.cs
blob: 677e321923ddcf1352bf502ab4eb1632cf9407aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using VRC.Udon.Common;
using VRC.Udon.Serialization.OdinSerializer;
using VRC.Udon.Serialization.Formatters;

[assembly: RegisterFormatter(typeof(UdonGameObjectComponentReferenceFormatter))]

namespace VRC.Udon.Serialization.Formatters
{
    public sealed class UdonGameObjectComponentReferenceFormatter : BaseFormatter<UdonGameObjectComponentHeapReference>
    {
        private static readonly Serializer<Type> _typeSerializer = Serializer.Get<Type>();

        protected override UdonGameObjectComponentHeapReference GetUninitializedObject()
        {
            return null;
        }

        // ReSharper disable once RedundantAssignment
        protected override void DeserializeImplementation(ref UdonGameObjectComponentHeapReference value, IDataReader reader)
        {
            Type type = _typeSerializer.ReadValue(reader);

            value = new UdonGameObjectComponentHeapReference(type);

            RegisterReferenceID(value, reader);
            InvokeOnDeserializingCallbacks(ref value, reader.Context);
        }

        protected override void SerializeImplementation(ref UdonGameObjectComponentHeapReference value, IDataWriter writer)
        {
            _typeSerializer.WriteValue(value.type, writer);
        }
    }
}