Ejemplo n.º 1
0
        /**
         * @private
         */
        protected override void _ParseArray(Dictionary <string,object> rawData)
        {
            var offsets = rawData[ObjectDataParser.OFFSET] as List <object>;

            int l0 = int.Parse(offsets[0].ToString());
            int l1 = int.Parse(offsets[1].ToString());
            int l2 = int.Parse(offsets[3].ToString());
            int l3 = int.Parse(offsets[5].ToString());
            int l4 = int.Parse(offsets[7].ToString());
            int l5 = int.Parse(offsets[9].ToString());
            int l6 = int.Parse(offsets[11].ToString());

            short[]  intArray        = { };
            float[]  floatArray      = { };
            short[]  frameIntArray   = { };
            float[]  frameFloatArray = { };
            short[]  frameArray      = { };
            ushort[] timelineArray   = { };

            using (MemoryStream ms = new MemoryStream(_binary))
                using (BinaryDataReader reader = new BinaryDataReader(ms))
                {
                    //ToRead
                    reader.Seek(this._binaryOffset,SeekOrigin.Begin);

                    intArray        = reader.ReadInt16s(l0,l1 / Helper.INT16_SIZE);
                    floatArray      = reader.ReadSingles(0,l2 / Helper.FLOAT_SIZE);
                    frameIntArray   = reader.ReadInt16s(0,l3 / Helper.INT16_SIZE);
                    frameFloatArray = reader.ReadSingles(0,l4 / Helper.FLOAT_SIZE);
                    frameArray      = reader.ReadInt16s(0,l5 / Helper.INT16_SIZE);
                    timelineArray   = reader.ReadUInt16s(0,l6 / Helper.UINT16_SIZE);

                    reader.Close();
                    ms.Close();
                }

            this._data.binary = this._binary;

            //
            this._intArrayBuffer        = intArray;
            this._floatArrayBuffer      = floatArray;
            this._frameIntArrayBuffer   = frameIntArray;
            this._frameFloatArrayBuffer = frameFloatArray;
            this._frameArrayBuffer      = frameArray;
            this._timelineArrayBuffer   = timelineArray;

            this._data.intArray        = this._intArrayBuffer;
            this._data.floatArray      = this._floatArrayBuffer;
            this._data.frameIntArray   = this._frameIntArrayBuffer;
            this._data.frameFloatArray = this._frameFloatArrayBuffer;
            this._data.frameArray      = this._frameArrayBuffer;
            this._data.timelineArray   = this._timelineArrayBuffer;
        }
Ejemplo n.º 2
0
        /**
         * @inheritDoc
         */
        public override DragonBonesData ParseDragonBonesData(object rawObj,float scale = 1)
        {
            Helper.Assert(rawObj != null && rawObj is byte[],"Data error.");

            byte[] bytes  = rawObj as byte[];
            object header = null;

            using (MemoryStream ms = new MemoryStream(bytes))
                using (BinaryDataReader reader = new BinaryDataReader(ms))
                {
                    ms.Position = 0;
                    byte[] tag = reader.ReadBytes(8);

                    byte[] array = System.Text.Encoding.ASCII.GetBytes("DBDT");

                    if (tag[0] != array[0] ||
                        tag[1] != array[1] ||
                        tag[2] != array[2] ||
                        tag[3] != array[3])
                    {
                        Helper.Assert(false,"Nonsupport data.");
                        return(null);
                    }

                    var headerLength = (int)reader.ReadUInt32();
                    var headerBytes  = reader.ReadBytes(headerLength);
                    var headerString = System.Text.Encoding.UTF8.GetString(headerBytes);
                    header = jsonParseDelegate != null?jsonParseDelegate(headerString) : string.Empty;

                    reader.Close();
                    ms.Dispose();

                    this._binary       = bytes;
                    this._binaryOffset = 8 + 4 + headerLength;
                }

            jsonParseDelegate = null;

            return(base.ParseDragonBonesData(header,scale));
        }