public static EntityChangeSet Deserialize(UnsafeAppendBuffer.Reader *bufferReader, NativeArray <RuntimeGlobalObjectId> globalObjectIDs, GlobalAssetObjectResolver resolver)
        {
            bufferReader->ReadNext <ComponentTypeHash>(out var typeHashes, Allocator.Persistent);

            for (int i = 0; i != typeHashes.Length; i++)
            {
                var stableTypeHash = typeHashes[i].StableTypeHash;
                var typeIndex      = TypeManager.GetTypeIndexFromStableTypeHash(stableTypeHash);
                if (typeIndex == -1)
                {
                    typeHashes.Dispose();
                    throw new ArgumentException("The LiveLink Patch Type Layout doesn't match the Data Layout of the Components. Please Rebuild the Player.");
                }
            }

            var createdEntityCount   = bufferReader->ReadNext <int>();
            var destroyedEntityCount = bufferReader->ReadNext <int>();

            bufferReader->ReadNext <EntityGuid>(out var entities, Allocator.Persistent);
            bufferReader->ReadNext <NativeString64>(out var names, Allocator.Persistent);
            bufferReader->ReadNext <PackedComponent>(out var addComponents, Allocator.Persistent);
            bufferReader->ReadNext <PackedComponent>(out var removeComponents, Allocator.Persistent);
            bufferReader->ReadNext <PackedComponentDataChange>(out var setComponents, Allocator.Persistent);
            bufferReader->ReadNext <byte>(out var componentData, Allocator.Persistent);
            bufferReader->ReadNext <EntityReferenceChange>(out var entityReferenceChanges, Allocator.Persistent);
            bufferReader->ReadNext <BlobAssetReferenceChange>(out var blobAssetReferenceChanges, Allocator.Persistent);
            bufferReader->ReadNext <LinkedEntityGroupChange>(out var linkedEntityGroupAdditions, Allocator.Persistent);
            bufferReader->ReadNext <LinkedEntityGroupChange>(out var linkedEntityGroupRemovals, Allocator.Persistent);
            bufferReader->ReadNext <BlobAssetChange>(out var createdBlobAssets, Allocator.Persistent);
            bufferReader->ReadNext <ulong>(out var destroyedBlobAssets, Allocator.Persistent);
            bufferReader->ReadNext <byte>(out var blobAssetData, Allocator.Persistent);
            bufferReader->ReadNext <PackedComponent>(out var setSharedComponentPackedComponents, Allocator.Persistent);


            var resolvedObjects = new UnityEngine.Object[globalObjectIDs.Length];

            resolver.ResolveObjects(globalObjectIDs, resolvedObjects);
            var reader = new PropertiesBinaryReader(bufferReader, resolvedObjects);
            var setSharedComponents = new PackedSharedComponentDataChange[setSharedComponentPackedComponents.Length];

            for (int i = 0; i < setSharedComponentPackedComponents.Length; i++)
            {
                object componentValue;
                if (bufferReader->ReadNext <int>() == 1)
                {
                    var packedTypeIndex = setSharedComponentPackedComponents[i].PackedTypeIndex;
                    var stableTypeHash  = typeHashes[packedTypeIndex].StableTypeHash;
                    var typeIndex       = TypeManager.GetTypeIndexFromStableTypeHash(stableTypeHash);
                    var type            = TypeManager.GetType(typeIndex);
                    componentValue = BoxedProperties.ReadBoxedStruct(type, reader);
                }
Exemplo n.º 2
0
        static PackedSharedComponentDataChange[] ReadSharedComponentDataChanges(UnsafeAppendBuffer.Reader *buffer, ManagedObjectBinaryReader reader, NativeArray <ComponentTypeHash> typeHashes)
        {
            buffer->ReadNext <PackedComponent>(out var packedComponents, Allocator.Temp);
            var setSharedComponentDataChanges = new PackedSharedComponentDataChange[packedComponents.Length];

            for (var i = 0; i < packedComponents.Length; i++)
            {
                var packedTypeIndex = packedComponents[i].PackedTypeIndex;
                var stableTypeHash  = typeHashes[packedTypeIndex].StableTypeHash;
                var typeIndex       = TypeManager.GetTypeIndexFromStableTypeHash(stableTypeHash);
                var type            = TypeManager.GetType(typeIndex);
                var componentValue  = reader.ReadObject(type);
                setSharedComponentDataChanges[i].Component        = packedComponents[i];
                setSharedComponentDataChanges[i].BoxedSharedValue = componentValue;
            }
            packedComponents.Dispose();
            return(setSharedComponentDataChanges);
        }