protected override void OnLoadLevel(int level, GridInfo gridInfo)
        {
            UnityMap2DUtil.CheckLoadTileIDMap();
            var tileInfo = GetMapInfo(TilemapUtil.TileMapName_BornPos);
            var campPoss = tileInfo.GetAllTiles(TilemapUtil.TileID_Camp);

            Debug.Assert(campPoss != null && campPoss.Count == 1, "campPoss!= null&& campPoss.Count == 1");
            campPos         = campPoss[0];
            enemyBornPoints = tileInfo.GetAllTiles(TilemapUtil.TileID_BornPosEnemy);
            playerBornPoss  = tileInfo.GetAllTiles(TilemapUtil.TileID_BornPosHero);
            var _gameConstStateService = GetService <IGameConstStateService>();

            if (_gameConstStateService != null)
            {
                _gameConstStateService.MapMin          = mapDataMin;
                _gameConstStateService.MapMax          = mapDataMax;
                _gameConstStateService.EnemyBornPoints = enemyBornPoints;
                _gameConstStateService.PlayerBornPoss  = playerBornPoss;
                _gameConstStateService.CampPos         = campPos;
            }

            EventHelper.Trigger(EEvent.LevelLoadProgress, 0.5f);
            UnityMap2DUtil.BindMapView(grid, gridInfo);
            EventHelper.Trigger(EEvent.LevelLoadProgress, 1f);
            EventHelper.Trigger(EEvent.LevelLoadDone, level);
        }
        protected override void OnLoadLevel(int level, GridInfo gridInfo)
        {
            UnityMap2DUtil.CheckLoadTileIDMap();

            EventHelper.Trigger(EEvent.LevelLoadProgress, 0.5f);
            UnityMap2DUtil.BindMapView(grid, gridInfo);
            EventHelper.Trigger(EEvent.LevelLoadProgress, 1f);
            EventHelper.Trigger(EEvent.LevelLoadDone, level);
        }
Beispiel #3
0
 //加载  解析配置表
 public static void CheckLoadTileIDMap()
 {
     if (!hasLoadIDMapConfig)
     {
         UnityMap2DUtil.hasLoadIDMapConfig = true;
         TextAsset textAsset = Resources.Load <TextAsset>(UnityMap2DUtil.idMapPath);
         if (textAsset == null)
         {
             Debug.LogError("CheckLoadTileIDMap:LoadFileFailed " + UnityMap2DUtil.idMapPath);
         }
         else
         {
             string   text  = textAsset.text;
             string[] array = text.Replace("\r\n", "\n").Split('\n');
             int      num   = array.Length;
             UnityMap2DUtil.tile2ID = new Dictionary <TileBase, ushort>(num);
             int i = 0;
             try
             {
                 while (i < num)
                 {
                     string text2 = array[i];
                     bool   flag3 = string.IsNullOrEmpty(text2.Trim());
                     if (!flag3)
                     {
                         string[] array2   = text2.Split('=');
                         ushort   num2     = ushort.Parse(array2[0].Trim());
                         string   relPath  = array2[1].Trim();
                         TileBase tileBase = UnityMap2DUtil.LoadTile(relPath);
                         id2Tiles[(int)num2] = tileBase;
                         tile2ID.Add(tileBase, num2);
                     }
                     i++;
                 }
             }
             catch (Exception ex)
             {
                 Debug.LogErrorFormat("CheckLoadTileIDMap:ParseError line = {0} str = {1} path = {2} e= {3}", new object[]
                 {
                     i + 1,
                     array[i],
                     UnityMap2DUtil.idMapPath,
                     ex.ToString()
                 });
             }
         }
     }
 }
Beispiel #4
0
        public static void BindMapView(Grid grid, GridInfo info)
        {
            bool flag = grid != null;

            if (flag)
            {
                foreach (Tilemap tilemap in grid.GetComponentsInChildren <Tilemap>())
                {
                    TileInfos mapInfo = info.GetMapInfo(tilemap.name);
                    bool      flag2   = mapInfo == null;
                    if (!flag2)
                    {
                        tilemap.ClearAllTiles();
                        TileInfosView tileInfosView = new TileInfosView();
                        mapInfo.view          = tileInfosView;
                        tileInfosView.tilemap = tilemap;
                        int        num   = mapInfo.tileIDs.Length;
                        TileBase[] array = new TileBase[num];
                        for (int j = 0; j < num; j++)
                        {
                            array[j] = UnityMap2DUtil.ID2Tile(mapInfo.tileIDs[j]);
                        }
                        tilemap.SetTiles((from t in mapInfo.GetAllPositions()
                                          select t.ToVector3Int()).ToArray <Vector3Int>(), array);
                        bool isPlaying = Application.isPlaying;
                        if (isPlaying)
                        {
                            bool isTagMap = mapInfo.isTagMap;
                            if (isTagMap)
                            {
                                tilemap.GetComponent <TilemapRenderer>().enabled = false;
                            }
                        }
                    }
                }
            }
        }
Beispiel #5
0
        public void SetTileID(int idx, LVector2Int pos, ushort id)
        {
            TileBase tileBase = UnityMap2DUtil.ID2Tile(id);

            this.tilemap.SetTile(new Vector3Int(pos.x, pos.y, 0), tileBase);
        }