Esempio n. 1
0
    public void door(int x, int y, TileData otherTileData)
    {
        TRAnimation door = otherTileData.gameObject.GetComponent <TRAnimation>();

        if (_PA._key_yellow > 0 && door.CurrentIndex == 1)
        {
            GameObject.Destroy(door.gameObject);
            otherTileData.Clear();
            _PA._key_yellow -= 1;
            _DM.tipContent   = "黄钥匙-1";
            _DM.tipTime      = 3f;
        }
        if (_PA._key_blue > 0 && door.CurrentIndex == 2)
        {
            GameObject.Destroy(door.gameObject);
            otherTileData.Clear();
            _PA._key_blue -= 1;
            _DM.tipContent = "蓝钥匙-1";
            _DM.tipTime    = 3f;
        }
        if (_PA._key_red > 0 && door.CurrentIndex == 3)
        {
            GameObject.Destroy(door.gameObject);
            otherTileData.Clear();
            _PA._key_red  -= 1;
            _DM.tipContent = "红钥匙-1";
            _DM.tipTime    = 3f;
        }
        if (door.SpriteTexture.name == "door-02")
        {
            GameObject.Destroy(door.gameObject);
            otherTileData.Clear();
        }
    }
Esempio n. 2
0
 public void Remove()
 {
     data?.Clear(); if (terrain != null)
     {
         GameObject.DestroyImmediate(terrain.gameObject);
     }
 }
Esempio n. 3
0
 public void feixing(int x, int y, TileData otherTileData)
 {
     _DM.tipContent     = "开启传送,可以传送到其他楼层";
     _DM.tipTime        = 3f;
     _PA._daoju_feixing = true;
     GameObject.Destroy(otherTileData.gameObject);
     otherTileData.Clear();
 }
Esempio n. 4
0
 public void tujian(int x, int y, TileData otherTileData)
 {
     _DM.tipContent    = "开启图鉴,开启后可点击怪物查看信息";
     _DM.tipTime       = 3f;
     _PA._daoju_tujian = true;
     GameObject.Destroy(otherTileData.gameObject);
     otherTileData.Clear();
 }
Esempio n. 5
0
            public void Execute()
            {
                int x = (int)(40 + math.sin(Elapsed * .35f) * 29.9f);
                int y = (int)(30 + math.cos(Elapsed) * 19.9f);
                int r = (int)(5 + math.sin(Elapsed * 0.5f) * 3.5f);

                Tiles.Clear();
                Tiles.Circle(x, y, r);
            }
Esempio n. 6
0
    public void RemoveSelectedGameObject()
    {
        switch (movingItemType)
        {
        case ItemType.ANIMAL:
            GameManager.Instance.AddToBalance(sellBackCost);
            objectToMove.GetComponent <Animal>().PopulationInfo.RemoveAnimal(objectToMove);
            break;

        case ItemType.FOOD:
            GameManager.Instance.AddToBalance(sellBackCost);
            FoodSource foodSource = objectToMove.GetComponent <FoodSource>();
            removeOriginalFood(foodSource);

            // Selling items no longer return them to inventory
            //Item foodItem = GameManager.Instance.LevelData.itemQuantities.Find(x => x.itemObject.ID.Equals(foodSource.Species.SpeciesName)).itemObject;

            //if (!foodItem)
            //    return;

            //FoodSourceStoreSection.AddItemQuantity(foodItem);
            break;

        case ItemType.TILE:
            if (initialTile.type == TileType.Liquid)
            {
                LiquidbodyController.Instance.RemoveConstructingLiquidContent(gridSystem.WorldToCell(objectToMove.transform.position));
            }


            GameManager.Instance.AddToBalance(sellBackCost);
            TileData tileData = gridSystem.GetTileData(gridSystem.WorldToCell(objectToMove.transform.position));
            tileData.Revert();
            gridSystem.ApplyChangeToTilemapTexture(gridSystem.WorldToCell(objectToMove.transform.position));
            if (tileData.currentTile == null)
            {
                tileData.Clear();
            }
            //gridSystem.RemoveTile(gridSystem.WorldToCell(objectToMove.transform.position));
            gridSystem.RemoveBuffer((Vector2Int)gridSystem.WorldToCell(objectToMove.transform.position));

            tileToDelete.SetActive(false);
            // Selling items no longer return them to inventory
            //LevelData.ItemData tileItemData = GameManager.Instance.LevelData.itemQuantities.Find(x => x.itemObject.ID.ToLower().Equals(objectToMove.name));

            //if (tileItemData == null)
            //    return;

            //TileStoreSection.AddItemQuantity(tileItemData.itemObject);
            break;

        default:
            break;
        }
        Reset();
    }
Esempio n. 7
0
 public static void tujian(int x, int y, TileData otherTileData)
 {
     AudioManager.Instance.playAudio("daoju");
     DialogManager.Instance.tipContent       = "开启“图鉴”,开启后可点击怪物查看信息";
     DialogManager.Instance.tipTime          = 3f;
     PlayerInfo.Instance.Data.HandBook.Value = true;
     GameObject.Destroy(otherTileData.gameObject);
     otherTileData.Clear();
     GameDataManager.Instance.sceneData[GameManager.Instance.CurrentFloor.Value][x, y] = 1;
 }
Esempio n. 8
0
 public static void feixing(int x, int y, TileData otherTileData)
 {
     AudioManager.Instance.playAudio("daoju");
     DialogManager.Instance.tipContent  = "开启“传送”,可传送到其他楼层";
     DialogManager.Instance.tipTime     = 3f;
     PlayerInfo.Instance.Data.Fly.Value = true;
     GameObject.Destroy(otherTileData.gameObject);
     otherTileData.Clear();
     GameDataManager.Instance.sceneData[GameManager.Instance.CurrentFloor.Value][x, y] = 1;
 }
Esempio n. 9
0
    public void key(int x, int y, TileData otherTileData)
    {
        Key key = otherTileData.gameObject.GetComponent <Key>();

        _PA._key_yellow += key.key_yellow;
        _PA._key_blue   += key.key_blue;
        _PA._key_red    += key.key_red;
        _DM.tipContent   = key.tip;
        _DM.tipTime      = 3f;
        GameObject.Destroy(key.gameObject);
        otherTileData.Clear();
    }
Esempio n. 10
0
 public void Execute(int x, int y, TileData otherTileData)
 {
     if (PlayerInfo.Instance.Data.KeyYellow.Value > 0 && currentIndex == 1)
     {
         AudioManager.Instance.playAudio("door");
         this.DestroyGameObj();
         otherTileData.Clear();
         GameDataManager.Instance.sceneData[GameManager.Instance.CurrentFloor.Value][x, y] = 1;
         PlayerInfo.Instance.Data.KeyYellow.Value -= 1;
         DialogManager.Instance.tipContent         = "黄钥匙-1";
         DialogManager.Instance.tipTime            = 3f;
     }
     if (PlayerInfo.Instance.Data.KeyBlue.Value > 0 && currentIndex == 2)
     {
         AudioManager.Instance.playAudio("door");
         this.DestroyGameObj();
         otherTileData.Clear();
         GameDataManager.Instance.sceneData[GameManager.Instance.CurrentFloor.Value][x, y] = 1;
         PlayerInfo.Instance.Data.KeyBlue.Value -= 1;
         DialogManager.Instance.tipContent       = "蓝钥匙-1";
         DialogManager.Instance.tipTime          = 3f;
     }
     if (PlayerInfo.Instance.Data.KeyRed.Value > 0 && currentIndex == 3)
     {
         AudioManager.Instance.playAudio("door");
         this.DestroyGameObj();
         otherTileData.Clear();
         GameDataManager.Instance.sceneData[GameManager.Instance.CurrentFloor.Value][x, y] = 1;
         PlayerInfo.Instance.Data.KeyRed.Value -= 1;
         DialogManager.Instance.tipContent      = "红钥匙-1";
         DialogManager.Instance.tipTime         = 3f;
     }
     if (spriteTexture.name == "door-02")
     {
         AudioManager.Instance.playAudio("door");
         this.DestroyGameObj();
         otherTileData.Clear();
         GameDataManager.Instance.sceneData[GameManager.Instance.CurrentFloor.Value][x, y] = 1;
     }
 }
Esempio n. 11
0
        public void Execute(int x, int y, TileData otherTileData)
        {
            AudioManager.Instance.playAudio("daoju");
            PlayerInfo.Instance.Data.KeyYellow.Value += key_yellow;
            PlayerInfo.Instance.Data.KeyBlue.Value   += key_blue;
            PlayerInfo.Instance.Data.KeyRed.Value    += key_red;
            DialogManager.Instance.tipContent         = tip;
            DialogManager.Instance.tipTime            = 3f;
            this.DestroyGameObj();

            otherTileData.Clear();
            GameDataManager.Instance.sceneData[GameManager.Instance.CurrentFloor.Value][x, y] = 1;
        }
Esempio n. 12
0
    public void daoju(int x, int y, TileData otherTileData)
    {
        Daoju daoju = otherTileData.gameObject.GetComponent <Daoju>();

        _PA._gongji    += daoju.gongji;
        _PA._fangyu    += daoju.fangyu;
        _PA._shengming += daoju.shengming;
        _PA._jinbi     += daoju.jinbi;
        _PA._dengji    += daoju.dengji;
        _PA._gongji    += daoju.dengji * 7;
        _PA._fangyu    += daoju.dengji * 7;
        _PA._shengming += daoju.dengji * 600;
        _DM.tipContent  = daoju.tip;
        _DM.tipTime     = 3f;
        GameObject.Destroy(daoju.gameObject);
        otherTileData.Clear();
    }
Esempio n. 13
0
        public void Execute(int x, int y, TileData otherTileData)
        {
            DialogManager.Instance.infoDabuguo  = "你打不过他。\n\n";
            DialogManager.Instance.infoDabuguo += "怪物属性:\n";
            DialogManager.Instance.infoDabuguo += "生命:" + shengming + "\n";
            DialogManager.Instance.infoDabuguo += "攻击:" + gongji + "\n";
            DialogManager.Instance.infoDabuguo += "防御:" + fangyu + "\n";
            DialogManager.Instance.infoDabuguo += "金币:" + jinbi + "\n";
            DialogManager.Instance.infoDabuguo += "经验:" + jingyan + "\n";

            if (PlayerInfo.Instance.Data.Attack.Value <= fangyu)
            {
                DialogManager.Instance.state = "dabuguo";
            }
            else
            {
                int   shanghai     = PlayerInfo.Instance.Data.Attack.Value - fangyu;
                float cishu        = Mathf.Ceil(shengming / shanghai);
                float zongshanghai = 0;
                if (gongji > PlayerInfo.Instance.Data.Defence.Value)
                {
                    float shoushang = gongji - PlayerInfo.Instance.Data.Defence.Value;
                    zongshanghai = shoushang * cishu;
                }
                if (zongshanghai >= PlayerInfo.Instance.Data.Life.Value)
                {
                    DialogManager.Instance.state = "dabuguo";
                }
                else
                {
                    AudioManager.Instance.playAudio("fight");
                    PlayerInfo.Instance.Data.Life.Value       -= (int)zongshanghai;
                    PlayerInfo.Instance.Data.Experience.Value += jingyan;
                    PlayerInfo.Instance.Data.Gold.Value       += jinbi;
                    DialogManager.Instance.tipContent          = "经验+" + jingyan + ",金币+" + jinbi;
                    DialogManager.Instance.tipTime             = 3f;
                    this.DestroyGameObj();
                    if (otherTileData.GetUserFlag(9))
                    {
                        Application.LoadLevel(2);
                    }
                    otherTileData.Clear();
                    GameDataManager.Instance.sceneData[GameManager.Instance.CurrentFloor.Value][x, y] = 1;
                }
            }
        }
Esempio n. 14
0
    public void guaiwu(int x, int y, TileData otherTileData)
    {
        Guaiwu guaiwu = otherTileData.gameObject.GetComponent <Guaiwu>();

        _DM.infoDabuguo  = "你打不过它。\r\n";
        _DM.infoDabuguo += "怪物属性:\n";
        _DM.infoDabuguo += "生命:" + guaiwu.shengming + "\n";
        _DM.infoDabuguo += "攻击:" + guaiwu.gongji + "\n";
        _DM.infoDabuguo += "防御:" + guaiwu.fangyu + "\n";
        _DM.infoDabuguo += "金币:" + guaiwu.jinbi + "\n";
        _DM.infoDabuguo += "经验:" + guaiwu.jingyan + "\n";
        if (_PA._gongji <= guaiwu.fangyu)
        {
            _DM.state = "dabuguo";
        }
        else
        {
            int   shanghai     = _PA._gongji - guaiwu.fangyu;
            float cishu        = Mathf.Ceil(guaiwu.shengming / shanghai);
            float zongshanghai = 0;
            if (guaiwu.gongji > _PA._fangyu)
            {
                float shoushang = guaiwu.gongji - _PA._fangyu;
                zongshanghai = shoushang * cishu;
            }
            if (zongshanghai >= _PA._shengming)
            {
                _DM.state = "dabuguo";
            }
            else
            {
                _PA._shengming -= (int)zongshanghai;
                _PA._jingyan   += guaiwu.jingyan;
                _PA._jinbi     += guaiwu.jinbi;
                _DM.tipContent  = "经验+" + guaiwu.jingyan + ",金币+" + guaiwu.jinbi;
                _DM.tipTime     = 3f;
                GameObject.Destroy(guaiwu.gameObject);
                if (otherTileData.GetUserFlag(9))
                {
                    SceneManager.LoadScene(1);
                }
                otherTileData.Clear();
            }
        }
    }
Esempio n. 15
0
 public bool clear2Door()
 {
     try
     {
         floorGo[2].SetActive(true);
         TileSystem ts_object = floorGo[2].GetComponent <TileSystem>();
         GameObject door      = GameObject.Find("Floor2/chunk_0_0/door-01_3").gameObject;
         TileData   tile      = ts_object.GetTile(6, 1);
         GameObject.Destroy(door.gameObject);
         tile.Clear();
         //_GDM.sceneData[2][6, 1] = 1;
         floorGo[2].SetActive(false);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 16
0
        public void Execute(int x, int y, TileData otherTileData)
        {
            AudioManager.Instance.playAudio("daoju");
            PlayerInfo.Instance.Data.Attack.Value  += gongji;
            PlayerInfo.Instance.Data.Defence.Value += fangyu;
            PlayerInfo.Instance.Data.Life.Value    += shengming;
            PlayerInfo.Instance.Data.Gold.Value    += jinbi;
            PlayerInfo.Instance.Data.Level.Value   += dengji;
            PlayerInfo.Instance.Data.Attack.Value  += dengji * 7;
            PlayerInfo.Instance.Data.Defence.Value += dengji * 7;
            PlayerInfo.Instance.Data.Life.Value    += dengji * 600;

            DialogManager.Instance.tipContent = tip;
            DialogManager.Instance.tipTime    = 3f;

            this.DestroyGameObj();

            otherTileData.Clear();
            GameDataManager.Instance.sceneData[GameManager.Instance.CurrentFloor.Value][x, y] = 1;
        }
Esempio n. 17
0
 public void LoadAlgorithmSettings()
 {
     FloorSettings.Clear();
     TileLayers.Clear();
     TileData.Clear();
     Items.Clear();
     Npcs.Clear();
     Rooms.Clear();
     if (Algorithm > -1)
     {
         FloorAlgorithm settingsGuide = GameData.FloorAlgorithmDex[Algorithm];
         for (int i = 0; i < settingsGuide.FloorSettings.Count; i++)
         {
             FloorSettings.Add(settingsGuide.FloorSettings[i].Item1, 0);
         }
         for (int i = 0; i < settingsGuide.LayerSettings.Count; i++)
         {
             TileLayers.Add(settingsGuide.LayerSettings[i], new List <Maps.TileAnim>());
         }
         for (int i = 0; i < settingsGuide.TileSettings.Count; i++)
         {
             TileData.Add(settingsGuide.TileSettings[i], new List <Maps.TileData>());
         }
         for (int i = 0; i < settingsGuide.ItemGroups.Count; i++)
         {
             Items.Add(settingsGuide.ItemGroups[i], new List <Tuple <ItemPreset, int> >());
         }
         for (int i = 0; i < settingsGuide.NpcGroups.Count; i++)
         {
             Npcs.Add(settingsGuide.NpcGroups[i], new List <Tuple <NpcPreset, int> >());
         }
         for (int i = 0; i < settingsGuide.RoomGroups.Count; i++)
         {
             Rooms.Add(settingsGuide.RoomGroups[i], new List <Tuple <int, int> >());
         }
     }
 }
Esempio n. 18
0
        public void LoadGame()
        {
            using (ES2Reader reader = ES2Reader.Create("player"))
            {
                PlayerInfo.Instance.Data.Level.Value      = reader.Read <int>("dengji");
                PlayerInfo.Instance.Data.Gold.Value       = reader.Read <int>("jinbi");
                PlayerInfo.Instance.Data.Experience.Value = reader.Read <int>("jingyan");
                PlayerInfo.Instance.Data.Life.Value       = reader.Read <int>("shengming");
                PlayerInfo.Instance.Data.Attack.Value     = reader.Read <int>("gongji");
                PlayerInfo.Instance.Data.Defence.Value    = reader.Read <int>("fangyu");
                PlayerInfo.Instance.Data.KeyYellow.Value  = reader.Read <int>("key_yellow");
                PlayerInfo.Instance.Data.KeyBlue.Value    = reader.Read <int>("key_blue");
                PlayerInfo.Instance.Data.KeyRed.Value     = reader.Read <int>("key_red");
                PlayerInfo.Instance.Data.HandBook.Value   = reader.Read <bool>("daoju_tujian");
                PlayerInfo.Instance.Data.Fly.Value        = reader.Read <bool>("daoju_feixing");
                GM.MaxFloor.Value = reader.Read <int>("maxFloor");
                Dialoguer.SetGlobalBoolean(0, reader.Read <bool>("hasJinglingTalked"));
                Dialoguer.SetGlobalBoolean(1, reader.Read <bool>("hasDaozeiTalked"));
                Dialoguer.SetGlobalBoolean(2, reader.Read <bool>("hasGoodJian"));
                Dialoguer.SetGlobalBoolean(3, reader.Read <bool>("hasGoodDun"));
                Dialoguer.SetGlobalBoolean(4, reader.Read <bool>("hasGangJian"));
                Dialoguer.SetGlobalBoolean(5, reader.Read <bool>("hasGangDun"));
            }
#if UNITY_WP8
            for (int i = 0; i < GM.MaxFloor + 1; i++)
            {
                GM.floorGO[i].SetActive(true);
                using (ES2Reader reader = ES2Reader.Create("floor" + i))
                {
                    TileSystem ts_object = GameObject.Find("Floor" + i).gameObject.GetComponent <TileSystem>();
                    for (int x = 0; x < 11; x++)
                    {
                        for (int y = 0; y < 11; y++)
                        {
                            int hasTile = reader.Read <int>(x + "v" + y);
                            if (sceneData[i] == null)
                            {
                                sceneData[i] = new int[11, 11];
                            }
                            sceneData[i][x, y] = hasTile;
                            if (sceneData[i][x, y] != null && sceneData[i][x, y] == 1)
                            {
                                TileData tile = ts_object.GetTile(x, y);
                                if (tile != null)
                                {
                                    GameObject.Destroy(tile.gameObject);
                                    tile.Clear();
                                }
                            }
                        }
                    }
                }
                GM.floorGO[i].SetActive(false);
            }
#else
            for (int i = 0; i < GM.MaxFloor.Value + 1; i++)
            {
                GM.floorGO[i].SetActive(true);
                sceneData[i] = ES2.Load2DArray <int>("floor" + i);
                TileSystem ts_object = GameObject.Find("Floor" + i).gameObject.GetComponent <TileSystem>();
                for (int x = 0; x < 11; x++)
                {
                    for (int y = 0; y < 11; y++)
                    {
                        if (sceneData[i][x, y] == 1)
                        {
                            TileData tile = ts_object.GetTile(x, y);
                            if (tile != null)
                            {
                                GameObject.Destroy(tile.gameObject);
                                tile.Clear();
                            }
                        }
                    }
                }
                GM.floorGO[i].SetActive(false);
            }
#endif
            GM.floorGO[0].SetActive(true);
            DM.state = "";
            PlayerPrefs.DeleteKey("loadgame");
            DM.tipContent = "读取成功";
            DM.tipTime    = 3;
        }
Esempio n. 19
0
 public void Execute()
 {
     Tiles.Clear();
 }
    /// <summary>
    /// Upgrade tile system from v1.0.0-v1.0.8 to v2.0.0.
    /// </summary>
    /// <remarks>
    /// <para>Replicates upgrade process that was included in v1.0.9+ but converts straight
    /// to v2.0.0 instead of v1.0.9.</para>
    /// </remarks>
    /// <param name="v1">Old tile system.</param>
    public static void UpgradeTileSystemA(MonoBehaviour v1)
    {
        RtsUpgradedBrushMap map = RtsBrushUpgradeUtility.BrushMappings;

        EditorUtility.DisplayProgressBar("Upgrade Tile System", "Initializing new data structure...", 0.0f);
        try {
            PropertyInfo piTileData_hasGameObject = typeof(TileData).GetProperty("HasGameObject", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            Vector3 tileSize = (Vector3)_fiTileSystem_tileSize.GetValue(v1);
            int     rows     = (int)_fiTileSystem_rows.GetValue(v1);
            int     columns  = (int)_fiTileSystem_columns.GetValue(v1);

            // Create v2.x tile system.
            TileSystem v2 = v1.gameObject.AddComponent <TileSystem>();
            v2.CreateSystem(tileSize.x, tileSize.y, tileSize.z, rows, columns, 30, 30);
            CopyProperties(v1, v2);

            // Assume value that was consistent with original default settings
            v2.applyRuntimeStripping = true;
            v2.StrippingPreset       = StrippingPreset.NoStripping;
            v2.BeginBulkEdit();

            Component[] instanceComponents = v1.GetComponentsInChildren(_tyTileInstance, true);

            float task      = 0.0f;
            float taskCount = instanceComponents.Length;
            float taskRatio = 1.0f / taskCount;

            TileData tile = new TileData();

            // Retrieve all tile instance components
            foreach (MonoBehaviour instance in instanceComponents)
            {
                EditorUtility.DisplayProgressBar("Upgrade Tile System", "Processing tile data...", (task++) * taskRatio);

                int row    = (int)_fiTileInstance_row.GetValue(instance);
                int column = (int)_fiTileInstance_column.GetValue(instance);

                tile.Clear();

                // Create and assign tile data
                tile.brush           = map.Lookup((Object)_piTileInstance_brush.GetValue(instance, null));
                tile.orientationMask = (byte)OrientationUtility.MaskFromName((string)_fiTileInstance_orientationName.GetValue(instance));
                tile.variationIndex  = (byte)(int)_fiTileInstance_variationIndex.GetValue(instance);
                tile.Empty           = false;
                tile.gameObject      = instance.gameObject;
                piTileData_hasGameObject.SetValue(tile, true, null);

                v2.SetTileFrom(row, column, tile);

                Chunk chunk = v2.GetChunkFromTileIndex(row, column);
                ForceRepaintForAtlasTiles(v2.GetTile(row, column), chunk);
                if (instance == null)
                {
                    continue;
                }

                // Cleanup original tile instance?
                if (!StrippingUtility.StripEmptyGameObject(instance.transform))
                {
                    // Reparent game object to its shiny new chunk!
                    instance.gameObject.transform.parent = chunk.transform;
                }

                // Destroy unwanted tile instance component
                Object.DestroyImmediate(instance);
            }

            int count = v2.EndBulkEdit();
            RemoveTileSystem(v1);

            if (count > 0)
            {
                Debug.Log(string.Format("Upgrade of tile system '{0}' completed and {1} tile(s) were force refreshed.", v2.name, count));
            }
            else
            {
                Debug.Log(string.Format("Upgrade of tile system '{0}' completed.", v2.name));
            }
        }
        finally {
            EditorUtility.ClearProgressBar();
        }
    }
        /// <summary>
        /// Save the map configuration
        /// </summary>
        /// <param name="_autoTileMap"></param>
        /// <returns></returns>
        public bool SaveData(AutoTileMap _autoTileMap)
        {
            int width  = TileMapWidth;
            int height = TileMapHeight;

            // avoid clear map data when auto tile map is not initialized
            if (!_autoTileMap.IsInitialized)
            {
                //Debug.LogError(" Error saving data. Autotilemap is not initialized! Map will not be saved. ");
                return(false);
            }

            Metadata.version = MetadataChunk.k_version;

            TileData.Clear();
            // TriggerLink.Clear();
            // WarpsData.Clear();
            // SignpostsData.Clear();
            // ScriptData.Clear();

            bool isEnableCompression = true;

            for (int iLayer = 0; iLayer < _autoTileMap.GetLayerCount(); ++iLayer)
            {
                AutoTileMap.MapLayer mapLayer = _autoTileMap.MapLayers[iLayer];
                List <int>           tileData = new List <int>(width * height);
                int iTileRepetition           = 0;
                int savedTileId = 0;
                int mapWidth    = _autoTileMap.MapTileWidth;
                int mapHeight   = _autoTileMap.MapTileHeight;
                for (int tile_y = 0; tile_y < height; ++tile_y)
                {
                    for (int tile_x = 0; tile_x < width; ++tile_x)
                    {
                        int iType = -1;
                        if (tile_x < mapWidth && tile_y < mapHeight)
                        {
                            // AutoTile autoTile = _autoTileMap.TileLayers[_autoTileMap.MapLayers[iLayer].TileLayerIdx][tile_x + tile_y * mapWidth];
                            AutoTile autoTile = _autoTileMap.TileLayers[iLayer][tile_x, tile_y];
                            iType = autoTile != null? autoTile.Id : -1;
                        }

                        if (isEnableCompression)
                        {
                            if (iTileRepetition == 0)
                            {
                                savedTileId     = iType;
                                iTileRepetition = 1;
                            }
                            else
                            {
                                // compression data. All tiles of the same type are store with number of repetitions ( negative number ) and type
                                // ex: 5|5|5|5 --> |-4|5| (4 times 5) ex: -1|-1|-1 --> |-3|-1| ( 3 times -1 )
                                if (iType == savedTileId)
                                {
                                    ++iTileRepetition;
                                }
                                else
                                {
                                    if (iTileRepetition > 1)
                                    {
                                        tileData.Add(-iTileRepetition);   // save number of repetition with negative sign
                                    }
                                    if (savedTileId < -1)
                                    {
                                        Debug.LogError(" Wrong tile id found when compressing the tile layer " + mapLayer.Name);
                                        savedTileId = -1;
                                    }
                                    tileData.Add(savedTileId);
                                    savedTileId     = iType;
                                    iTileRepetition = 1;
                                }
                            }
                        }
                        else
                        {
                            tileData.Add(iType);   // save number of repetition with negative sign
                        }
                    }
                }
                if (isEnableCompression)
                {
                    // save last tile type found
                    if (iTileRepetition > 1)
                    {
                        tileData.Add(-iTileRepetition);
                    }
                    tileData.Add(savedTileId);
                }
                //
                TileData.Add(new TileLayer()
                {
                    Tiles        = tileData,
                    Depth        = mapLayer.Depth,
                    LayerType    = mapLayer.LayerType,
                    SortingLayer = mapLayer.SortingLayer,
                    SortingOrder = mapLayer.SortingOrder,
                    Name         = mapLayer.Name,
                    Visible      = mapLayer.Visible
                });
            }
            TileMapWidth  = width;
            TileMapHeight = height;

            //Compression Data
            OverlayLink_C   = CreateCompressionArray(OverlayLink);
            TriggerLink_C   = CreateCompressionArray(TriggerLink);
            High_C          = CreateCompressionArray(High);
            OverlayRotate_C = CreateCompressionArray(OverlayRotate);
            // RawFlagMap.Data = FlagMap;
            RawFlagAction = new List <FlagAction.SerializableFlagAction>(ListFlagAction.Count);
            for (int i = 0; i < ListFlagAction.Count; i++)
            {
                var r = new FlagAction.SerializableFlagAction();
                r.FlagAction = ListFlagAction[i];
                RawFlagAction.Add(r);
            }
            Debug.Log("Save with Compression");
            return(true);
        }