Example #1
0
    /// <summary>
    /// 根据土地的地图坐标获取LandTiled对象
    /// </summary>
    /// <param name="mapPoint">地图坐标系位置</param>
    /// <returns></returns>
    public LandTiled FindLandTiledByMapPoint(Vector2 mapPoint)
    {
        //父层Scene坐标
        Vector2 sceneMapPoint = CoordinationConvert.TileMapToSceneMapPoint(mapPoint);

        SceneTiled sceneTiled = GetSceneTiled(sceneMapPoint);

        if (sceneTiled == null)
        {
            return(null);
        }
        //相对Scene的坐标
        Vector2 relativeMapPoint = mapPoint - new Vector2((int)sceneMapPoint.x * SceneTiled.SceneRow, (int)sceneMapPoint.y * SceneTiled.SceneColumn);

        int landIndex = (int)(relativeMapPoint.x + relativeMapPoint.y * SceneTiled.SceneColumn);

        return(sceneTiled[landIndex]);
    }
Example #2
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);
    }