Пример #1
0
        private bool ReadHeader(BytesReader buffer)
        {
            uint flag = buffer.ReadUInt32();

            if (flag != HeaderFlag)
            {
                return(false);
            }

            mapType    = (ELevelMapType)buffer.ReadInt32();
            minCol     = buffer.ReadInt32();
            maxBallId  = buffer.ReadInt32();
            ballRadius = buffer.ReadFloat();

            return(true);
        }
Пример #2
0
        private bool ReadBalls(BytesReader buffer)
        {
            uint flag = buffer.ReadUInt32();

            if (flag != BallFlag)
            {
                return(false);
            }

            int numOfBall = buffer.ReadInt32();

            if (numOfBall > 0)
            {
                for (int i = 0; i < numOfBall; i++)
                {
                    BallData ball = new BallData();
                    ball.Read(buffer);
                    balls.Add(ball);
                }
            }

            return(true);
        }
Пример #3
0
        public bool LoadFromBytes(byte[] data)
        {
            balls.Clear();

            try
            {
                BytesReader buffer = new BytesReader(data);

                uint flag    = buffer.ReadUInt32();
                int  version = buffer.ReadInt32();

                if (flag != FileFlag || version != FileVersion)
                {
                    Debug.LogError("LevelMapData format error.");
                    return(false);
                }

                if (!ReadHeader(buffer))
                {
                    Debug.LogError("Level file format error.");
                    return(false);
                }

                if (!ReadBalls(buffer))
                {
                    Debug.LogError("Level file format error.");
                    return(false);
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }