Esempio n. 1
0
        //============================================================
        // <T>序列化。</T>
        //============================================================
        public void Serialize(IOutput output)
        {
            output.WriteInt8((sbyte)(int)_typeCd);
            output.WriteInt8((sbyte)(int)_wrapCd);
            output.WriteInt8((sbyte)(int)_scrollCd);
            output.WriteFloat(_scrollSpeed);
            output.WriteUint16((ushort)_cellCount.Width);
            output.WriteUint16((ushort)_cellCount.Height);
            output.WriteUint16((ushort)_cellSize.Width);
            output.WriteUint16((ushort)_cellSize.Height);

            int mapCellCount = 0;

            for (int i = 0; i < _mapCell.Count; i++)
            {
                FMbMapCell cell = _mapCell[i];
                if (0 != cell.ResourceId)
                {
                    mapCellCount++;
                }
            }
            output.WriteInt32(mapCellCount);
            foreach (FMbMapCell cell in _mapCell)
            {
                if (0 != cell.ResourceId)
                {
                    cell.Serialize(output);
                }
            }
        }
Esempio n. 2
0
        //============================================================
        // <T>加载配置文件。</T>
        //============================================================
        public void LoadConfig(FXmlNode config)
        {
            if (config.Contains("cell_count"))
            {
                _cellCount.Parse(config.Get("cell_count"));
            }
            if (config.Contains("cell_size"))
            {
                _cellSize.Parse(config.Get("cell_size"));
            }
            if (config.Contains("type_cd"))
            {
                _typeCd = REnum.ToValue <EMapLayerType>(config.Get("type_cd"));
            }
            if (config.Contains("scroll_cd"))
            {
                _scrollCd = REnum.ToValue <EMapLayerScroll>(config.Get("scroll_cd"));
            }
            if (config.Contains("wrap_cd"))
            {
                _wrapCd = REnum.ToValue <EMapLayerWrap>(config.Get("wrap_cd"));
            }
            if (config.Contains("scroll_speed"))
            {
                _scrollSpeed = config.GetFloat("scroll_speed");
            }
            _tileNode = config.Find("Tiles");
            if (null == _tileNode)
            {
                return;
            }
            // 创建所有格子
            for (int m = 0; m < _cellCount.Height; m++)
            {
                for (int n = 0; n < _cellCount.Width; n++)
                {
                    FMbMapCell cell = new FMbMapCell();
                    cell.Index = new SIntPoint2(n, m);
                    _mapCell.Push(cell);
                }
            }

            // 加载格子资源图片编号
            foreach (FXmlNode cellNode in _tileNode.Nodes)
            {
                FDsMapCell cell = new FDsMapCell();
                cell.Resource.LoadConfig(cellNode);
                SIntPoint2 cellIndex = cell.Resource.Index;
                FMbMapCell c         = FingCellByIndex(cellIndex.X, cellIndex.Y);
                c.ResourceId = cell.Resource.ResourceId;
            }
        }