Unity-Technologies / HLODSystem

881 stars 142 forks source link

Add UserDataSerialization #101

Closed JangkyuSeo closed 2 years ago

JangkyuSeo commented 2 years ago

Purpose of this PR

Added the UserDataSerializer. Register UserDataSerializer that inherits UserDataSerializerBase in the same way as Batcher and Streaming. If you register, you can select like below figure. image

The component for the serializer is added as shown in the figure below at build time. image

Below is implement the UserDataSerializerBase.

public class EmptyUserDataSerializer : UserDataSerializerBase
{
    protected override void SerializeUserData(GameObject gameObject, HLODUserData data)
    {
     }
    protected override void DeserializeUserData(GameObject gameObject, HLODUserData data)
    {
    }
}

Below is a simple implementing UserDataSerializer.

public class TestUserDataSerializer : Unity.HLODSystem.Serializer.UserDataSerializerBase
{
#if UNITY_EDITOR
    [InitializeOnLoadMethod]
    static void Register()
    {
        Unity.HLODSystem.Serializer.UserDataSerializerTypes.RegisterType(typeof(TestUserDataSerializer));
    }
#endif

    protected override void SerializeUserData(GameObject gameObject, HLODUserData data)
    {
        var test = gameObject.GetComponent<TestSerialize>();
        if (test == null)
            return;

        data.IntDatas.AddData("Test", test.Value);
    }

    protected override void DeserializeUserData(GameObject gameObject, HLODUserData data)
    {
        if (data.IntDatas.HasData("Test") == false)
            return;

        var test = gameObject.AddComponent<TestSerialize>();
        test.Value = data.IntDatas.GetData("Test");
    }
}

Release Notes

Add the UserDataSerialization


Testing status

ManualTest on the AddressableSample.


Overall Product Risks

Technical Risk: Low

Halo Effect: Medium


Comments to reviewers