using System.Collections;
using System.Collections.Generic;
using Unity.Netcode;
using UnityEngine;
using System;

public static class SerializationExtensions
{
    public static void ReadValueSafe(this FastBufferReader reader, out Guid guid)
    {
        reader.ReadValueSafe(out string val);
        guid = new Guid(val);
    }

    public static void WriteValueSafe(this FastBufferWriter writer, in Guid guid)
    {
        writer.WriteValueSafe(guid.ToString());
    }

    public static void DuplicateValueSafe(in Guid guid, ref Guid duplicateGuid)
    {
        duplicateGuid = new Guid(guid.ToString());
    }

    public static void InitialiseSerializers()
    {
        UserNetworkVariableSerialization<Guid>.WriteValue = WriteValueSafe;
        UserNetworkVariableSerialization<Guid>.ReadValue = ReadValueSafe;
        UserNetworkVariableSerialization<Guid>.DuplicateValue = DuplicateValueSafe;
    }
}

public class GuidNetworkVariableSupport : MonoBehaviour
{
    void Start()
    {
        SerializationExtensions.InitialiseSerializers();
    }
}
