Esempio n. 1
0
    /// <summary>
    /// 获得一个缓存的SceneTiled对应
    /// </summary>
    /// <param name="sceneData"></param>
    /// <returns></returns>
    public SceneTiled SpwanSceneTiled(WorldSceneData sceneData)
    {
        if (!SceneMap.Contains(sceneData.WorldIndex))
        {
            SceneTiled sceneTile = new SceneTiled(sceneData);
            SceneTilePool.Add(sceneTile);

            if (SceneTilePool.Count > MaxSceneTiledCount)
            {
                DestroyFirst();
            }

            SceneMap.Add(sceneData.WorldIndex);
        }
        else
        {
            //重新排序
            SceneTiled sceneTiled = null;
            for (int i = SceneTilePool.Count - 1; i >= 0; i--)
            {
                if (SceneTilePool[i].WorldMapIndex == sceneData.WorldIndex)
                {
                    sceneTiled = SceneTilePool[i];
                    SceneTilePool.RemoveAt(i);
                    break;
                }
            }
            SceneTilePool.Add(sceneTiled);
        }

        return(SceneTilePool[SceneTilePool.Count - 1]);
    }
Esempio n. 2
0
    /// <summary>
    /// 是否已缓存Tiled
    /// </summary>
    /// <param name="sceneData"></param>
    /// <returns>true表示已存在</returns>
    public bool HasCacheTiled(WorldSceneData sceneData)
    {
        if (sceneData == null)
        {
            return(false);
        }

        return(SceneMap.Contains(sceneData.WorldIndex));
    }
Esempio n. 3
0
    /// <summary>
    /// 初始化
    /// </summary>
    /// <param name="worldmaps"></param>
    public void Initilize(int[] worldmaps)
    {
        worldScenes = new WorldSceneData[worldmaps.Length];

        for (int i = 0; i < worldScenes.Length; i++)
        {
            WorldSceneData wsd = new WorldSceneData();
            wsd.WorldIndex = (byte)i;
            wsd.SceneId    = (byte)worldmaps[i];

            worldScenes[i] = wsd;
        }

        Debug.Log("scene count : " + worldScenes);
    }
Esempio n. 4
0
    private void addSceneTiled(Vector2 mapPos, Dictionary <int, WorldSceneData> worldSceneDatas)
    {
        int            tileIndex = Math.Abs((int)mapPos.x * MapRow) + Math.Abs((int)mapPos.y);
        WorldSceneData wsd       = MapData.Instance[tileIndex];

        if (wsd == null)
        {
            return;
        }

        if (!worldSceneDatas.ContainsKey(tileIndex))
        {
            worldSceneDatas.Add(tileIndex, wsd);
        }
    }
Esempio n. 5
0
    /// <summary>
    /// 销毁缓存SceneTiled
    /// </summary>
    /// <param name="sceneData"></param>
    public void DestroySceneTiled(WorldSceneData sceneData)
    {
        if (!SceneMap.Contains(sceneData.WorldIndex))
        {
            return;
        }

        for (int i = SceneTilePool.Count - 1; i >= 0; i--)
        {
            if (SceneTilePool[i].WorldMapIndex == sceneData.WorldIndex)
            {
                SceneTilePool[i].Destroy();
                SceneTilePool.RemoveAt(i);
                break;
            }
        }

        SceneMap.Remove(sceneData.WorldIndex);
    }
Esempio n. 6
0
    /// <summary>
    /// 主相机移动时的操作
    /// </summary>
    public void CameraChange()
    {
//        this.culScreenTiledCount();
//        Debug.Log("halfTileW:" + halfScreenWidthTiledCount + " , halfTileH:" + halfScreenHeightTiledCount);
        //计算相机中心个点的世界坐标位置
//        Vector2 center = new Vector2(Screen.width / 2 , Screen.height / 2);

        //计算TileIndex索引
        Dictionary <int, WorldSceneData> worldSceneDatas = new Dictionary <int, WorldSceneData>();
//        Vector2 mapPos = CoordinationConvert.SceneCamToSceneMapPoint(center);
//        addSceneTiled(mapPos, worldSceneDatas);
        //        //计算横向
        //        for (int i = 0; i < 2; i++)
        //        {
        //            //横向
        //            float nearX =  mapPos.x - (1 - (i % 2) * 2) * halfScreenWidthTiledCount;
        //            float nearY = mapPos.y + (1 - (i % 2) * 2) * halfScreenWidthTiledCount;
        //            Vector2 nearMapPos = new Vector2(nearX , nearY);
        //            addSceneTiled(nearMapPos, worldSceneDatas);
        //
        //            //纵向
        //            nearX = mapPos.x - (1 - (i % 2) * 2) * halfScreenHeightTiledCount;
        //            nearY = mapPos.y - (1 - (i % 2) * 2) * halfScreenHeightTiledCount;
        //            nearMapPos = new Vector2(nearX, nearY);
        //            addSceneTiled(nearMapPos, worldSceneDatas);
        //        }
        //
        //        //计算四个边角
        //        addShowTiled(Vector2.zero , worldSceneDatas);
        //        addShowTiled(new Vector2(Screen.width , 0), worldSceneDatas);
        //        addShowTiled(new Vector2(0 , Screen.height), worldSceneDatas);
        //        addShowTiled(new Vector2(Screen.width , Screen.height), worldSceneDatas);

        Vector2 mapLeftTop     = CoordinationConvert.SceneCamToWorldMapPoint(Vector2.zero);
        Vector2 mapLeftBottom  = CoordinationConvert.SceneCamToWorldMapPoint(new Vector2(0, Screen.height));
        Vector2 mapRightTop    = CoordinationConvert.SceneCamToWorldMapPoint(new Vector2(Screen.width, 0));
        Vector2 mapRightBottom = CoordinationConvert.SceneCamToWorldMapPoint(new Vector2(Screen.width, Screen.height));

        Debug.Log("Map LT: " + mapLeftTop + " , LB: " + mapLeftBottom + " , RT: " + mapRightTop + " , RB:" + mapRightBottom);

        int count = (int)(mapRightTop.x - mapLeftTop.x) + 2;

        for (int i = 0; i <= count; i++)
        {
            //上边缘
            Vector2 newMapPoint   = mapLeftTop + new Vector2(i + 1, -i + 1);
            Vector2 sceneMapPoint = CoordinationConvert.TileMapToSceneMapPoint(newMapPoint);
            addSceneTiled(sceneMapPoint, worldSceneDatas);

            //下边缘
            newMapPoint   = mapLeftBottom + new Vector2(i - 1, -i);
            sceneMapPoint = CoordinationConvert.TileMapToSceneMapPoint(newMapPoint);
            addSceneTiled(sceneMapPoint, worldSceneDatas);
        }

        //左边缘
        count = (int)(mapLeftTop.x - mapLeftBottom.x) + 1;
        for (int i = 0; i <= count; i++)
        {
            Vector2 newMapPoint   = mapLeftTop - new Vector2(i, i - 2);
            Vector2 sceneMapPoint = CoordinationConvert.TileMapToSceneMapPoint(newMapPoint);
            addSceneTiled(sceneMapPoint, worldSceneDatas);
        }

        //右边缘
        count = (int)(mapRightTop.x - mapRightBottom.x) + 2;
        for (int i = 0; i <= count; i++)
        {
            Vector2 newMapPoint   = mapRightTop - new Vector2(i - 2, i);
            Vector2 sceneMapPoint = CoordinationConvert.TileMapToSceneMapPoint(newMapPoint);
            addSceneTiled(sceneMapPoint, worldSceneDatas);
        }

        WorldSceneData[] wsdArr = new WorldSceneData[worldSceneDatas.Count];
        worldSceneDatas.Values.CopyTo(wsdArr, 0);

        this.MergeMap(wsdArr);

        //用于测试地图的可视区域
        //debugViewMap(mapLeftTop , mapLeftBottom , mapRightTop , mapRightBottom);
    }
Esempio n. 7
0
 public SceneTiled(WorldSceneData sceneData)
 {
     this.SceneData = sceneData;
 }