コード例 #1
0
        public void Save(string file_path)
        {
            var tile_map_data = new Data.TileMapData();

            tile_map_data.Level  = Level;
            tile_map_data.Width  = Width;
            tile_map_data.Height = Height;

            tile_map_data.FloorLayer   = _parseFloorLayer();
            tile_map_data.MonsterDatas = new List <Data.MonsterData>();
            tile_map_data.PortalDatas  = new List <Data.PortalData>();
            tile_map_data.ItemDatas    = new List <Data.ItemData>();

            for (uint r = 0; r < Height; ++r)
            {
                for (uint c = 0; c < Width; ++c)
                {
                    var go = mLayerCollide[r, c];
                    if (go == null)
                    {
                        continue;
                    }

                    var tile = go.GetComponent <Tile>();
                    switch (tile.TileType)
                    {
                    case Logic.Tile.EType.Monster:
                    {
                        var data = new Data.MonsterData();
                        data.Pos = new Logic.TilePosition(r, c);
                        data.Id  = (uint)tile.Properties["MonsterId"];

                        tile_map_data.MonsterDatas.Add(data);
                        break;
                    }

                    case Logic.Tile.EType.Portal:
                    {
                        var data = new Data.PortalData();
                        data.Pos = new Logic.TilePosition(r, c);
                        data.DestinationLevel    = (uint)tile.Properties["DestLevel"];
                        data.DestinationPosition = (Logic.TilePosition)tile.Properties["DestPos"];

                        tile_map_data.PortalDatas.Add(data);

                        break;
                    }
                    }
                }
            }

            using (var file = new FileStream(file_path, FileMode.Create))
            {
                var formatter = new BinaryFormatter();
                formatter.Serialize(file, tile_map_data);
            }
        }
コード例 #2
0
        public Tile_Portal CreatePortal(Data.PortalData data)
        {
            var portal = new Tile_Portal();

            portal.Data    = data;
            portal.IsBlock = false;

            return(portal);
        }
コード例 #3
0
ファイル: TileMap.cs プロジェクト: securitydefense/MagicTower
        public IEnumerator SaveToData()
        {
            foreach (Tile tile in LayerFloor)
            {
                if (tile != null)
                {
                    Data.FloorLayer[tile.Position.Row, tile.Position.Col] = tile.Type;
                }
            }

            var monsters = new List <Data.MonsterData>();
            var portals  = new List <Data.PortalData>();

            foreach (Tile tile in LayerCollide)
            {
                if (tile != null)
                {
                    switch (tile.Type)
                    {
                    case Tile.EType.Monster:
                    {
                        var monster_data = new Data.MonsterData();
                        monster_data.Pos = tile.Position;
                        monster_data.Id  = (tile as Tile_Monster).Id;

                        monsters.Add(monster_data);
                        break;
                    }

                    case Tile.EType.Portal:
                    {
                        var portal_data = new Data.PortalData();
                        portal_data.Pos = tile.Position;
                        portal_data.DestinationLevel    = (tile as Tile_Portal).DestinationLevel;
                        portal_data.DestinationPosition = (tile as Tile_Portal).DestinationPosition;

                        portals.Add(portal_data);
                        break;
                    }
                    }
                }
            }

            Data.MonsterDatas = monsters;
            Data.PortalDatas  = portals;

            yield return(null);
        }