Ejemplo n.º 1
0
        public void Write(BinaryBuffer buf, PrefabFooter metadata)
        {
            var numFieldsWritten = 0;

            metadata.WriteLocalID(buf, bindings.type);

            for (int i = 0; i < fields.Length; i++)
            {
                var fieldOverride = fields[i];

                if (fieldOverride.node != null)
                {
                    buf.Write(i);
                    var metaField = fieldOverride.node.Bindings.fields[fieldOverride.fieldID];
                    var start     = buf.position;
                    metaField.Write(fieldOverride.node, buf);
                    metadata.fieldSizes.Enqueue(buf.position - start);
                    numFieldsWritten++;
                }
                else if (fieldOverride.buf != null)
                {
                    buf.Write(i);
                    var start = buf.position;
                    buf.WriteBytes(fieldOverride.buf, fieldOverride.position, fieldOverride.length);
                    metadata.fieldSizes.Enqueue(buf.position - start);
                    numFieldsWritten++;
                }
            }

            metadata.collectionCounts.Push(numFieldsWritten);

            var numChildrenWritten = 0;

            for (int i = 0; i < children.Length; i++)
            {
                var child = children[i];
                if (child == null)
                {
                    continue;
                }

                buf.Write(i);
                child.Write(buf, metadata);
                numChildrenWritten++;
            }

            metadata.collectionCounts.Push(numChildrenWritten);
        }
Ejemplo n.º 2
0
        public void Read(BinaryBuffer buf, PrefabFooter footer)
        {
            var typeLocalID = buf.ReadInt();
            var typeGUID    = footer.LocalToGuid(typeLocalID);
            var type        = DeltaCore.Get <Type>(typeGUID);

            bindings = NodeBindings.GetBindings(type);

            var numFields = footer.collectionCounts.Pop();

            if (numFields > 0)
            {
                fields = new FieldOverride[bindings.fields.Length];
            }

            for (var iField = 0; iField < numFields; iField++)
            {
                var overrideIndex = buf.ReadInt();
                var fieldSize     = footer.fieldSizes.Dequeue();

                //Index if the type matches
                if (footer.DoesFieldTypeMatch(typeLocalID, iField))
                {
                    fields[overrideIndex] = new FieldOverride {
                        buf      = buf,
                        position = buf.position,
                        length   = fieldSize
                    };
                }

                buf.position += fieldSize;
            }

            var numChildren = footer.collectionCounts.Pop();

            if (numChildren > 0)
            {
                children = new PrefabNode[numChildren];
            }

            for (var iChild = 0; iChild < numChildren; iChild++)
            {
                var child = new PrefabNode();
                children[iChild] = child;
                child.Read(buf, footer);
            }
        }